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 CenterFile Exchange에서 Linear and Nonlinear Regression에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by