初学者求帮忙!
![matlab非线性分段方程拟合 急~谢谢~]()
如图所示是一组非线性分段方程,其中待拟合参数有:T0,Ta,tm,δT,以及分段点ts。
我尝试使用lsqcurvefit进行拟合,但是代码编写有一些问题。。查阅相关资料也不太知道这种分段点就是未知参数的方程应该如何编程,希望大家给予帮助
xdata = [ 5.5000 6.5000 7.5000 8.5000 9.5000 10.5000 11.5000 12.5000 13.5000 14.5000 15.5000 16.5000 17.5000 18.5000 19.5000 20.5000 21.5000 22.5000 23.5000 24.5000 1.5000 2.5000 3.5000 4.5000];
ydata = [299.0545 300.8932 304.5193 308.6715 311.6907 315.0223 315.7924 317.1786 315.0809 313.1319 312.8464 309.4712 305.4651 304.1893 302.5152 301.9055 303.4350 299.9959 299.2613 299.7677 299.4591 298.5113 298.7621 298.6650];
x0 = [299.05 40 14 0.5 17.4];
function F = fun(x,xdata)
if xdata > x(5)
w = 4/3*(x(3) - 5.4);
F = a + b*cos( 3.14/w.*( xdata -c ) );
elseif xdata <= x(5)
w = 4/3*(c - 5.4);
k = w/3.14 * ( atan( 3.14/w*(x(5)-x(3)) ) - d/b*asin( 3.14/w*( x(5)-x(3) ) ) );
F = a + d + ( b*cos( 3.14/w*(ee-c) ) - d ) * k/( k + xdata - ee );
end
end
[x,resnorm] = lsqcurvefit(@fun,x0,xdata,ydata);
这样运行之后会报错:
Error using feval
Output argument "F" (and maybe others)
not assigned during call to
"F:\DTC\pros\fun1012.m>fun1012".
Error in lsqcurvefit (line 203)
initVals.F =
feval(funfcn_x_xdata{3},xCurrent,XDATA,varargin{:});
Caused by:
Failure in initial user-supplied
objective function evaluation.
LSQCURVEFIT cannot continue.
最后应该就是没有F的返回值了。。。我这个语句写的应该是肯定有问题但是我不太知道是什么问题。。希望能够请高人指点一下 谢谢!!!!! |