Nonlinear Least Square(Marquardt)
- From: Mike <ibrahimm@xxxxxxx>
- Date: Sun, 20 Nov 2005 14:21:15 -0500
Hi all,
Please, could someone help me with the matlab programs below.
I have an x, y data set and I want to do nonlinear least square
fitting of the data.
First, I would like the function "mkety" to calculate and return the
parameters, K1,K2,K3 to "nonlinr_kety".
Then, "nonlinr_kety" would fit and find the best value of the
parameters, K1, K2, K3.
However, I am undefined errors, etc,
Could someone please, help, give pointers,etc.
Thank you.
Mike
############################
%% mnonlinr_kety.m
load renal.mat;
t=pet.t;
dt=pet.dt;
Ca=pet.Ca;
Ct=pet.kr;
xdata = zeros(length(t),4);
ydata = zeros(length(t),2);
xdata(:,1) = t;
ydata(:,1) = Ca;
ydata(:,2) = Ct;
lb = [0;3;3;0.05;0;0];
ub = [1.5;6;6;0.5;max(Ca);max(Ct)];
X0 = [4.0;4.0;0.5];
X0 = X0';
options=optimset('Display','iter','TolFun',0.00001*ones(size(length(t)
)),'LevenbergMarquardt','on','Jacobian','off');
[x,resnorm,residual,exitflag,output,lambda,Jacobian]=
lsqcurvefit('mkety',X0,t,K(1),K(2),K(3),Ca,Ct,lb,ub);
%%%%%%%
function mkety_out=mkety(t,K,Ca,Ct)
%
K1exp(-(k2+lambda)t)(integrate(integrate(t,Ca,t+dt)exp((k2+lambda)t)))
)%
%[Nt, a]=max(size(t));
%if size(t,2)==Nt; t=t'; end
%Nc=max(size(Ca));
%if size(Ca,2)==Nc; Ca=Ca'; end
%if Nt ~= Nc;
% errordlg('Argument length mismatch','Error in function mkety')
% return
%end
hlf1 = 122.2/60.0;
lbd = log(2)/hlf1;
K(1) = zeros(length(t),1);
K(2) = zeros(length(t),1);
K(3) = zeros(length(t),1);
xdata(:,2) = K(1);
xdata(:,3) = K(2);
xdata(:,4) = K(3);
K(1)=K1;
K(2)=k2;
K(3)= delay;
%Nk2=length(k2);
%NK1=length(K1);
mkety_out=zeros(length(t),3);
%for l=1:length(delay);
delay=(-5:0.05:5)'/60;
%for j=1:length(K1)
%for i=1:length(k2)
u=exp(-(K(2)+lbd)*t);
tmp=u.*integrate(t,Ca./u,t);
temp=K(1)*(integrate(t,tmp,t+dt)-integrate(t,tmp,t))./dt;
%end
mkety_out(:,:,:)= temp;
%end
%end
return;
.
- Follow-Ups:
- Re: Nonlinear Least Square(Marquardt)
- From: John D'Errico
- Re: Nonlinear Least Square(Marquardt)
- Prev by Date: profiling compiled code
- Next by Date: Avoiding for loops
- Previous by thread: profiling compiled code
- Next by thread: Re: Nonlinear Least Square(Marquardt)
- Index(es):
Relevant Pages
|