clear,clc
%question 1
T=[293.65 295.65 297.65 299.65 301.65 303.9]';
P=[750 5940 6350 6600 6940 7300]';
P=log10(P);
fx1=@(b,x)b(1)+b(2)./(x+b(3));
b1=[9 0.5 -293];
for l=1:5
b1=lsqcurvefit(fx1,b1,T,P);
b1=nlinfit(T,P,fx1,b1);
end
b1
figure(1),clf
plot(T,P,'o','markerfacecolor','k')
hold on
x11=linspace(min(T),max(T),200);
y11=fx1(b1,x11);
plot(x11,y11,'r-','linewidth',2)
legend('data','fit','location','best')
axis tight
%question 2
x2=[-67.4, -60.4, -54.5, -48.1, -44.4, -44.0, -40.0, -30.0, -20.0, -10.0, 0, 10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 64.7, 70.0, 80.0, 90.0, 100.0, 110.0, 120.0, 130.0, 140.0, 150.0, 160.0, 170.0, 180.0, 190.0, 200.0, 210.0, 220.0, 230.0, 240.0]';
y2=[0.102, 0.212, 0.378, 0.702, 0.982, 1.0, 2.0, 4.0, 8.0, 15.5, 29.6, 54.7, 96.0, 160.0, 260.5, 406.0, 625.0, 760.0, 927.0, 1341.0, 1897.0, 2621.0, 3561.0, 4751.0, 6242.0, 8071.0, 1.034*10^4, 1.303*10^4, 1.629*10^4, 2.009*10^4, 2.461*10^4, 2.979*10^4, 3.577*10^4, 4.257*10^4, 5.041*10^4, 5.966*10^4]';
fx2=@(b,x)b(1)+b(2)*exp(b(3)*x+b(4)*x.^2);
b2=[-105 110 0.04 -.0001];
for l=1:5
b2=lsqcurvefit(fx2,b2,x2,y2);
b2=nlinfit(x2,y2,fx2,b2);
end
b2
figure(2),clf
plot(x2,y2,'o','markerfacecolor','k')
hold on
x21=linspace(min(x2),max(x2),200);
y21=fx2(b2,x21);
plot(x21,y21,'r-','linewidth',2)
legend('data','fit','location','best')
axis tight |