matlab 我用的lsqcurvefit进行拟合,代码如下:x=[1 2 3 4 5 6 7 8 9 10 11 12

问题描述:

matlab
我用的lsqcurvefit进行拟合,代码如下:x=[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
];y=[148 149 150 151 153 155 156 154 146 129 102 69 51 44 43 41 41 43 43 43];c0=[1 1 1 1];
x=lsqcurvefit('feimi',c0,xdata,y);feimi文件的内容如下
function f = feimi(c,xdata)
%UNTITLED2 Summary of this function goes here
% Detailed explanation goes here
f=c(4)/(exp((xdata-c(2))/c(3))+1)+c(1);
% f=c(1)*xdata+c(2)*xdata*xdata+c(3)*xdata*xdata*xdata+c(4);
end
为啥有错误呢,应该怎么改呢
1个回答 分类:综合 2014-11-03

问题解答:

我来补答
可以这样改:
function f = feimi(x,xdata)
%UNTITLED2 Summary of this function goes here
% Detailed explanation goes here
f=x(4)./(exp((xdata-x(2))./x(3))+1)+x(1);
% f=c(1)*xdata+c(2)*xdata*xdata+c(3)*xdata*xdata*xdata+c(4);
end
上面保存为feimi.m,在命令行输入
xdata=1:20;
ydata=[148 149 150 151 153 155 156 154 146 129 102 69 51 44 43 41 41 43 43 43];
x0=[1 1 1 1];
[x fval]=lsqcurvefit('feimi',x0,xdata,ydata)
结果:
Optimization terminated:first-order optimality less than OPTIONS.TolFun,
and no negative/zero curvature detected in trust region model.
x =
144.8182 11.4118 -0.0146 -98.3737
fval =
3.1999e+003
 
 
展开全文阅读
剩余:2000
上一页:一道物理提题