问题描述:
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);哪位高手指点一下!感激不尽!
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);哪位高手指点一下!感激不尽!
问题解答:
我来补答展开全文阅读