Using summation containing function for curve fitting

9 ビュー (過去 30 日間)
Aniket Masaye
Aniket Masaye 2019 年 1 月 8 日
編集済み: Andrew 2023 年 9 月 24 日
I was trying to fit my data in an equation given below:
equation.jpg
where a=1,, also summation upto 250 terms is enough.
k & Cs are fitting parameters. I have data for t & S(t).
I tried the curve fitting tool. It doesnt support for summation functions.
Can you help me to code for this for this fit ?
I am attaching the data file.

採用された回答

Stephan
Stephan 2019 年 1 月 9 日
Hi,
you can use this script:
x0 = [12 3];
x = lsqcurvefit(@(x,t)equation_fit(x,t),x0,t,S)
S_calculated = equation_fit(x,t);
plot(t,S,t,S_calculated)
function S_calc = equation_fit(x,t)
n = 1:250; % Number of sumations
a = 1; % define a
w2n = n.^2.*pi^2./4000; % Definition of omega_n_squared
% Fitting values
Cs = x(1);
k = x(2);
% Determine function
sum_parts = ((1-(-1).^n)./(n.^2)).*(exp(-w2n.*t)+...
(k.*(1-(1+w2n.*t).*exp(-w2n.*t)))./(w2n+k.*(1-exp(-w2n.*t))));
S_calc = 1 + a.*Cs.*(1 - (4/pi^2 .* sum(sum_parts,2)));
end
But the resulting fit appears not to be a very good result to me:
fit_result.PNG
Note that the last two lines of your data file contain invalid informations - i deleted them and attached the needed .mat-file to this answer, so that if you load the .mat-file to workspace you can execute the script and check the results by yourself. The result of sum_parts is a matrix with 89425x250 (number of samples of S(t) x n). In the second step the sum is build, so that you sum up from n=1...250 and the result is the S_calc with the needed dimenstion of 89425x1. This is the way you can solve this summation problem for curve fitting in Matlab.
Best regards
Stephan
  3 件のコメント
Stephan
Stephan 2019 年 1 月 9 日
編集済み: Stephan 2019 年 1 月 9 日
Cs=x(1)
k=x(2)
if my answer was useful please accept it.
Lisa97
Lisa97 2019 年 6 月 2 日
Hi Stephan: your code is really helpful. Thanks a lot!

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

その他の回答 (1 件)

Andrew
Andrew 2023 年 9 月 23 日
編集済み: Andrew 2023 年 9 月 24 日
Dear Stephan,
I am trying to fit the attached data to the following model
using the curve fitting tool in Matlab without success. For the equation, t = time (min), l = 0.0023 m and n = 0 to infinity while D is the fitting parameter or unknown constant to be found once the data is fitted. Could you please help me with a code to fit the data? Thanks in anticipation to your positive response.
Kind regards,
Andrew

カテゴリ

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