做视频好用的素材网站宠物美容师宠物美容培训学校
本帖最后由 wangmanyi_1981 于 2013-8-11 20:12 编辑
做一个非线性拟合,拟合函数的不是一个表达式,需要通过多步计算才能得到。
看到大家的介绍一般都是:
ft=fittype('a*x^2+b*x+c','indpendent','x')
f=fit(x,y,ft)
这样的写法当然没问题,但拟合方程必须用'a*x^2+b*x+c'字符串的形式表达出来。
我在fittype帮助中看到:
he following example demonstrates how to fit a curve definedby an file. First define a function in a MATLAB file:
function y = piecewiseLine( x, a, b, c, d, k )
% PIECEWISELINE A line made of two pieces% that is not continuousy = zeros( size( x ) );
% This example includes a for-loop and if statement
% purely for demonstration purposes.
for i = 1:length( x )
if x(i) < k,
y(i) = a + b.* x(i);
else
y(i) = c + d.* x(i);
end
end
end
Enter the following commands to define some data, create a fittype specifyingthe function piecewiseLine, create a fit with the fittype,and plot the results:
x = [0.81;0.91;0.13;0.91;0.63;0.098;0.28;0.55;...
0.96;0.96;0.16;0.97;0.96];
y = [0.17;0.12;0.16;0.0035;0.37;0.082;0.34;0.56;
...0.15;-0.046;0.17;-0.091;-0.071];
ft = fittype( 'piecewiseLine( x, a, b, c, d, k )' )
f = fit( x, y, ft, 'StartPoint', [1, 0, 1, 0, 0.5] )
plot( f, x, y )
说明可以将fittype(expr)中的expr写成函数名(带输入参数)
我自己写了如下程序,运行过不去,请教高手:
建立一个function文件,名为: y_carb = isothermal_optimization_nlffuc( x,HA,bAB,lamanaA )
然后再script文件中写代码:
.......
ft=fittype('isothermal_optimization_nlffuc( x,HA,bAB,lamanaA )')
[rst,err]=fit(x,y,ft)
......
运行script后提示:
??? Error using ==> fittype.fittype>fittype.fittype at 280
Expression isothermal_optimization_nlffuc( x,HA,bAB,lamanaA ) is not a valid MATLAB expression,
has non-scalar coefficients, or cannot be evaluated:
Error in fittype expression ==> isothermal_optimization_nlffuc( x,HA,bAB,lamanaA )
??? Matrix dimensions must agree.Error in ==> isothermal_optimization_main at 202
ft= fittype( 'isothermal_optimization_nlffuc( x,HA,bAB,lamanaA )' )
从报错提示上看,系统还是认为expr字符串应该为一个表达式,不把他作为帮助文档例子中的函数名对待,
请问是什么原因造成的呢?
是不是在哪里还有设置选项?
谢谢