X-Received: by 10.224.223.198 with SMTP id il6mr7818530qab.7.1378538611627;
        Sat, 07 Sep 2013 00:23:31 -0700 (PDT)
X-Received: by 10.50.2.74 with SMTP id 10mr51576igs.15.1378538611593; Sat, 07
 Sep 2013 00:23:31 -0700 (PDT)
Path: news.mathworks.com!newsfeed-00.mathworks.com!news.kjsl.com!feeder.erje.net!us.feeder.erje.net!news.glorb.com!j7no492732qai.0!news-out.google.com!p7ni1205qas.0!nntp.google.com!j7no492726qai.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
Newsgroups: comp.soft-sys.matlab
Date: Sat, 7 Sep 2013 00:23:31 -0700 (PDT)
In-Reply-To: <l0c53o$ou2$1@newscl01ah.mathworks.com>
Complaints-To: groups-abuse@google.com
Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=130.102.82.3; posting-account=IIsL2goAAADEO-s9vhbsiCiUtymxELhu
NNTP-Posting-Host: 130.102.82.3
References: <7c6b0e44-91d4-4012-9269-3f446903ae16@googlegroups.com> <l0c53o$ou2$1@newscl01ah.mathworks.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <ebbab5b5-2831-4dfa-b17a-f1e333a12647@googlegroups.com>
Subject: Re: Curvefitting with fminsearch
From: Kapila Bandara <kmkssanju@gmail.com>
Injection-Date: Sat, 07 Sep 2013 07:23:31 +0000
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Lines: 105
Xref: news.mathworks.com comp.soft-sys.matlab:802051

On Friday, September 6, 2013 6:52:08 PM UTC+10, Torsten wrote:
> Kapila Bandara <kmkssanju@gmail.com> wrote in message <7c6b0e44-91d4-4012-9269-3f446903ae16@googlegroups.com>...
> 
> > Hi
> 
> > 
> 
> > I used fminserach function to for optimize the fitting with custom function. However, it gives deference results at each simulation . I have attached both function file and code file here with. could you please help me to adjust my programme to get consistence answer.
> 
> > 
> 
> > unction [estimates, model] = fitcurvedemo1(xdata, ydata)
> 
> > % Call fminsearch with a random starting point.
> 
> > start_point = rand(1,2);
> 
> > model = @expfun;
> 
> > estimates = fminsearch(model, start_point);
> 
> > % expfun accepts curve parameters as inputs, and outputs sse,
> 
> > % the sum of squares error for A*exp(-lambda*xdata)-ydata,
> 
> > % and the FittedCurve. FMINSEARCH only needs sse, but we want
> 
> > % to plot the FittedCurve at the end.
> 
> >     function [sse, FittedCurve] = expfun(params)
> 
> >         A = params(1);
> 
> >         lambda = params(2);
> 
> >        
> 
> >        % B=params(3);
> 
> >        % beta=params(4);
> 
> >         FittedCurve =A.*(exp(-lambda.*((1.8*1^-26)./xdata)));
> 
> >         ErrorVector = FittedCurve - ydata;
> 
> >         sse = sum(ErrorVector .^ 2);
> 
> >     end
> 
> > end
> 
> > ........................
> 
> > clear all
> 
> > ydata=10^-12*[8.51 51 100 ]
> 
> > xdata=[1 2 3 ]
> 
> > 
> 
> > 
> 
> > [estimates, model] = fitcurvedemo1(xdata,ydata)
> 
> > plot(xdata, ydata, '*')
> 
> > hold on
> 
> > [sse, FittedCurve] = model(estimates);
> 
> > plot(xdata, FittedCurve, 'r')
> 
> >  
> 
> > xlabel('xdata')
> 
> > ylabel('f(estimates,xdata)')
> 
> > title(['Fitting to function ', func2str(model)]);
> 
> > legend('data', ['fit using ', func2str(model)])
> 
> > hold off
> 
> 
> 
> 1. Use lsqcurvefit for such kind of problems.
> 
> 2. Your ydata are very small - so you will have to choose a very small tolerance
> 
> TolFun.
> 
> 
> 
> Best wishes
> 
> Torsten.

Thank you very much