How to use a user defined function inside the curve fitting function?

조회 수: 3 (최근 30일)
Victor Carneiro da Cunha Martorelli
편집: Torsten 2023년 12월 21일
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.

답변 (1개)

Torsten
Torsten 2023년 12월 21일
편집: Torsten 2023년 12월 21일
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.

카테고리

Help CenterFile Exchange에서 Get Started with Curve Fitting Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by