Matlab Assignment: 1 Submitted TO
Matlab Assignment: 1 Submitted TO
Computing Lab
MATLAB ASSIGNMENT
1 SUBMITTED TO
Mam Komal
2 SUBMITTED BY
Group 09
• Zain ul Abidin (2017-PE-16)
• Muhammad Azim (2017-Pe-41
• Anas Yaqoob (2017-PE-31)
Assignment #01
Q#1: Create a variable, myage, and store your age in it. Subtract one from the value of the
variable. Add two to the value of the variable.
2.1 PROCEDURE
• My age = 19
• Press “;” to suppress the answer
• eeSubtract b=1 from m yage
• It gives the answer 18
• Add c=2 to the variable
• Press enter to get the answer.
• Ans obtained=20
Q#2: Find a format option that would result in the following output format:
2 | Page
Group Number 09 Engineering
Computing Lab
2.2 PROCEDURE
• Use format rat to get answer in the rational form.
• Press enter to get the answer.
• Answer = 67/112
Q#3: Think about what the results would be for the following expressions, and then type them
to verify your answers.
a) 25 / 4 * 4
2.3 PROCEDURE
3 | Page
Group Number 09 Engineering
Computing Lab
• So, it is verified.
b) 3 + 4 ^ 2
2.4 PROCEDURE
• Assigned any value to the variables.
• Let say; a=3, b=4
• Answer should be 19 according to the question.
• Solving on MATLAB gives the same answer.
• Hence, verified.
4 \ 12 + 4
• Assigned any value to the variables.
• Let say; a=4, b=12
• Ans should be 7 according to the question.
• Solving on MATLAB gives the same answer.
• Hence, proved.
c) 3 ^ 2
• Assigned any value to the variables.
• Let say; a=3, b=2
• Answer should be 9 according to the question
• Solving on MATLAB gives the same answer
• Hence, verified
4 | Page
Group Number 09 Engineering
Computing Lab
d) (5 – 2) * 3
Q#4: Create a variable, pounds, to store a weight in pounds. Convert this to kilograms and
assign the result to a variable kilo. The conversion factor is 1 kilogram = 2.2 pounds.
Q#5: The combined resistance RT of three resistors R1, R2, and R3 in parallel is given by
5 | Page
Group Number 09 Engineering
Computing Lab
Create variables for the three resistors and store values in each, and then calculate the
combined resistance.
2.7 PROCEDURE
• Let R1=3 Ω, R2=4, R3=5 Ω
• Now by using formula,
• We get the total resistance =1.2766 Ω
Q#6: Create a variable ftemp to store a temperature in degrees Fahrenheit (F). Convert this
to degrees Celsius and store the result in a variable ctemp. The conversion factor is C = (F –
32) * 5/9.
2.8 PROCEDURE
• Let, Temperature in oF =ftemp=97oF
• Convert it into oC by using given formula
• Ctemp=36.111oC
Q#7: A vector can be represented by its rectangular coordinates x and y or by its polar
coordinates r and theta. The relationship between them is given by the equations:
Assign values for the polar coordinates to variables r and theta. Then, using these values,
assign the corresponding rectangular coordinates to variables x and y.
6 | Page
Group Number 09 Engineering
Computing Lab
Q#8: Wind often makes the air feel even colder than it is. The Wind Chill Factor (WCF)
measures how cold it feels with a given air temperature T (in degrees Fahrenheit) and wind
speed (V, in miles per hour). One formula for the WCF is:
Wind Chill Factor= 35.7 + 0.6 T – 35.7 V0.16 + 0.43 T V0.16
Create variables for the temperature T and wind speed V, and then using this formula
calculate the WCF.
2.9 PROCEDURE
• Let; T=23 oF, V=200 miles per hour
• Put values of the variables according
to question.
• Applying the formula in the
MATLAB, Answer given is -10.7494
7 | Page
Group Number 09 Engineering
Computing Lab
a) √19
2.10 PROCEDURE
• First assigned the variable ‘a’
• For square root use the command sqrt.
• Put variable in the brackets.
• And on pressing enter, get the answer.
• Answer = 4.3589
b) 31.2
2.11 PROCEDURE
• Assign both values the variable a=3 and b=1.2.
• By using cap on keyboard, we can get the superscript power
• Answer = 3.7372
c) tan π
2.12 PROCEDURE
• Assigned any value to the pi
• Let pi=30
• Then find its value on MATLAB
• Answer = -6.4053
a) 3 4 5 6
8 | Page
Group Number 09 Engineering
Computing Lab
2.13 PROCEDURE
• Let assign the variable ‘c’.
• The colon operator allows to create an equally
spaced vector of values using the more general form
start:step:end
• In the given question, we start with 3 and end at 6
and each step of 1.
b) 1 1.5 2 2.5 3
2.14 PROCEDURE
• Let assign the variable ‘b’.
• The colon operator allows to create an equally spaced vector of values using the more
general form start:step:end
• In the given question we start with 1 and end at 3 and the step of 0.5
c) 5 4 3 2
2.15 PROCEDURE
• Let assign the variable ‘b’
• The colon operator allows to create an equally spaced
vector of values using the more general form
start:step:end
• In the given question we start with 5and end at 2 and
the step of -1.
a) 4 6 8
9 | Page
Group Number 09 Engineering
Computing Lab
2.16 PROCEDURE
• The linspace function creates a linearly spaced vector
• linspace(x,y,n) creates a vector with n values in the
inclusive range from x to y.
• “x” is the start and the “y” is the end, “n” is the no.
of total values.
• MATLAB itself decides the interval for this range.
• Where x=4, y=8 and n=3
b) -3 -6 -9 -12 -15
2.17 PROCEDURE
• The linspace function creates a linearly
spaced vector
• linspace(x,y,n) creates a vector with n
values in the inclusive range from x to y.
• “x” is the start and the “y” is the end, “n”
is the no. of total values
• MATLAB itself decides the interval for
this range.
• Where x=-3, y=-15 and n=5
c) 9 7 5
2.18 PROCEDURE
• The linspace function creates a linearly spaced vector
• linspace(x,y,n) creates a vector with n values in the inclusive range from x to y.
• “x” is the start and the “y” is the end, “n” is the no.
of total values
• MATLAB itself decides the interval for this range.
• Where x=9, y=5 and n=3
10 | P a g e
Group Number 09 Engineering
Computing Lab
7 8 9 10
12 10 8 6
2.19 PROCEDURE
• First, assign the name “a” to the matrix
• Then, press enter to show the matrix
• Refer the element in the first row, third column
by giving the command a (1,3)
• That is shown 9 on MATLAB
2.20 PROCEDURE
11 | P a g e
Group Number 09 Engineering
Computing Lab
2.21 PROCEDURE
• After assigning the name to the matrix as “a”, give
the command a (1:2, 1;2)
• This will refer to the first two columns in
MATLAB
Using this matrix, find a simple expression that will transform the matrix into each of
the following
2 7
5 5
8 3
Ans:
12 | P a g e
Group Number 09 Engineering
Computing Lab
2X=3Y+1
X+Y=4
Ans
A= 2 2 B=1 2
4 4 3 4
Prove that
a) A+B=B+A
13 | P a g e
Group Number 09 Engineering
Computing Lab
b) A-B= - (B-A)
Ans:
a) A+B=B+A
Hence proved.
b) A-B= - (B-A)
Hence proved.
14 | P a g e
Group Number 09 Engineering
Computing Lab
Q#16: Plot a same graph of the following functions using values of x=-2 to 2.
y=x2
y=3x-2
Also label the axes and suggest a suitable title for the plot.
Ans:
15 | P a g e
Group Number 09 Engineering
Computing Lab
16 | P a g e