How can I use parameters from workspace in custom equation using fittype function?
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
I'd like to write the coefficient, in the custom equation, in literal form, keeping A as the solution of the curve fitting
function A = coffin_coefficient(X,Y)
[xData, yData] = prepareCurveData( X, Y );
ft = fittype( 'A*x^(-6.9397)*exp(0.8084/((8.6173e-05)*(120+273.15)))', 'independent', 'x', 'dependent', 'y' );
opts = fitoptions( 'Method', 'NonlinearLeastSquares' );
opts.Algorithm = 'Levenberg-Marquardt';
opts.Display = 'Off';
opts.StartPoint = 0.1;
0 Commenti
Risposte (1)
Guillaume Le Goc
il 9 Apr 2020
If you want to fit y(x) to find the parameter A, now you have set the fittype and fitoptions for the fit, you just need to perform the fit :
f = fit(xData, yData, ft, opts);
And for your function to return the found A, you can access it with :
A = f.A;
You might want to get the 95% confidence interval for the value :
ci = confint(f);
3 Commenti
Guillaume Le Goc
il 9 Apr 2020
Modificato: Guillaume Le Goc
il 9 Apr 2020
Sorry, I did not understand what your problem was.
I generally read that the eval function is generally not recommended, especially here where it is of no use.
Since your variables n, Ea... are defined in the workspace from which you call your coffin_coefficient function, you can simply pass them as input arguments in your function, as you did. Now, those variables exist within the function, and you can simply define your fitting function normally as you did in the first place, replacing numerical values by their variable names.
In fact,
eval(['ft=a+b+c;']);
does the same thing than
ft=a+b+c;
but is way slower.
In short, now that you pass all the variables to your function, you can use them as you would in a script/command window, ie. using the workspace you have access to.
Vedere anche
Categorie
Scopri di più su Linear and Nonlinear Regression in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!