# Mathlab

Topics: Optimization, Maxima and minima Pages: 6 (456 words) Published: April 23, 2013
%Question a)Equation 1

%T in unit celcius
T=[
77
77
63.5
53.3
53.3
77.6
77.6
77.6
52.9
52.9
77.6
62.7
53.7
53.7
79.5
79.5
64.0
64.0
54.5
39.2
38.3
49.4
40.2
40.2
40.2
40.2
39.7
40.2
40.2
40.2
39.9
39.9
39.8];
%rate constant k in unite mol/m^3
kE5=[
2.70
2.87
1.48
0.71
0.66
2.44
1.26
2.40
0.72
0.70
2.40
1.42
0.69
0.68
3.03
3.06
1.31
1.37
0.70
0.146
0.159
0.260
0.284
0.323
0.283
0.284
0.277
0.318
0.323
0.326
0.312
0.314
0.307]*10^5;
TKelvin=T+273; % change to kelvin
Tnew=1./TKelvin;
knew=log10(kE5);
R= 82.05746; %cm^3?atm.?K^?1.?mol^?1
polyfit(Tnew,knew,1)
c1=polyfit(Tnew,knew,1);
polyval(c1,Tnew);
plot(Tnew,knew,'b*',Tnew,polyval(c1,Tnew))

Command window
>> classwork_week4

ans =

1.0e+03 *

-2.8178 0.0134

%Question a)Equation 2
Tabs=298;% unit kelvin
TKelvin_2=1/Tabs-1./TKelvin;
polyfit(TKelvin_2,knew,1)
c1=polyfit(TKelvin_2,knew,1);
polyval(c1,TKelvin_2);
plot(TKelvin_2,knew,'b*',TKelvin_2,polyval(c1,TKelvin_2))

Command window
>> classwork_week4

ans =

1.0e+03 *

2.8178 0.0040

Editor
%Question b) Equation 1
function f=classworkfuncequation1(a,Tnew)
A=a(1);
B=a(2);
f=A*exp(-B.*Tnew);

Command window
Cguessequation1=[1 1];
>> Cnew=nlinfit(Tnew,knew,@classworkfuncequation1,Cguessequation1)

Cnew =

27.6813 572.1670

>> Cguessequation1=[1 1];
>> Cnew=lsqcurvefit(@classworkfuncequation1,Cguessequation1,Tnew,knew)

Local minimum found.

Optimization completed because the size of the gradient is less than the default value of the function tolerance.

<stopping criteria details>

Cnew =

27.6813 572.1670

Editor
%Question b) Equation 2

function f=classworkfunc(a,TKelvin_2)
A=a(1);
B=a(2);
f=A*exp(-B.*TKelvin_2);

Command Window

>> Cguessequation2=[1 1];
>> Cnew=nlinfit(TKelvin_2,knew,@classworkfunc,Cguessequation2)

Cnew =

4.0582 -572.1669

>> Cguessequation2=[1 1];
>> Cnew=lsqcurvefit(@classworkfunc,Cguessequation2,TKelvin_2,knew)

Local minimum found.

Optimization completed because the size of the gradient is less than the default value of the function tolerance.

<stopping criteria details>

Cnew =

4.0582 -572.1670

>> classwork_week4

ans =

1.0e+03 *

-2.8178 0.0134

ans =

1.0e+03 *

2.8178 0.0040

%Question c)
%plot graph
plot = (Tnew,knew,'b*',Tnew,polyval(c1,Tnew),TKelvin_2,knew,'b*',TKelvin_2,polyval(c1,TKelvin_2)).

Please join StudyMode to read the full document