matlab 使用lsqcurvefit函数出错 需要拟合的函数m文件:function f = nihehanshu(a,t)f = (a(1)/a(2))^a(1)*t^(a(1)-1)*exp(-t*a(1)/a(2))/gamma(a(1));程序:t = [1,1.26,1.58,2,2.51,3.16,3.98,5.01,6.31,7.94,10,12.59,15.85,19.95,25.12,31.62];
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/19 19:21:22
matlab 使用lsqcurvefit函数出错 需要拟合的函数m文件:function f = nihehanshu(a,t)f = (a(1)/a(2))^a(1)*t^(a(1)-1)*exp(-t*a(1)/a(2))/gamma(a(1));程序:t = [1,1.26,1.58,2,2.51,3.16,3.98,5.01,6.31,7.94,10,12.59,15.85,19.95,25.12,31.62];
matlab 使用lsqcurvefit函数出错
需要拟合的函数m文件:
function f = nihehanshu(a,t)
f = (a(1)/a(2))^a(1)*t^(a(1)-1)*exp(-t*a(1)/a(2))/gamma(a(1));
程序:
t = [1,1.26,1.58,2,2.51,3.16,3.98,5.01,6.31,7.94,10,12.59,15.85,19.95,25.12,31.62];
y = [0.0012,0.0024,0.0044,0.0078,0.0134,0.0217,0.033,0.0462,0.0586,0.0662,0.0656,0.0404,0.024,0.0113,0.004];
a0 = [1,1];
[a,resnorm] = lsqcurvefit(@nihehanshu,a0,t,y)
程序提示出错:
Error using ==> mpower
Matrix must be square.
Error in ==> nihehanshu at 2
f = (a(1)/a(2))^a(1)*t^(a(1)-1)*exp(-t*a(1)/a(2))/gamma(a(1));
Error in ==> lsqcurvefit at 209
initVals.F = feval(funfcn_x_xdata{3},xCurrent,XDATA,varargin{:});
Error in ==> Nakagami_fit at 47
[a,resnorm] = lsqcurvefit(@nihehanshu,a0,t,Pr)
Caused by:
Failure in initial user-supplied objective function evaluation.LSQCURVEFIT cannot continue.
matlab 使用lsqcurvefit函数出错 需要拟合的函数m文件:function f = nihehanshu(a,t)f = (a(1)/a(2))^a(1)*t^(a(1)-1)*exp(-t*a(1)/a(2))/gamma(a(1));程序:t = [1,1.26,1.58,2,2.51,3.16,3.98,5.01,6.31,7.94,10,12.59,15.85,19.95,25.12,31.62];
function f = nihehanshu(a,t)
f = (a(1)/a(2))^a(1)*t.^(a(1)-1).*exp(-t*a(1)/a(2))/gamma(a(1)); %矩阵对应元素计算,要加点
----------------------------------------------
t = [1.26,1.58,2,2.51,3.16,3.98,5.01,6.31,7.94,10,12.59,15.85,19.95,25.12,31.62];
y = [0.0012,0.0024,0.0044,0.0078,0.0134,0.0217,0.033,0.0462,0.0586,0.0662,0.0656,0.0404,0.024,0.0113,0.004]; %t和y的长度要一致
a0 = [4,13]; % lsqcurvefit 对初值的精确度要求较高
[a,resnorm] = lsqcurvefit(@nihehanshu,a0,t,y)