%編寫完畢,保存爲hth.m
Thta=(x(3)-x(4))./((1+(x(1).*ht).^x(2)).^(1-(1./x(2))))+x(4);
%不運行hth.m,而是進行下一步驟,否則提示x未定義
ht=[0 27.2 53.04 62.56 69.36 81.60 95.20 108.80 126.48 159.12 197.20 251.60 262.48 286.96 359.04 452.88 503.20];
th=[476 434 406 401 392 382 365 351 335 312 287 271 261 253 252 236 234]*0.001;
x0=[0.1 1.5 0.5 0.1];
x1=[0 1 0 0];
x2=[5 5 1 1];
[x resnorm]=lsqcurvefit(@hth,x0,ht,th,x1,x2)
ht=[0 27.2 53.04 62.56 69.36 81.60 95.20 108.80 126.48 159.12 197.20 251.60 262.48 286.96 359.04 452.88 503.20];
th=[476 434 406 401 392 382 365 351 335 312 287 271 261 253 252 236 234]*0.001;
x0=[0.1 1.5 0.5 0.1];
x1=[0 1 0 0];
x2=[5 5 1 1];
[x,res]=lsqcurvefit(f,x0,ht,th,x1,x2)
y1=fx(x,ht);
plot(th,ht,' o',y1,ht,'-')
fun=inline('(x(3)-x(4))./((1+(x(1).*ht).^x(2)).^(1-(1./x(2))))+x(4)','x','ht');
ht=[0 27.2 53.04 62.56 69.36 81.60 95.20 108.80 126.48 159.12 197.20 251.60 262.48 286.96 359.04 452.88 503.20];
th=[476 434 406 401 392 382 365 351 335 312 287 271 261 253 252 236 234]*0.001;
x0=[0.1 1.2 0.5 0.1];
[x,r,J]=nlinfit(ht,th,fun,x0);
x
R=sum(r.^2) %誤差平方和
y=fun(x,ht);
plot(th,ht,'*',y,ht,'-r')
%y(x)=c1+c2*exp(-3*x)+c3*cos(-2*x).*exp(-4*x)+c4*x.^2
x=[0 0.2 0.4 0.7 0.9 0.92 0.99 1.2 1.4 1.48 1.5]';
y=[2.88 2.2576 1.9683 1.9258 2.0862 2.109 2.1979 2.5409 2.9627 3.155 3.2052]';
A=[ones(size(x)),exp(-3*x),cos(-2*x).*exp(-4*x),x.^2];
c=A\y; %最小二乘解
c1=c'
x0=[0:0.01:1.5]';
A1=[ones(size(x0)),exp(-3*x0),cos(-2*x0).*exp(-4*x0),x0.^2];
y1=A1*c;
plot(x0,y1,x,y,'rx');
p=polyfit(x,y,2)
y1=polyval(p,x);
plot(x,y1,x,y,'ro')