Fitting theoritical curve to experimental data
14 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Panagiotis Artemiou
il 15 Mar 2023
Commentato: Panagiotis Artemiou
il 24 Mag 2023
I have a curve that was derived from experimental data. I have another curve that has 3 parameters and i want to optimize these parameters so that the experimental and theoritical curves much.
The theoretical curve depends on this equation:
Zre(i)=(Rsol(i)+ (Rcoat(i)/(1+w(i).^2.*Rcoat(i).^2.*Ccoat(i).^2)))';
Where Rsol, Rcoat and Ccoat are the parameters I want to optimize.
Is there any specific tool or function in matlab for that job?
Thank you.
2 Commenti
the cyclist
il 15 Mar 2023
On the one hand, I can just say, "You can use fitnlm to fit this non-linear model" (if you have the Statistics and Machine Learning Toolbox). You can also use fit from the Curve Fitting Toolbox, but I don't use that toolbox, so I can't advise.
But on the other hand, I am a little confused by your question.
First, you notated your parameters as Rsol(i), Rcoat(i), Ccoat(i), rather than just Rsol, Rcoat, Ccoat. I would have assumed that i labels your observations, but I'm not sure. Perhaps you are actually trying to fit
Zre(i)=(Rsol+ (Rcoat/(1+w(i).^2.*Rcoat.^2.*Ccoat.^2)))';
where you have N measurements of Zre and w? Is that right?
It is also confusing to me that you want to "fit a curve to another curve". Why not fit the curve to the original data? How is the "expermental curve" specified?
Can you upload your data and/or the curve specifications? Can you give a little more detailed description?
Risposta accettata
Shubham
il 3 Mag 2023
Hi Panagiotis,
As there are many optimization tools in MATLAB that you can use to optimize the parameters of your theoretical curve to fit the experimental data. Among those tools, one is very popular, i.e., `fminsearch` that uses the Nelder-Mead simplex algorithm to find the minimum of a function.
Providing you an example code snippet that can help to get more clarity on the usage of the function and you can modify it to optimize you parameters:
% Define your experimental data and theoretical function
x = [1 2 3 4 5];
y_exp = [1.2 2.1 3.1 4.2 5.3];
fun = @(params) theoretical_curve(params, x);
% Define the function to optimize
function z = theoretical_curve(params, x)
Rsol = params(1);
Rcoat = params(2);
Ccoat = params(3);
w = 1; % Define w as needed
z = (Rsol + (Rcoat./(1 + w.^2.*Rcoat.^2.*Ccoat.^2)))';
end
% Use fminsearch to find the optimal parameters
params0 = [1 1 1]; % Initial guess for parameters
params_opt = fminsearch(@(params) norm(y_exp - theoretical_curve(params, x)), params0);
% Plot the optimized curve against the experimental data
y_opt = theoretical_curve(params_opt, x);
plot(x, y_exp, 'o', x, y_opt)
legend('Experimental', 'Optimized')
In this example, fminsearch is used to minimize the Euclidean distance between the experimental data and the theoretical curve, which is defined in the theoretical_curve function. The initial guess for the parameters is set to [1 1 1], but you can change this as needed. Finally, the optimized curve is plotted against the experimental data.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Least Squares 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!