How to use a user defined function inside the curve fitting function?
4 views (last 30 days)
Show older comments
Hi all,
I have a funciton that takes into account various parameters:
function [concatz] = my_fit_functioncpe(freq,parameters)
Rsolc = parameters(1);
Cm = parameters(2);
Rq = parameters(3);
Rn = parameters(4);
Ln = parameters(5);
RKch = parameters(6);
Rm = parameters(7);
Lm = parameters(8);
Rl = parameters(9);
Rctc = parameters(10);
T = parameters(11);
qc = parameters(12);
w = 2 * pi * freq;
Z = Rctc + 1./((1./Rsolc+T*(1j*w).^qc)) + 1./((1j*w*Cm)+ 1/Rl + 1/Rq + 1/RKch + 1./(Rn + (1j*w*Ln)) + 1./(Rm + (1j*w*Lm)));%4c
%CPEIMPEDANCE = 1./(T*(1j*w).^qc);
%Z = 1./(1./(Rctc)+(1./(Rsolc+CPEIMPEDANCE))) + 1./((1j*w*Cm) +1./Rl+ 1./Rq + 1./RKch + 1./(Rn + (1j*w*Ln)) + 1./(Rm + (1j*w*Lm)));
reZ = real(Z);
imZ = imag(Z);
concatz = cat(2,reZ,imZ);
end
But I want it to take this initial values like a normal function and fit it to my data. I am not sure how to do that and I have searched everywhere. In python, curve_fit seems to do the trick but I need it for matlab.
0 Comments
Answers (1)
Torsten
on 21 Dec 2023
Edited: Torsten
on 21 Dec 2023
Use "lsqcurvefit".
There are lots of examples under
that show how to use a function to define the response values from a model equation.
But your model is hopelessly overfitted. Reduce the number of parameters first.
As an example, for the expression 1./Rl+ 1./Rq + 1./RKch, the three parameters cannot be fitted independently. Substitute them by one parameter 1/R. Other cases where reductions are necessary are obvious.
0 Comments
See Also
Categories
Find more on Interpolation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!