SS LAB REPORT 1 Final
SS LAB REPORT 1 Final
Variable Arithematic
Timing Functions
Introduction to M-files
Task # 01:
a) Mat lab stores numeric data as double‐precision floating point by default. To store data
as an 8‐ bit integer, int8 (a conversion function) can be used. Type the sample code in
mat lab command window:
>> x = 26
>> whos
>> y = int8(x)
>> whos
What difference do you see? State your findings. (Also try uint16, uint32, uint64)
b) Take your name in command window e.g. name = ‘Ali’. Convert it into 8‐bit integer
format using int8 function.
Problem Analysis:
In Part a of Task 1 there are simple commands to be typed in mat lab which converts the vector x from
the default double to integer. We have to also try uint16,uint32,uint64 commands.Here the uint is for
unsigned integers
In Part b of Task 1 we have to take a name and convert it into integer using int8 Function
Algorithm:
In part a we have to simply write the commands given in lab manual and after that we have to write
commands for uint16,uint32,uint64
Code:
Discussion and Conclusion:
In this task we learnt about the conversion of double to integer ,unsigned integer and conversion of
character to integer
Task # 02:
Create an M-File to prove any five expressions from the following:
Use etime or tic toc functions to evaluate time taken for solving each of the five chosen
expressions.
Problem Analysis:
In Task 2 we have to create a M-file and proof five of the given trigonometric identities given in the lab
manual.
One Approach is to have values for alpha and beta of sin and cos and check for the values of left hand
side and right side equations. If both sides values is same it will prove the trigonometric identity
Algorithm:
First we have to give a specific value to alpha and beta, then check for the value of left hand side
equation and then right side equation. If both sides values match it means the identity is true
Code:
tic
disp 'proof of expression number one';
% sin(a+b)=sin(a)*cos(b)+cos(a)*sin(b)
a=pi/4;
b=pi/4;
sin(a+b);
sin(a)*cos(b)+cos(a)*sin(b);
disp 'the value of sin(a+b) is ';
disp (sin(a+b));
disp 'the value of sin(a)*cos(b)+cos(a)*sin(b) is ';
disp (sin(a)*cos(b)+cos(a)*sin(b));
disp 'As the values are same so expression is proved';
Task # 03:
Write a CGPA Calculator program using M-File: Design a transcript for your second semester
result i.e. take grade points and credit hours of each subject as input from user and store in
variables. Take product of each subject grade points with its credit hours and divide by total
credit hours in order to evaluate CGPA. Show the results in the form of well designed transcript
using disp and input commands.
Problem Analysis:
In task 3 we have to create a cgpa calculator that calculates the student cgpa of semester. The program
will ask for the subject grade point and credit hour and will show the equivalent grade for his grade
point and at the end the student cgpa will be displayed
The approach for cgpa calculating is that we take product of credit hour and grade points of all subjects
and add them and after that we divide it with the total sum of credit hours
Algorithm:
The algorithm will be that first we will prompt the user to enter the grade points and credit hours for all
the subjects then to show equivalent grade for the grade points of subject we will use the if else
statements and after that cgpa will be calculated by taking the product of credit hour and grade points
of all subjects and add them and after that divide it with the total sum of credit hours
Code:
clear all
% gpa calculator
disp 'A Cgpa Calculator';
disp 'lets start to calculate your cgpa of 2 Semester ';
disp 'Please Enter the grade point of Differential Equation ';
de=input('Grade Point of Differentoial Equation is : ');
disp 'Please Enter the credit hours of Differential Equation ';
dec=input('credit hours of Differentoial Equation are : ');
disp 'Please Enter the grade point of Engineering Drawing ';
edg=input('Grade Point of Egineering Drawing is : ');
disp 'Please Enter the credit hours of Engineering Drawing ';
edgc=input('credit hours of Engineering Drawing are : ');
disp 'Please Enter the grade point of Computer Programming ';
cp=input('Grade Point of Computer Programming is : ');
disp 'Please Enter the credit hours of Computer Programming ';
cpc=input('credit hours of Computer Programming are : ');
disp 'Please Enter the grade point of Circuit and Systems 1 ';
cs=input('Grade Point of Circuit and Systems 1 is : ');
disp 'Please Enter the credit hours of Circuit and Systems 1 ';
csc=input('credit hours of Circuit and Systems 1 are : ');
disp 'Please Enter the grade point of CPS ';
cps=input('Grade Point of CPS is : ');
disp 'Please Enter the credit hours of CPS ';
cpsc=input('credit hours of CPS are : ');
disp 'Please Enter the grade point of Pak Std ';
pk=input('Grade Point of Pak Std is : ');
disp 'Please Enter the credit hours of Pak Std ';
pkc=input('credit hours of Pak Std are : ');
disp 'Please Enter the grade point of CS 1 Lab ';
csl=input('Grade Point of CS 1 Lab is : ');
disp 'Please Enter the credit hours of CS 1 Lab ';
cslc=input('credit hours of CS 1 Lab are : ');
disp 'Please Enter the grade point of CP Lab ';
cpl=input('Grade Point of CP Lab is : ');
disp 'Please Enter the credit hours of CP Lab ';
cplc=input('credit hours of CP Lab are : ');
disp 'Please Enter the grade point of EDG Lab ';
edgl=input('Grade Point of EDG Lab is : ');
disp 'Please Enter the credit hours of EDG Lab ';
edglc=input('credit hours of EDG Lab are : ');
% DE
if (de>3.67)
disp 'DIFFERENTIAL EQUATION GRADE IS : A';
else if (de>3.33)
disp 'DIFFERENTIAL EQUATION GRADE IS : A-';
else if (de>3.00)
disp 'DIFFERENTIAL EQUATION GRADE IS : B+';
else if (de>2.67)
disp 'DIFFERENTIAL EQUATION GRADE IS : B';
else if (de>2.33)
disp 'DIFFERENTIAL EQUATION GRADE IS : B-';
else if (de>2.00)
disp 'DIFFERENTIAL EQUATION GRADE IS : C+';
else if (de>1.67)
disp 'DIFFERENTIAL EQUATION GRADE IS : C';
else if (de>1.33)
disp 'DIFFERENTIAL EQUATION GRADE IS : C-';
else if (de>1.00)
disp 'DIFFERENTIAL EQUATION GRADE IS :
D+';
else if (de==1.00)
disp 'DIFFERENTIAL EQUATION GRADE IS :
D';
else
disp 'DIFFERENTIAL EQUATION GRADE IS :
F';
end
end
end
end
end
end
end
end
end
end
% EDG
if (edg>3.67)
disp 'ENGINEERING DRAWING GRADE IS : A';
else if (edg>3.33)
disp 'ENGINEERING DRAWING GRADE IS : A-';
else if (edg>3.00)
disp 'ENGINEERING DRAWING GRADE IS : B+';
else if (edg>2.67)
disp 'ENGINEERING DRAWING GRADE IS : B';
else if (edg>2.33)
disp 'ENGINEERING DRAWING GRADE IS : B-';
else if (edg>2.00)
disp 'ENGINEERING DRAWING GRADE IS : C+';
else if (edg>1.67)
disp 'ENGINEERING DRAWING GRADE IS : C';
else if (edg>1.33)
disp 'ENGINEERING DRAWING GRADE IS : C-';
else if (edg>1.00)
disp 'ENGINEERING DRAWING GRADE IS : D+';
else if (edg==1.00)
disp 'ENGINEERING DRAWING GRADE IS :
D';
else
disp 'ENGINEERING DRAWING GRADE IS :
F';
end
end
end
end
end
end
end
end
end
end
% CP
if (cp>3.67)
disp 'COMPUTER PROGRAMMING GRADE IS : A';
else if (cp>3.33)
disp 'COMPUTER PROGRAMMING GRADE IS : A-';
else if (cp>3.00)
disp 'COMPUTER PROGRAMMING GRADE IS : B+';
else if (cp>2.67)
disp 'COMPUTER PROGRAMMING GRADE IS : B';
else if (cp>2.33)
disp 'COMPUTER PROGRAMMING GRADE IS : B-';
else if (cp>2.00)
disp 'COMPUTER PROGRAMMING GRADE IS : C+';
else if (cp>1.67)
disp 'COMPUTER PROGRAMMING GRADE IS : C';
else if (cp>1.33)
disp 'COMPUTER PROGRAMMING GRADE IS : C-';
else if (cp>1.00)
disp 'COMPUTER PROGRAMMING GRADE IS : D+';
else if (cp==1.00)
disp 'COMPUTER PROGRAMMING GRADE IS :
D';
else
disp 'COMPUTER PROGRAMMING GRADE IS :
F';
end
end
end
end
end
end
end
end
end
end
% CS 1
if (cs>3.67)
disp 'CIRCUIT AND SYSTEMS 1 GRADE IS : A';
else if (cs>3.33)
disp 'CIRCUIT AND SYSTEMS 1 GRADE IS : A-';
else if (cs>3.00)
disp 'CIRCUIT AND SYSTEMS 1 GRADE IS : B+';
else if (cs>2.67)
disp 'CIRCUIT AND SYSTEMS 1 GRADE IS : B';
else if (cs>2.33)
disp 'CIRCUIT AND SYSTEMS 1 GRADE IS : B-';
else if (cs>2.00)
disp 'CIRCUIT AND SYSTEMS 1 GRADE IS : C+';
else if (cs>1.67)
disp 'CIRCUIT AND SYSTEMS 1 GRADE IS : C';
else if (cs>1.33)
disp 'CIRCUIT AND SYSTEMS 1 GRADE IS : C-';
else if (cs>1.00)
disp 'CIRCUIT AND SYSTEMS 1 GRADE IS :
D+';
else if (cs==1.00)
disp 'CIRCUIT AND SYSTEMS 1 GRADE IS :
D';
else
disp 'CIRCUIT AND SYSTEMS 1 GRADE IS :
F';
end
end
end
end
end
end
end
end
end
end
%CPS
if (cps>3.67)
disp 'COMMUNICATIONS AND PRESENTATION SKILLS GRADE IS : A';
else if (cps>3.33)
disp 'COMMUNICATIONS AND PRESENTATION SKILLS GRADE IS : A-';
else if (cps>3.00)
disp 'COMMUNICATIONS AND PRESENTATION SKILLS GRADE IS : B+';
else if (cps>2.67)
disp 'COMMUNICATIONS AND PRESENTATION SKILLS GRADE IS : B';
else if (cps>2.33)
disp 'COMMUNICATIONS AND PRESENTATION SKILLS GRADE IS :
B-';
else if (cps>2.00)
disp 'COMMUNICATIONS AND PRESENTATION SKILLS GRADE
IS : C+';
else if (cps>1.67)
disp 'COMMUNICATIONS AND PRESENTATION SKILLS GRADE
IS : C';
else if (cps>1.33)
disp 'COMMUNICATIONS AND PRESENTATION SKILLS
GRADE IS : C-';
else if (cps>1.00)
disp 'COMMUNICATIONS AND PRESENTATION
SKILLS GRADE IS : D+';
else if (cps==1.00)
disp 'COMMUNICATIONS AND PRESENTATION
SKILLS GRADE IS : D';
else
disp 'COMMUNICATIONS AND PRESENTATION
SKILLS GRADE IS : F';
end
end
end
end
end
end
end
end
end
end
% PAK STD
if (pk>3.67)
disp 'PAK STUDY GRADE IS : A';
else if (pk>3.33)
disp 'PAK STUDY GRADE IS : A-';
else if (pk>3.00)
disp 'PAK STUDY GRADE IS : B+';
else if (pk>2.67)
disp 'PAK STUDY GRADE IS : B';
else if (pk>2.33)
disp 'PAK STUDY GRADE IS : B-';
else if (pk>2.00)
disp 'PAK STUDY GRADE IS : C+';
else if (pk>1.67)
disp 'PAK STUDY GRADE IS : C';
else if (pk>1.33)
disp 'PAK STUDY GRADE IS : C-';
else if (pk>1.00)
disp 'PAK STUDY GRADE IS : D+';
else if (pk==1.00)
disp 'PAK STUDY GRADE IS : D';
else
disp 'PAK STUDY GRADE IS : F';
end
end
end
end
end
end
end
end
end
end
%CS 1 LAB
if (csl>3.67)
disp 'CIRCUIT AND SYSTEMS 1 LAB GRADE IS : A';
else if (csl>3.33)
disp 'CIRCUIT AND SYSTEMS 1 LAB GRADE IS : A-';
else if (csl>3.00)
disp 'CIRCUIT AND SYSTEMS 1 LAB GRADE IS : B+';
else if (csl>2.67)
disp 'CIRCUIT AND SYSTEMS 1 LAB GRADE IS : B';
else if (csl>2.33)
disp 'CIRCUIT AND SYSTEMS 1 LAB GRADE IS : B-';
else if (csl>2.00)
disp 'CIRCUIT AND SYSTEMS 1 LAB GRADE IS : C+';
else if (csl>1.67)
disp 'CIRCUIT AND SYSTEMS 1 LAB GRADE IS : C';
else if (csl>1.33)
disp 'CIRCUIT AND SYSTEMS 1 LAB GRADE IS :
C-';
else if (csl>1.00)
disp 'CIRCUIT AND SYSTEMS 1 LAB GRADE IS :
D+';
else if (csl==1.00)
disp 'CIRCUIT AND SYSTEMS 1 LAB GRADE
IS : D';
else
disp 'CIRCUIT AND SYSTEMS 1 LAB GRADE
IS : F';
end
end
end
end
end
end
end
end
end
end
% CP LAB
if (cpl>3.67)
disp 'COMPUTER PROGRAMMING LAB GRADE IS : A';
else if (cpl>3.33)
disp 'COMPUTER PROGRAMMING LAB GRADE IS : A-';
else if (cpl>3.00)
disp 'COMPUTER PROGRAMMING LAB GRADE IS : B+';
else if (cpl>2.67)
disp 'COMPUTER PROGRAMMING LAB GRADE IS : B';
else if (cpl>2.33)
disp 'COMPUTER PROGRAMMING LAB GRADE IS : B-';
else if (cpl>2.00)
disp 'COMPUTER PROGRAMMING LAB GRADE IS : C+';
else if (cpl>1.67)
disp 'COMPUTER PROGRAMMING LAB GRADE IS : C';
else if (cpl>1.33)
disp 'COMPUTER PROGRAMMING LAB GRADE IS : C-';
else if (cpl>1.00)
disp 'COMPUTER PROGRAMMING LAB GRADE IS :
D+';
else if (cpl==1.00)
disp 'COMPUTER PROGRAMMING LAB GRADE
IS : D';
else
disp 'COMPUTER PROGRAMMING LAB GRADE
IS : F';
end
end
end
end
end
end
end
end
end
end
%EDG LAB
if (edgl>3.67)
disp 'ENGINEERING DRAWING LAB GRADE IS : A';
else if (edgl>3.33)
disp 'ENGINEERING DRAWING LAB GRADE IS : A-';
else if (edgl>3.00)
disp 'ENGINEERING DRAWING LAB GRADE IS : B+';
else if (edgl>2.67)
disp 'ENGINEERING DRAWING LAB GRADE IS : B';
else if (edgl>2.33)
disp 'ENGINEERING DRAWING LAB GRADE IS : B-';
else if (edgl>2.00)
disp 'ENGINEERING DRAWING LAB GRADE IS : C+';
else if (edgl>1.67)
disp 'ENGINEERING DRAWING LAB GRADE IS : C';
else if (edgl>1.33)
disp 'ENGINEERING DRAWING LAB GRADE IS : C-';
else if (edgl>1.00)
disp 'ENGINEERING DRAWING LAB GRADE IS :
D+';
else if (edgl==1.00)
disp 'ENGINEERING DRAWING LAB GRADE IS
: D';
else
disp 'ENGINEERING DRAWING LAB GRADE IS
: F';
end
end
end
end
end
end
end
end
end
end
Output
Discussion and Conclusion:
In task 3 we created a cgpa calculator to calculate the cgpa of students in mat lab. The purpose for this
task was to apply different programming concepts in mat lab
Task # 04:
Write a simple code to swap the values of two variables of double type using M-file. Create the
logic in such a way that no third variable is used. Show the etime for this code.
Problem Analysis:
In task 4 we have to create such program which can take two values from user and swap it without using
the temporary variable.
The approach can be in many ways, one of them is to take two values from user 1 and 2 then add 2 with
1 and store the values in 1 after that we subtract the 1(updated) from 2 and store it in 2 so in this way
the first value is swapped and at last we subtract 1 from 2(updated) and store it in 1 and hence the
values are swapped
Algorithm:
First we will take values for x and y like x=15,y=20
Now we will add x and y so we get
x+y=35
y=x-y=35-20=15
x=x-y=35-15=20
so the final result is x=20,y=15 and hence the values are swapped.
Code:
tic
disp 'task 04 to swap numbers without using third variable ';
x=input('Enter the first number : ');
y=input('Enter the Second number : ');
disp 'Before swapping the values are : ';
disp (x);
disp (y);
x=x+y;
y=x-y;
x=x-y;
Output :
Discussion and Conclusion:
In this task we learnt about the swapping of variables without using the third variable and also noted the
time taken for execution