Fit of numerical expression
1 view (last 30 days)
Show older comments
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?
0 Comments
Accepted Answer
Torsten
on 13 Aug 2019
Use an anonymous function to define your model equation.
For examples, see
9 Comments
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.
More Answers (0)
See Also
Categories
Find more on Linear and Nonlinear Regression in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!