Assume one has data, which for sake of convenience we will generate in Matlab: x=[0:10] y=exp(-.7*x) xx=x' yy=y' plot(x,y) But we did not really know where it came from Plotting it suggests an exponential decay, but we do not know the rate- i.e. the .7. we would like to find u such that z=|| exp(-u*xx)-yy|| is minimized so we will minimize the error. u occurs nonlinearly! There is a 1 dimensional search engine fminbnd that takes a function of 1 variable and bounds and produces a minimum so we write a function which given u, xx and yy will return z. Open the editor and type function z=exp3(u,xx,yy) z=norm(exp(-u*xx)-yy); disp([u z]) save this as exp3. Note that exp3 has 3 variables. we can get around this by the following trick [zz,FVAL,EXITFLAG,OUTPUT] =fminbnd(@(u)exp3(u,xx,yy),.1,2) which says find me u between .1 and 2 try this. now look at data which might have more than 1 variable what if we had generated data as y = 2*exp(-.1*x)+ 3*exp(-1.5*x) and set yy=y' assume we thought perhaps there were 4 parameters- weighted sum of 2 exponentials but we did not really know the 2 , -1,3,1.5 Create the function using the editor function z=exp4(u,xx,yy) z=norm(u(1)*exp(-u(2)*xx)+ u(3)*exp(-u(4)*xx)-yy); disp([u(1) u(2) u(3) u(4) z]) and save as exp4 now use fminsearch [zz,FVAL,EXITFLAG,OUTPUT]=fminsearch(@(v)exp4(v,xx,yy),[1;2;3;4]) and stand back there is also one especially for nonlinear functions as in: function zz=exp5(u,xx,yy) zz=u(1)*exp(-u(2)*xx)+ u(3)*exp(-u(4)*xx)-yy; disp([u(1) u(2) u(3) u(4) ]) calling [zz,FVAL,EXITFLAG,OUTPUT]=lsqnonlin(@(v)exp5(v,xx,yy),[1;2;3;4])