Curve fitting tool fits a wrong equation

I am using Matlab for my physical chemistry lab evaluation. Currently I am trying to fit an equation , using the custom equation function. When I fit it works fine, but as soon as I add a second parameter, the fit bocomes linear and I can't figure out why.

3 件のコメント

the cyclist
the cyclist 2022 年 11 月 28 日
Can you upload the data? You can use the paper clip icon in the INSERT section of the toolbar.
Elizaveta Iavorskaia
Elizaveta Iavorskaia 2022 年 11 月 28 日
I used the following data:
p = [101500, 77300, 61600, 51300, 45000, 39000];
V = [0.03, 0.04, 0.05, 0.06, 0.07, 0.08];
P as x, V as y.
These are the data I collected from the experiment.
the cyclist
the cyclist 2022 年 11 月 28 日
Also, I don't think this should matter, but just to be absolutely certain, I would try coding the equation as
(a./x) + b

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

 採用された回答

the cyclist
the cyclist 2022 年 11 月 28 日

1 投票

I can't figure out what is going wrong here, and I don't have the Curve Fitting Toolbox to play around.
I get a sensible fit using fitnlm, so if you have the Statistics and Machine Learning Toolbox, you could use that if you don't figure this out.
% The data
p = [101500, 77300, 61600, 51300, 45000, 39000]';
V = [0.03, 0.04, 0.05, 0.06, 0.07, 0.08]';
% Define function that will be used to fit data
% (F is a vector of fitting parameters)
f = @(F,x) F(1)./x + F(2);
% Define starting guess of coefficients
beta0 = [1000 1];
% Fit the model
mdl = fitnlm(p,V,f,beta0);
% Plot the data and fit
figure
plot(p,V,'*',p,predict(mdl,p),'g');
xlabel("p")
ylabel("V")
legend('data','fit','Location','NorthEast')

3 件のコメント

John D'Errico
John D'Errico 2022 年 11 月 28 日
The problem is almost certainly a poor choice of starting values when this happens. And since the curve fitting toolbox uses random starting values when none are provided, sometimes it gets it wrong.
Elizaveta Iavorskaia
Elizaveta Iavorskaia 2022 年 11 月 28 日
Thank you very much for the answers!
Matt J
Matt J 2022 年 11 月 28 日
To get a better starting guess:
StatPoint=polyfit(1./x,y,1);

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

その他の回答 (0 件)

カテゴリ

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

製品

リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by