Matlab:曲线拟合中的错误 [英] Matlab :Error in Curve fitting

查看:543
本文介绍了Matlab:曲线拟合中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经描述了一个模型,我想拟合到曲线"中,在这种情况下我遇到了一个错误,请仔细检查.

I have described a model and i would like to fit in the Curve,I am obtaining an Error in this context , kindly review it.

function c = model(t, a1, a2, a3, b1, b2, b3, td, tmax)

c = zeros(size(t));

ind = (t > td) & (t < tmax);
c(ind) = (t(ind) - td) ./ (tmax - td) * (a1 + a2 + a3);

ind = (t >= tmax);
c(ind) = a1 * exp(-b1 * (t(ind) - tmax))+ a2 * exp(-b2 * (t(ind) - tmax)) + a3 * exp(-b3 * (t(ind) - tmax));




ft = fittype('model(t, a1, a2, a3, b1, b2, b3, td, tmax)', 'independent','t');
fo = fit(t, c, ft,'StartPoint', [20000, 20000, 20000, 0.01, 0.01, 0.01, 10, 30],'Lower', [0, 0, 0, 0, 0, 0, 0, 0]);
plot(t, c, 'x')
hold all
ts = 0:0.1:50;
plot(ts, model(ts, fo.a1, fo.a2, fo.a3, fo.b1, fo.b2, fo.b3, fo.td, fo.tmax))
axis([0 50 -2000 80000])
xlabel time
ylabel concentration    

end

以下是我遇到的错误

Error in fittype expression ==> model(t, a1, a2, a3, b1, b2, b3, td, tmax)
??? Expression model(t, a1, a2, a3, b1, b2, b3, td, tmax) is not a valid MATLAB
expression,
 has non-scalar coefficients, or cannot be evaluated:

请问我是否正确使用了fittype表达式

Could you please review if i have used fittype expression correctly

推荐答案

创建一个保存模型的函数:

Create a function that holds the model:

function c = modelfnc(t, a1, a2, a3, b1, b2, b3, td, tmax)
...    
end

然后将其余代码放入主函数(另一个文件)中.另外,在开始拟合过程之前,您需要定义变量并获取一些数据.

Then put the rest of the code in the main function (another file). Also you need to define the variables and have some data before starting the fitting process.

define c,t,...
ft = fittype('modelfnc(t, a1, a2, a3, b1, b2, b3, td, tmax)', 'independent','t');
fo = fit(t, c, ft,'StartPoint', [20000, 20000, 20000, 0.01, 0.01, 0.01, 10, 30],'Lower', [0, 0, 0, 0, 0, 0, 0, 0]);
plot(t, c, 'x')

这篇关于Matlab:曲线拟合中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆