How to create a curve fit for my data?

1 回表示 (過去 30 日間)
Arpad Takacs
Arpad Takacs 2021 年 4 月 8 日
コメント済み: Star Strider 2021 年 4 月 8 日
I have the following function: . How can I create a curve fit for my data points?

採用された回答

Star Strider
Star Strider 2021 年 4 月 8 日
Assuming you have a vector of ‘T’ values that are functions of ‘s’, ‘g’ is given and the parameter to be estimated is ‘x’:
Tfcn = @(x,s,g) 2*pi*sqrt((x+s.^2)./(g.*s)); % Objective Function
s = 1:20; % Create Data
T = rand(size(s))*10; % Create Data
g = 9.81;
X0 = 1;
X = fminsearch(@(x) norm(T - Tfcn(x,s,g)), X0); % Estimate Parameters
figure
plot(s, T, '.')
hold on
plot(s, Tfcn(X,s,g), '-r')
hold off
grid
.
  2 件のコメント
Arpad Takacs
Arpad Takacs 2021 年 4 月 8 日
編集済み: Arpad Takacs 2021 年 4 月 8 日
Thank you so much! And how can I calculate the error of the coefficient 'x'? My data also have an error which should be counted as well.
Star Strider
Star Strider 2021 年 4 月 8 日
As always, my pleasure!
If you have the Statistics and Machine Learning Toolbox, use the fitnlm function (introduced in R2013b). It will provide confidence limits on the parameters automatically, and the ‘Tfcn’ will work with it, with one small change in the calling syntax:
mdl - fitnlm(s, T, @(x,s)Tfcn(x,s,g), X0)
Then see the fitnlm documentation I linked to to understand how to get even more information from the ‘mdl’ variable and associated functions.
The nlinfit function is also an option (with the same calling syntax as for fitnlm) for ‘Tfcn’. See that documentation and related functions such as nlparci and nlpredci (linked to in that documentation).

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with Curve Fitting Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by