I am trying to fit a function using lsqcurvefit
linked with MultiStart
. The thing is that the obtained results are highly inconsistent with the training data.
The whole problem has to do with the frequency response of two RC parallel circuits connected in series (obtained experimentally -xdata,ydata-) and the calculation of R,C values via fitting in the proper impedance equation.
The steps I followed are (according to mathworks tutorial):
Step I (Create the objective function)
function [Ztotal] = RQRQ_test(c,omega)
% c = [Rs CPE1 n1 Rct1 CPE2 n2 Rct2];
% τCPE1
YCPE1 = c(2)*(1i*omega).^c(3);
Y1 = YCPE1 + c(4).^-1;
Z1 = 1./Y1;
% τCPE2
YCPE2 = c(5)*(1i*omega).^c(6);
Y2 = YCPE2 + c(7).^-1;
Z2 = 1./Y2;
% Ztotal
Ztotal = (abs(Z1 + Z2 + c(1)))';
Step II (Create the training data)
omega = logspace(5,-1,120); %xdata
Zexp = xlsread('(RQ)(RQ)_test.xlsx', 'D2:D121'); %ydata
c0 = [3 1e-04 0.9 20 1e-06 0.9 100]; %initial values of c
Step III (Set bounds)
lb = [2 1e-05 0.9 10 1e-06 0.9 50];
ub = [8 1e-01 1 100 1e-03 1 200];
Step IV (Set up the problem)
problem = createOptimProblem('lsqcurvefit','x0',c0,'objective',@RQRQ_test,...
'lb',lb,'ub',ub,'xdata',omega,'ydata',Zexp);
Step V (Run MultiStart
)
[xmulti,errormulti] = run(ms,problem,50)
After I run the above procedure the result I get is the following:
MultiStart completed the runs from all start points.
All 50 local solver runs converged with a positive local solver exit flag.
xmulti =
8.0000 0.0083 1.0000 100.0000 0.0008 0.9000 85.1574
errormulti =
1.3146e+04
In the plot appended below the line and open circles correspond to c initial and optimized values respectively.
I cannot understand why the error is so large. Is there sth wrong with my code or the way I handle the problem? This may be due to my little matlab experience but it's been days I am struggling to find the solution..
Any help would be more than appreciated.
Thank you in advance for your time.