2306316 Comp Appl Chem Ind
MATLAB Problem Set 4
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
Obtain and plot the first through fourth-degree polynomials for the following data:
x = 0, 1, … ,5 and y = 0, 1, 60, 40, 41, and 47.
Sol
>> x=[0:1:5];
>> y=[0 1 60 40 41 47];
>> p1=polyfit(x,y,1)
p1 =
9.5714 7.5714
>> p2=polyfit(x,y,2);
>> p3=polyfit(x,y,3);
>> p4=polyfit(x,y,4);
>> xp=[0:.1:5];
>> yp1=polyval(p1,xp);
>> yp2=polyval(p2,xp);
>> yp3=polyval(p3,xp);
>> yp4=polyval(p4,xp);
>> plot(xp,yp1,'--r')
>> hold on
>> plot(xp,yp2,':k')
>> plot(xp,yp3,'-.c')
>> plot(xp,yp4,'-y')
>> ylabel('Y');
>> xlabel('X');
>> legend('yp1','yp2','yp3','yp4')
>> plot(xp,yp4,'+b')
Problem 2
On average the surface area A of human beings is related to weight W and height H. Measurements
2
on a number of individuals of height 180 cm and different weights (kg) give values of A (m ) in the
following table:
Show that a power law fits these data reasonably well. Create a plot displaying both the data (using
square symbols) and the power law relationship (using a solid line). Evaluate the constants b and m,
and predict what the surface area is for a 95-kg person.
Sol
>> W=[70 75 77 80 82 84 87 90];
>> A=[2.1 2.12 2.15 2.2 2.22 2.23 2.26 2.3];
>> p=polyfit(log(W),log(A),1)
p=
0.3799 -0.8797
>> m=p(1)
m=
0.3799
>> b=exp(p(2))
b=
0.4149
>> Wi=[70 75 77 80 82 84 87 90];
>> Ai=b*(Wi.^m);
>> plot(W,A,'o',Wi,Ai,'--r')
>> plot(W,A,'s',Wi,Ai,'--r')
>> xlabel('Weight(kg)')
>> ylabel('Area(sqm)')
2.3
2.25
2.2
Area(sqm)
A
Ai
2.15
2.1
2.05
70 72 74 76 78 80 82 84 86 88 90
Weight(kg)
>> A=0.4149*(95^0.3799)
A = 2.3403 square meter . ##############################################
Problem 3
When a constant voltage was applied to a certain motor initially at rest, its rotational speed s(t)
versus time was measured. The data appears in the following table:
Fit the following function with the data. Find the values of the constants b and c. Plot the function
along with the data in the same chart. Comment whether the function can describe the data.
Sol
>> s=[1210 1866 2301 2564 2724 2881 2879 2915 2975 3010];
>> t=[1 2 3 4 5 6 7 8 9 10];
>> p=polyfit(t,log(s),1)
p=
0.0791 7.3696
>> m=p(1)
m=
0.0791
>> b=exp(p(2))
b=
1.5869e+003
>> xi=1:0.1:10;
>> si=b*exp(m*xi)
>> plot(t,s,'o',ti,si,'+')
>> xlabel('Time(sec)');
>> ylabel('Speed(rpm)');
This function can’t describe this data. #######################
Problem 4
o
A mixture of benzene and toluene with p percent benzene and (100-p) percent toluene at 10 C is
o
fed continuously to a vessel in which the mixture is heated to 50 C. The liquid product is 40
percent benzene and the vapor product is 68.4 percent benzene. Using the conservation of the
overall mass, we obtain the equation
V+L=1
where V is the vapor mass and L is the liquid mass. Using the conservation of benzene mass, we
obtain the equation
0.684V + 0.4L = 0.01p
Write a user-defined function that uses the left-division method to solve for V and L with p as the
function’s input argument. Test your function for the case where p = 50 percent.
Sol
M-files
function [x]=fvle(p)
p = input('Enter the percent benzene : ');
A=[1 1 ; 0.684 0.4];
b=[1 ; 0.01*p ];
x=A\b;
disp(x)
>> fvle
Enter the percent benzene : 50
0.3521
0.6479
ans =
0.3521
0.6479
Problem 5
The charge within a capacitor is given by the expression
where Q is the charge, in coulombs, i is the current, in amperes, and t is the time, in seconds.
Suppose the variation of current with time is given by the equation
Determine the charge stored within the capacitor during the first 200 seconds.
Sol
M-files
function i=I(t)
i=0.2.*exp(-0.1.*t);
>> Charge=quadl('I',0,200)
Charge =
2.0000 #################
Problem 6
-0.2x
The equation e sin(x+2) = 0.1 has 3 solutions in the interval 0 < x < 10. Find these 3 solutions.
Sol M-files
function y=f2(x)
y=exp(-0.2*x).*sin(x+2)-0.1;
>> x=0:.1:10;
>> plot(x,f2(x))
>> grid on
0.8
0.6
0.4
0.2
-0.2
-0.4
-0.6
-0.8
0 1 2 3 4 5 6 7 8 9 10
>> xzero=fzero('f2',8)
xzero =
7.0066
>> xzero=fzero('f2',5)
xzero =
4.5334
>> xzero=fzero('f2',2)
xzero =
1.0187
Problem 7
-0.2x
The function y = 1 + e sin(x+2) has 2 minimum points in the interval 0 < x < 10. Find the values
of x and y at each minimum.
Sol M-files
function y=f7(x)
y=exp(-0.2*x).*sin(x+2)+1;
>> x=0:.1:10;
>> plot(x,f7(x))
>> grid on
2
1.8
1.6
1.4
1.2
0.8
0.6
0.4
0 1 2 3 4 5 6 7 8 9 10
>> [xmin fval]=fminbnd('f7',0.25,3)
xmin =
2.5150
fval =
0.4070
>> [xmin fval]=fminbnd('f7',7,10)
xmin =
8.7982
fval =
0.8312