0% found this document useful (0 votes)
66 views

Matlab Assignment: 1 Submitted TO

Here are the steps to plot the same graph of the following functions: 1) y = x^2 2) y = 2x 1) Assign variables: x = 0:0.1:5; y1 = x.^2; y2 = 2*x; 2) Plot on the same axes: plot(x,y1,x,y2) title('Functions y=x^2 and y=2x') xlabel('x') ylabel('y') legend('y=x^2','y=2x') 3) Save and view the plot Q#17: Find the roots of the following polynomial using

Uploaded by

Zain Ul Abidin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
66 views

Matlab Assignment: 1 Submitted TO

Here are the steps to plot the same graph of the following functions: 1) y = x^2 2) y = 2x 1) Assign variables: x = 0:0.1:5; y1 = x.^2; y2 = 2*x; 2) Plot on the same axes: plot(x,y1,x,y2) title('Functions y=x^2 and y=2x') xlabel('x') ylabel('y') legend('y=x^2','y=2x') 3) Save and view the plot Q#17: Find the roots of the following polynomial using

Uploaded by

Zain Ul Abidin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Group Number 09 Engineering

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)

Department of Polymer and Process


Engineering
1 | Page
Group Number 09 Engineering
Computing Lab

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:

>> 5/16 + 2/7

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

• Assign any value to the variables.


• Let say; a=25, b=4
• Answer should be 25.
• Solving on MATLAB gives the same answer.

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

2.5 STEPS INVOLVED


• Assigned any value to the variables.
• Let say; a=5, b=2, c=3
• Answer should be 9 according to the question
• Solving on MATLAB gives the same answer
• Hence, verified

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.

2.6 STEPS INVOLVED


• Let, weight = 50pounds
• Also, 1 kilogram = 2.2 pounds
• Answer is 50 pounds is equal to the 22.7273 kilos.

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.

• Let r=6, θ=30o


• By using the given formulas, we can find the answer.

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

Q#9: Find MATLAB expressions for the following:

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

Q#10: Using the colon operator, create the following vectors

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.

Q#11: Using the linspace function, create the following vectors:

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

Q #12: Find a way to generate the following matrix:


mat =

7 8 9 10

12 10 8 6

Then, give expressions that will, for the matrix mat,

a) Refer to the element in the first row, third column

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

b) Refer to the entire second row

2.20 PROCEDURE

• After assigning the name to the matrix as “a”,


give command a (2,:)
• That will refer to the entire second row in
MATLAB

c) Refer to the first two columns

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

Q#13: Create a matrix variable, mymat, which stores the following:


mymat =
2 5 8
7 5 3

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

Q#14: Solve the system of linear equations using MATLAB

2X=3Y+1
X+Y=4

Ans

Q#15: Considering the following vectors

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

You might also like