Clear Filters
Clear Filters

Fitting theoritical curve to experimental data

15 views (last 30 days)
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 Comments
the cyclist
the cyclist on 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?
Panagiotis Artemiou
Panagiotis Artemiou on 15 Mar 2023
First of all thank you very much for the answer.
Yes my equation is in fact this
Zre(i)=(Rsol+ (Rcoat/(1+w(i).^2.*Rcoat.^2.*Ccoat.^2)))';
The experimental curve is in fact derived from a set of data. Do you suggest that fitting the curve to the experimental data directly is better?
To be more specific I have these equations:
Zre(i)=(Rsol+ (Rcoat/(1+w(i).^2.*Rcoat.^2.*Ccoat.^2)))';
Zim(i)=(-w(i).^2.*Rcoat.^2.*Ccoat.^2)/(1+w(i).^2.*Rcoat.^2.*Ccoat.^2);
which are the real and imaginary part of the impedance for a circuit .
As I said there are 3 parameters, Rsol, Rcoat, Ccoat. And I want to find these parameters so that they match the experimental data (which I am attaching). The first column on the data.txt file is the w(i) variable in the equations.

Sign in to comment.

Accepted Answer

Shubham
Shubham on 3 May 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.

More Answers (0)

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!