Fit of numerical expression

1 view (last 30 days)
Moritz Ruhwedel
Moritz Ruhwedel on 13 Aug 2019
Commented: Moritz Ruhwedel on 14 Aug 2019
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?

Accepted Answer

Torsten
Torsten on 13 Aug 2019
Use an anonymous function to define your model equation.
For examples, see
  9 Comments
Torsten
Torsten on 14 Aug 2019
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 on 14 Aug 2019
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

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!