乘以函数曲线

时间:2015-05-24 13:41:24

标签: matlab

我使用fit()函数将曲线拟合到我的数据集中。然后我想计算这个函数的积分,所以我使用integrate()。一切正常,我得到了一个结果。现在我想从这样的函数计算积分:x*fun,其中fun是fit()函数的结果。我怎样才能做到这一点?谢谢!

1 个答案:

答案 0 :(得分:0)

如果你想按照你说的方式拥有它,你可以做这样的事情

%I'm making up a function
x = 0:0.1:10;
y = x.^2;
[ft, ~] = fit( x, y, 'poly2' );

%Put in the new formula, the formula() function puts out the formula as a string and then just pre- and append a "x*"
fitType = fittype(['x*(',formula(ft),')']);

%You need the values from the original fit, to put into the new fit, the cell array is so Matlab will read them as separate inputs
coeff = num2cell(coeffvalues(ft));

%Make the fit
NewFit = cfit(fitType, coeff{:});

%Now it's just what you did before
plot(integrate(NewFit, x, min(x))