Fit of numerical expression

1 回表示 (過去 30 日間)
Moritz Ruhwedel
Moritz Ruhwedel 2019 年 8 月 13 日
コメント済み: Moritz Ruhwedel 2019 年 8 月 14 日
Hi all, i have my data which i want to be fitted consisting of the independent variable x and the dependent variable y. My function that should fit the data is something like f(x,a,b,c,d) = integral(g(x,y,a,b,c),y,0,d) where d is known and a, b and c are the fitting parameters. g can only be integrated numericaly. If i try to do the fit using ft = fittype('f(x,a,b,c,d)') i get an error like: Expression f(x,a,b,c,d) is not a valid MATLAB expression,
has non-scalar coefficients, or cannot be evaluated
Any ideas how i can solve this problem?
Edit: If i try to compute values for f for certain sets of variables i get: Warning: Reached the limit on the maximum number of intervals in use. Approximate bound on error is
4.0e-01. and a probably right value for f, but this value is much smaller than the suggested error. g is definitly finite over the range i integrate. How reliable could this value be and how could i manage to get an smaller error?

採用された回答

Torsten
Torsten 2019 年 8 月 13 日
Use an anonymous function to define your model equation.
For examples, see
  9 件のコメント
Torsten
Torsten 2019 年 8 月 14 日
Don't define your function in the call to "fittype", but use a separate function file:
ft = fittype(@(d_Fe, r_bulk_Pt, r_Fe, mfp_Pt, h, k, x) fun(d_Fe,r_bulk_Pt,r_Fe,mfp_Pt,h,k,x));
and write a function
function res = fun(d_Fe,r_bulk_Pt,r_Fe,mfp_Pt,h,k,x)
...
end
This way, you have the possibility to debug what is happening.
One obvious thing is that x/((x)... is wrong because x is a vector. Use elementwise division here.
Moritz Ruhwedel
Moritz Ruhwedel 2019 年 8 月 14 日
Okay now i found the problem, when replacing a variable called x i replaced accidently the x in exp with a t. Now it works, thank you Torsten, you saved my Bachelorthesis :D

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLinear and Nonlinear Regression についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by