%reading data in: %load data which in this case include wavelength and dissolved absorption A=load('gr02395.txt') %takeout range of interest I=find(A(:,1)<700 & A(:,1)>400); wl=A(I,1); a_g=A(I,2); %setting options for fmisearch opts = optimset('fminsearch'); opts = optimset(opts,'MaxIter',4000); opts = optimset(opts,'MaxFunEvals',2000); % usually 100*number of params opts = optimset(opts,'TolFun',1e-9); %opts = optimset('LevenbergMarquardt','on'); %guess for paramters (amplitude at 532 and slope) x0=[1.0, 0.03]; %minimization routine x1 = fminsearch(@least_squares,x0,opts,a_g,wl) %plot data and fit plot(wl, a_g, '.k', wl, x1(1)*exp(-x1(2)*(wl-532)),'b')