2306316 Comp Appl Chem Ind
MATLAB Problem Set 3
Use MATLAB to solve these problems. Copy the scripts in the Command Window, M-files, and
figures [from menu bar, click edit, then choose copy figure] into a WORD document. Specify which
part comes from the Command Window or M-files.
Problem 1
The table gives data for the distance traveled along five truck routes and the corresponding time
required to travel each route. Use the data to compute the average speed required to drive each route.
Find the route that has the highest average speed.
Sol
>> distance=[560,440,490,530,370]
distance =
560 440 490 530 370
>> Time=[10.3 8.2 9.1 10.1 7.5]
Time =
10.3000 8.2000 9.1000 10.1000 7.5000
>> Average velocity=distance./Time
Average velocity =
54.3689 53.6585 53.8462 52.4752 49.3333
>> [distance, n ]=max(Average velocity)
distance =
54.3689
n=
1 >>>>> 54.3689 miles/hr & route 1 #########
Problem 2
Create, save, and run a script file that solves the following set of equations for given values of a, b,
and c. Check your file for the case a = 112, b = 75, and c = -67.
6x - 4y + 8z = a
-5x – 3y + 7z = b
14x + 9y – 5z = c
Sol
>> alg
Enter the first coefficient 112
Enter the second coefficient 75
Enter the third coefficient -67
The answer of system algebra:
2.0000
-5.0000
10.0000
Problem 3
Find the roots of
x3 + 13x2 + 52x + 6 = 0
Use the poly function to confirm your answer.
Sol
>> p=[1 13 52 6];
>> r=roots(p)
r=
-6.4406 + 2.9980i
-6.4406 - 2.9980i
-0.1189
>> p=poly(r)
p=
1.0000 13.0000 52.0000 6.0000
>>
Problem 4
Confirm that
Sol
>> u=[20 -7 5 10];
>> v=[4 12 -3];
>> w=conv(u,v)
w=
80 212 -124 121 105 -30
.
Problem 5
Confirm that
with a remainder of 59x – 41.
Sol
>> a=[12 5 -2 3];
>> b=[3 -7 4];
>> [c d]=deconv(a,b)
c=
4.0000 11.0000
d=
0 0.0000 59.0000 -41.0000
Problem 6
Plot the polynomial
y = x3 + 13x2 + 52x + 6
over the range -7 ≤ x ≤ 1.
Sol
>> x=-7:.01:1;
>> y=x.^3+13*x.^2+52*x+6;
>> plot(x,y)
>> p=polyfit(x,y,3)
p=
1.0000 13.0000 52.0000 6.0000
>> hold on
>> plot(x,y)
>> hold on
>> xp=-7:.01:1;
>> yp=polyvali(p,xp);
80
60
40
20
0
y
-20
y
-40 yp
-60
-80
-7 -6 -5 -4 -3 -2 -1 0 1
x
Problem 7
Plot the polynomials y = 3x4 – 6x3 + 8x2 + 4x + 90 and z = 3x3 + 5x2 - 8x + 70 over the interval -3
≤ x ≤ 3. Properly label the plot and each curve. The variables y and z represent current in milliamps;
the variable x represents voltage in volts.
Sol
>> py=[3 -6 8 4 90];
>> xy=-3:.1:3;
>> yy=polyval(py,xy);
>> plot(xy,yy,'o')
>> hold on
>> plot(xy,yy,'o')
>> pz=[3 -5 -8 70];
>> xz=-3:.1:3;
>> yz=polyval(pz,xz);
>> plot(xz,yz,'x')
>> hold on
>> grid on
>> hold on
>> plot(xz,yz,'x')
>> plot(xy,yy,'o')
>> xlabel('voltage in volts');
>> ylabel('current in milliamps');
>> legend('yy','yy')
>> legend('yy','yz')
>> plot(xz,yz,'--r',xy,yy,':k')
>> legend('yy','yz')
Problem 8
Create a surface plot and a contour plot of the function
Sol
>> x=0:.05:1;
>> y=1:.2:3;
>> [X,Y]=meshgrid(x,y);
>> Z=(X-2).^2+2*X.*Y+Y.^2;
>> surf(X,Y,Z)
>> contour(X,Y,Z)