【培训通知】2013年MCM优秀论文精读培训
中国数模界最第一大专业科技
(www.madio.net)数学中国 数学建模思想方法大全精讲专题
第数学建模思想方法大全精讲专题
数学建模精品资源课程系列
国内专业的数学建模实训
如题,利用lsqcurvefit和lsqnonlin两个函数进行非线性拟合,总是提前收敛,求大神解释为什么?是否是更改里面的options选项,具体怎么改?在线等,万谢。。。
1、程序代码如下:
1)编写M-文件 curvefun1.m
function f=curvefun1(x,tdata)
f=1-exp(-6.908*(((tdata-x(1))./x(2)).^x(3)));
%其中 x(1)=cb; x(2)=cb-cc;x(3)=m+1;
2)输入命令
tdata=[………];
ydata=[………];
x0=[-10,55,2];
[x,resnorm] =lsqcurvefit('curvefun1',x0,tdata,ydata)
f= curvefun1(x,tdata);
3) 结果
Local minimum possible.
lsqcurvefit stopped because the finalchange in the sum of squares relative to its initial value is less than the defaultvalue of the function tolerance.
x =
Columns 1 through 2
-3.59020088832205 - 0.62244270778384i 53.9542595923814 + 0.14425192684233i
Column 3
2.69114674932468 + 0.0818892331391404i
resnorm =
0.00627209364358831
2、函数介绍如下:
1)函数 lsqcurvefit
2)格式 x = lsqcurvefit(fun,x0,xdata,ydata)
x =lsqcurvefit(fun,x0,xdata,ydata,lb,ub)
x =lsqcurvefit(fun,x0,xdata,ydata,lb,ub,options)
[x,resnorm] = lsqcurvefit(…)
[x,resnorm,residual] = lsqcurvefit(…)
[x,resnorm,residual,exitflag] =lsqcurvefit(…)
[x,resnorm,residual,exitflag,output]= lsqcurvefit(…)
[x,resnorm,residual,exitflag,output,lambda]= lsqcurvefit(…)
[x,resnorm,residual,exitflag,output,lambda,jacobian]=lsqcurvefit(…)
3)参数说明:
x0为初始解向量;xdata,ydata为满足关系ydata=F(x, xdata)的数据;
lb、ub为解向量的下界和上界,若没有指定界,则lb=[ ],ub=[ ];
options为指定的优化参数;
fun为拟合函数,其定义方式为:x = lsqcurvefit(@myfun,x0,xdata,ydata),
其中myfun已定义为 function F = myfun(x,xdata)
F = … % 计算x处拟合函数值fun的用法与前面相同;
resnorm=sum ((fun(x,xdata)-ydata).^2),即在x处残差的平方和;
residual=fun(x,xdata)-ydata,即在x处的残差;
exitflag为终止迭代的条件;
output为输出的优化信息;
lambda为解x处的Lagrange乘子;
jacobian为解x处拟合函数fun的jacobian矩阵。
Examples
FUN can be specified using @:
xdata = [5;4;6]; % example xdata
ydata = 3*sin([5;4;6])+6; % example ydata
x = lsqcurvefit(@myfun, [2 7], xdata, ydata)
where myfun is a MATLAB function such as:
function F = myfun(x,xdata)
F = x(1)*sin(xdata)+x(2);
FUN can also be an anonymous function:
x = lsqcurvefit(@(x,xdata) x(1)*sin(xdata)+x(2),[2 7],xdata,ydata)
If FUN is parameterized, you can use anonymous functions to capture the
problem-dependent parameters. Suppose you want to solve the
curve-fitting problem given in the function myfun, which is
parameterized by its second argument c. Here myfun is a MATLAB file
function such as
function F = myfun(x,xdata,c)
F = x(1)*exp(c*xdata)+x(2);
To solve the curve-fitting problem for a specific value of c, first
assign the value to c. Then create a two-argument anonymous function
that captures that value of c and calls myfun with three arguments.
Finally, pass this anonymous function to lsqcurvefit:
xdata = [3; 1; 4]; % example xdata
ydata = 6*exp(-1.5*xdata)+3; % example ydata
c = -1.5; % define parameter
x = lsqcurvefit(@(x,xdata) myfun(x,xdata,c),[5;1],xdata,ydata)
Examples
FUN can be specified using @:
x = lsqnonlin(@myfun,[2 3 4])
where myfun is a MATLAB function such as:
function F = myfun(x)
F = sin(x);
FUN can also be an anonymous function:
x = lsqnonlin(@(x) sin(3*x),[1 4])
If FUN is parameterized, you can use anonymous functions to capture the
problem-dependent parameters. Suppose you want to solve the non-linear
least squares problem given in the function myfun, which is
parameterized by its second argument c. Here myfun is a MATLAB file
function such as
function F = myfun(x,c)
F = [ 2*x(1) - exp(c*x(1))
-x(1) - exp(c*x(2))
x(1) - x(2) ];
To solve the least squares problem for a specific value of c, first
assign the value to c. Then create a one-argument anonymous function
that captures that value of c and calls myfun with two arguments.
Finally, pass this anonymous function to lsqnonlin:
c = -1; % define parameter first
x = lsqnonlin(@(x) myfun(x,c),[1;1])