Nonlinear Least Square(Marquardt)



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;
.



Relevant Pages

  • Re: spatial autocorelation methods
    ... > a 'detect' in the other data set). ... > clusteredness, but am leaning towards brute force identification of clusters ... what the problem is with input data needing to be square. ... erosion filters applied to the data to simplify the problem. ...
    (sci.image.processing)
  • Nonlinear least squares with cheap function evaulation
    ... I'm fitting a 1D data set (time series) to a nonlinear equation made up ... which has analytical partial derivatives. ... MATLAB to do the fitting. ...
    (sci.math.num-analysis)
  • fmincon confidence interval
    ... I am interested in fitting a model function with 5 ... parameters to a data set. ... uncertainty in each of the parameter's estimate. ... which permits the use of constraints ...
    (comp.soft-sys.matlab)
  • Re: Square root of a negative rral value
    ... data set that went with this, crashes on trying to take the square ... square root operation before terminating correctly with a final table. ... When the standard deviation is zero, ...
    (comp.lang.fortran)
  • Re: data fitting for 2 data sets and functions
    ... I have also seen the same method being mentioned in the optimization toolbox but I have never used it. ... As for the problem of fitting the two functions simultaneously, unfortunately I don't have a good idea... ... in fact no result when just fitting one function to the data set! ... while this is an easy job for 'lsqcurvefit' function. ...
    (comp.soft-sys.matlab)