MATLAB: How to curve fit a transcendental function to data

curveequationfitfittingtranscendental

Hi,
I am trying to curve fit three parameters in a transcendental function to some data, and have searched both Google and MathWorks' fora to find an iterative method. However, so far none have seemed to yield results, or maybe I didn't understand the posted replys..
The function is as follows:
y = B – k1 (x – y/A) – k2 *(1 – exp( -k3(x – y/A)))
I already know the parameters A and B, and want to determine k1, k2 and k3 by fitting to a set of data containing values for x and y.
I have tried to isolate a zero on the left side, and then use the lsqcurvefit function to solve it using the following syntax (taken from one previously mentioned example):
B = 40; %Constants
A = 128e3;
k = [1 1 1]'; %Initial guesses of k1, k2, k3
xdata = epsilon; %x-data of 50 entries
ydata = sigma_matrix(:,5); %y-data of 50 entries
zeroes = zeros(1,length(xdata))'; %array of zeros to find root
predictedzeros = @(k,xdata,ydata) ydata + k1*(xdata-ydata/A) + k2(1-exp(-k3*(xdata-ydata/A))) - B
[ahat,resnorm,residual,exitflag,output,lambda,jacobian] = lsqcurvefit(predictedzeros,k,xdata,zeros(1,length(xdata))')
However, it gives me the following error:
predictedzeros =
@(k,xdata,ydata)ydata+k1*(xdata-ydata/A)+k2(1-exp(-k3*(xdata-ydata/A)))-B
Not enough input arguments.
Error in Fit>@(k,xdata,ydata)ydata+k1*(xdata-ydata/A)+k2(1-exp(-k3*(xdata-ydata/A)))-B
Error in lsqcurvefit (line 202)
initVals.F = feval(funfcn_x_xdata{3},xCurrent,XDATA,varargin{:});
Error in Fit (line 16)
[ahat,resnorm,residual,exitflag,output,lambda,jacobian] = lsqcurvefit(predictedzeros,k,xdata,zeros(1,length(xdata))')
Caused by:
Failure in initial objective function evaluation. LSQCURVEFIT cannot continue.
Does anyone have an idea of how to move forward from this point? I'm not an expert at MATLAB, but you're welcome to throw hardcore work-arounds at me 🙂 I'm pretty frustrated at this point.
Thanks for your help.

Best Answer

Set
k0 = [k1_0;k2_0;k3_0]
to a vector of initial values for your unknown parameters. Write your function as:
predictedzeros = @(k,xdata,ydata) ydata + k(1)*(xdata-ydata/A) + k(2)(1-exp(-k(3)*(xdata-ydata/A))) - B
and write the call to lsqcurvefit as:
k = lsqcurvefit(predictedzeros,k0,xdata,ydata)
You may have to try several initial value vectors.
Related Question