I wish to extract the fit formula or function along with its coefficients, then differentiate it to get its derivative function and also integrate the fit function to get its integration. How to do that please suggest.
load dataset.mat
x=dataset(:,1);y=dataset(:,2);
[fit, gof] = createFit(x, y)
fx = differentiate(fit,x);
df_fit=(x.^2)*3+2*x.+1;
plot(x,[fx-dif_fit])
function [fitresult, gof] = createFit(x, y)
% Fit: 'untitled fit 1'.
[xData, yData] = prepareCurveData( x, y );
% Set up fittype and options.
ft = fittype( 'poly3' );
% Fit model to data.
[fitresult, gof] = fit( xData, yData, ft );
end

 採用された回答

Walter Roberson
Walter Roberson 2022 年 11 月 29 日

0 投票

differentiate is specifically designed to differentiate cfit and sfit objects.
integrate is designed to integrate cfit objects.

3 件のコメント

Josh
Josh 2022 年 11 月 30 日
Thanks for the answer. As we manually differentiate the fit function and compare it to the values of the fx, they are not the same. How so!! Please suggest.
Walter Roberson
Walter Roberson 2022 年 11 月 30 日
df_fit=(x.^2)*3+2*x.+1; is the derivative of x^3 + x^2 + x + const but poly3 is going to create a model of the form a*x^3 + b*x^2 + c*x + const which would have a derivative of 3*a*x^2 + 2*b*x + c
Torsten
Torsten 2022 年 11 月 30 日
Isn't the derivative with respect to the fitting parameters required here ? [x.^3,x.^2,x] ?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeGet Started with Curve Fitting Toolbox についてさらに検索

質問済み:

2022 年 11 月 29 日

コメント済み:

2022 年 11 月 30 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by