Labfans是一个针对大学生、工程师和科研工作者的技术社区。 | 论坛首页 | 联系我们(Contact Us) |
![]() |
|
![]() |
#1 |
初级会员
注册日期: 2013-05-09
年龄: 38
帖子: 7
声望力: 0 ![]() |
![]()
function [] = lsqFuncTion()
%与指数模型Y=b*exp(a*T)拟合 T=[0 120 744 912 1080 1248 1416 1584 1752 1920 2088 2256 2424 2592]; % f2=feval(fun2, b, T); %fun2=@(b,T)b(1)*exp(b(2)*T) %fun2 = inline('b(1)*exp(b(2)*T)', 'b', 'T'); %fun2 = inline('b(1) .* T + b(2)', 'b', 'T'); Z=[0.523 0.523 0.175 0.525 0.524 1.989 0.525 1.989 1.989 1.989 0.523 0.524 0.524 0.525 0.523 0.52 0.52 0.964 0.52 0.521 0.521 0.909 1.133 1.989 1.989 0.519 0.52 0.521 0.521 0.521 0.512 0.511 0.178 0.513 0.512 1.012 1.091 0.512 0.517 0.127 0.512 0.512 0.512 0.512 0.77 0.52 0.52 1.024 0.958 0.513 0.511 0.512 0.944 0.912 0.112 0.512 1.989 1.989 1.989 1.515 0.512 0.512 0.175 0.521 0.523 0.522 0.524 1.989 1.989 1.989 0.523 1.989 1.989 0.199 1.989 0.523 0.523 0.87 0.521 0.516 0.989 0.518 0.517 0.517 0.517 1.989 0.516 0.516 0.516 0.515 0.512 0.512 0.871 0.525 0.527 1.42 0.643 1.993 1.083 0.097 0.519 1.989 1.989 1.989 1.989 0.515 0.515 0.836 0.513 0.524 0.524 0.525 0.524 1.348 0.524 1.989 0.523 0.524 0.523 0.523 0.519 0.519 0.888 0.517 0.521 0.521 0.521 1.053 0.86 0.099 1.948 0.519 0.52 0.521 0.521]; i=0; while i<9 i=i+1; Y=Z(i, ![]() %Y = fun2( [1511, 0.958], T); %for test, use a idea data [b, resnorm2]=lsqcurvefit(@fun2, [, ], T, Y); %--for child fun2 %b =lsqcurvefit(fun2, [0, 0], T, Y); %--for inline fun2 % 函数的拟合值 F2(:,i)=fun2( b, T); R2(:,i)=resnorm2; para21=b(1,1); A2(:,i)=para21; para22=b(1,2); B2(:,i)=para22; bb(i, ![]() end bb(1,1 )= 111; %------------------------- function Y = fun2(b, T) Y = b(1)*exp(T.*b(2)); 总是报错 ??? Error using ==> optim\private\lsqncommon Function value and YDATA sizes are incommensurate. Error in ==> lsqFuncTion at 27 [b, resnorm2]=lsqcurvefit(@fun2, [1511, 0.958], T, Y); %--for child fun2 我那个初值不知道该怎么取,总是。。。还求高手指点!不胜感激!致礼! |
![]() |
![]() |