Hi all, I have some problems in fitting my experimental data. Say I have two columns of data, the independent variable X and the depedent one Y. I want to fit the following model: Y=y0 + a*X*integral(f(z);0,t*X), where integral(F(z);0,t*X) means that i'm integrating the function f(z) on the interval [0, t*X]. The parameters to be determined through the fitting are y0, a and t. The problem is that I have not an analytical expression for the function F: I have a file .dat containing two columns,expressing the value of F at certain points. The amount of points in which F is evaluated is very huge and I managed to do a very good cubic spline interpolation; however this does not solve my problem, because I don't know how to construct a fitting procedure for that model. Is there a way to do that with MATLAB?

1 comentario

Megan
Megan el 9 de Jun. de 2023
To get Matlab's "fit" function to work properly, your own fit function (let's say it is "piecewiseLine(x,a,b,c,d,k)")must be saved within your current directory, it cannot merely be defined within the confines of your code. This detail had me stuck for more time than I'd like to admit!

Iniciar sesión para comentar.

 Respuesta aceptada

Michael Haderlein
Michael Haderlein el 10 de Jul. de 2014
Editada: Michael Haderlein el 10 de Jul. de 2014

2 votos

Dear Alessandro,
The fitting procedure can also handle non-analytical functions (that's what you need, if I got you correctly). You can use any function in the fitting equation, also self-defined ones:
>> f=fittype('a*myfun(x)');
>> c=fit(x,y,f);
In myfun , you can write whatever you want, may it be an analytical function, a complex code with iterations, or a database look-up. Just make sure to save it as *.m file at a path Matlab can find.
However, be aware that the function will be called pretty often, so make sure it's fast as possible. Thus, a database look-up might not be the best way, but your spline could do much better.
Best regards,
Michael

Más respuestas (1)

Michael Haderlein
Michael Haderlein el 10 de Jul. de 2014

1 voto

Please check out the help for the "fit"-function, there is a very helpful and intuitive example.
Easiest way is to save the file just in your default Matlab folder. Otherwise, you can add directories to the search path list by addpath or by right-clicking the desired folder in the Matlab-explorer window.

Categorías

Etiquetas

Aún no se han introducido etiquetas.

Preguntada:

el 10 de Jul. de 2014

Comentada:

el 9 de Jun. de 2023

Community Treasure Hunt

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

Start Hunting!

Translated by