I use lsqcurvefit to fit my function. My function is:
C_PET (t)=(k_1/(α_2+α_1 ) [(k_3+k_4-α_1 ) e^((-α_1 t) )+(α_2-k_3-k_4 ) e^((-α_2 t) ) ]* C_P (t))+vC_b (t)
I went to find the solution, meaning the best fit for my K parametres. The problem is that the solution that my code give is the initial point. this is the code (vb is constant , cp,ydata,t are a vector
k0 = 1*ones(1,4);
k0(4) = 0;
k0 = [0.8,0.1,0.5,0.07]
a1=[k0(2)+k0(3)+k0(4)+sqrt(((k0(2)+k0(3)+k0(4)).^2) -4*k0(2)*k0(4))]/2;
a2=[k0(2)+k0(3)+k0(4)-sqrt(((k0(2)+k0(3)+k0(4)).^2) -4*k0(2)*k0(4))]/2;
l1=(k0(1)/(a2+a1))*(k0(3)+k0(4)-a1) l2=(a2-k0(3)-k0(4))
l2=(a2-k0(3)-k0(4))
y=conv((l1*exp(-a1*t)+l2*exp(-a2*t)),cp);
y=(y(1:numel(t)));
CPET=@(k,t) y+(vb*cp);
[xfitted,errorfitted] = lsqcurvefit(CPET,k0,t,ydata)
%
So please can you hep me.
Your objective function
CPET
is a constant:You have declared it as a function of
k
andt
but neithery
,vb
norcp
change whenk
ort
change. That's why your solver isn't changing the answer. No matter what values ofk
ort
lsqcurvefit
feeds toCPET
, the answer is always the same, which is wrong.Your objective function is very long, so lets consider a much simpler one, say fitting a quadratic model that has another function of
t
as another term (i.e. in the same way that yourC_P
works) something like:O = k1 + k2*t + k3*t2 + CP(t)
To write this objective function into the form expected by
lsqcurvefit
do:Now
CP
above can be a vector, CP, if and only ift
will always be a natural number. It would make far more sense however to create a function calledCP
that takest
in as an input. For example maybe allCP
does is take the sine oft
thenYou need to write your
CPET
similary as a function ofk
andt
and it needs to use bothk
andt
in it's definition.