matlab 非线性拟合问题,采用语句nlinfit

问题描述:

matlab 非线性拟合问题,采用语句nlinfit
A1=[0.48755108 0;0 0.41344023];
A2=[0.39875031 0;0 0.50497499];
A3=[2.3120353 0;0 2.4904862];
t1=[0.04338408 0;0 0.03684262];
t2=[0.09461442 0;0 0.09076162];
t3=[23.793604 0;0 23.771995];
weixiang=zeros(1,163);
count = 0;
for t=0.19:0.005:1.00
count = count + 1;
n = 1+(A1.*t^2)./(t^2-t1^2)+(A2.*t^2)./(t^2-t2^2)+(A3.*t^2)./(t^2-t3^2)
n0 = sqrt(n)
Ncha=n0(2,2)-n0(1,1)
w=2*pi*110.9*Ncha/t
weixiang(1,count)= w
end
y1=cos(weixiang/2).*cos(weixiang/2)
t=0.19:0.005:1.00
plot(t,y1,'+')
grid on
hold on
xlabel('bochang/um');ylabel('[cos(w/2)]^2')%做散点的过程
%非线性拟合.
A1=[0.50345678 0;0 0.41344023];
A2=[0.39875031 0;0 0.50497499];
A3=[2.3120353 0;0 2.4904862];
t1=[0.04338408 0;0 0.03684262];
t2=[0.09461442 0;0 0.09076162];
t3=[23.793604 0;0 23.771995];
t=0.19:0.005:1.00;
b=zeros(1,13)
b(1)=A1(1,1);b(2)=A1(2,2);b(3)=A2(1,1);b(4)=A2(2,2);b(5)=A3(1,1);b(6)=A3(2,2);
b(7)=t1(1,1);b(8)=t1(2,2);b(9)=t2(1,1);b(10)=t2(2,2);b(11)=t3(1,1);b(12)=t3(2,2);b(13)=0.1109
b0=[0.50345678 0.41344023 0.39875031 0.50497499 2.3120353 2.4904862 0.04338408 0.03684262 0.09461442 0.09076162 23.793604 23.771995 0.1109]
fun=inline('cos([sqrt(1+b(1)*t^2./(t^2-b(7)^2)+b(3)*t^2./(t^2-b(9)^2)+b(5)*t^2./(t^2-b(11)^2))-sqrt(1+b(2)*t^2./(t^2-b(8)^2)+b(4)*t^2./(t^2-b(10)^2)+b(6)*t^2./(t^2-b(12)^2))]*pi*b(13)./t).^2','b','t')
[b,r,j,covb,mse]=nlinfit(t,y1,fun,b0);
b
希望返回最佳参数b,但中途出错.? Error using ==> nlinfit at 114
The inline model function generated the following error:
Error using ==> inlineeval at 15
Error in inline expression ==>
cos([sqrt(1+b(1)*t^2./(t^2-b(7)^2)+b(3)*t^2./(t^2-b(9)^2)+b(5)*t^2./(t^2-b(11)^2))-sqrt(1+b(2)*t^2./(t^2-b(8)^2)+b(4)*t^2./(t^2-b(10)^2)+b(6)*t^2./(t^2-b(12)^2))]*pi*b(13)./t).^2
? Error using ==> mpower
Matrix must be square.
Error in ==> mgfzuosandianUntitled at 37
[b,r,j,covb,mse]=nlinfit(t,y1,fun,b0);哪位高手指点一下!感激不尽!
1个回答 分类:综合 2014-10-28

问题解答:

我来补答
/>补充回答:数据不好
建立函数文件:
function y = myfun(beta,x)
y = 2.350176*beta(1)*(1-1/beta(2))*(1-(1-x(:,1).^(1/beta(2))).^beta(2)).^2.*(x(:,1).^(-1/beta(2))-1).^(-beta(2)).*x(:,1).^(-1/beta(2)-0.5).*x(:,2);
运行代码:
x=[0.4292 0.4269 0.381 0.4015 0.4117 0.3017; 0.00014 0.00059 0.0126 0.0061 0.00425 0.0443];
x = x';
y=[0.517 0.509 0.44 0.466 0.479 0.309];
y = y';
beta=nlinfit(x,y,@myfun,[8 0.5])
运行结果:
beta =
-55262931764.9336 0.0517
 
 
展开全文阅读
剩余:2000