help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Curve fit


From: Liam Groener
Subject: Re: Curve fit
Date: Sat, 20 Nov 2010 11:50:56 -0800

On Nov 20, 2010, at 6:36 AM, cunninghands wrote:

> 
> Wow, thanks. Its still complicated for me. 
> 
> But ill try to understand it better. 
> 
> Thanks for all your help guys. 
> -- 
> View this message in context: 
> http://octave.1599824.n4.nabble.com/Curve-fit-tp3051324p3051586.html
> Sent from the Octave - General mailing list archive at Nabble.com.
> _______________________________________________
> Help-octave mailing list
> address@hidden
> https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
>> On Nov 20, 2010, at 5:49 AM, Andy Buckle wrote:
> 
>>> I decided to try Andy's method and I thought you might be interested in the 
>>> details. Here are my commands (after I copied and pasted your data to a 
>>> file and read it into vectors x and y):
>> 
>> (Jaroslav's method: that was a copy-paste).
>> 
>> Nice, though. I was tempted to try and do the curve fit, just because
>> I enjoy this kind of thing, but didn't have time.
>> 
>>> a little off at the knee of the curve.
>> 
>> I think using a polynomial (?quadratic) as the argument for the
>> exponential might just give it the freedom to follow the points.
> 
> On Nov 20, 2010, at 7:47 AM, Stuart Edwards wrote:
> 
>> or perhaps just
>> 
>> axis ("ij")
>> 
>> stu
>> 
>> 
>> On Nov 20, 2010, at 10:06 AM, Andy Buckle wrote:
>> 
>>> On Sat, Nov 20, 2010 at 2:56 PM, cunninghands <address@hidden> wrote:
>>>> 
>>>> May I ask (in addition).
>>>> 
>>>> How can I reverse the y axis. (I want 0 to be at the top, and the maximum y
>>>> at the bottom).
>>>  
>>> set(gca(),'ydir','reverse')
>>> 
>>> get(gca())
>>> will give you a list of axis properties that may be of interest for
>>> other tweaking.
Hi again,
I'll try to explain what we're doing. First the commands incorporating Andy and 
Stuart's suggestions (that's a new one on me Stuart):

[61] >> 
[c,fval,info,output]=fsolve(@(c)((c(1)-c(2).*x).*(1-exp(c(3)+c(4).*x+c(5).*x.^2))-y),[10;.001;0;-.2;0]);
[62] >> y2 = (c(1)-c(2).*x).*(1-exp(c(3)+c(4).*x+c(5).*x.^2));
[63] >> plot(x,y2,'linewidth',2,'r',x,y,'+','markersize',3,'linewidth',2)
[64] >> axis ("ij")

The first step is to select a function form to be fit to the data. Andy 
suggested a modification to function I originally used to:
    f(x) = (1 - ax)(1-exp(b+cx+dx^2)
where a, b, c, and d are the constants to be determined. In practice, we use a 
vector c to represent the unknown constants, so:
  f(x) = (1-c(1) x)(1-exp(c(2)+c(3) x + c(4) x^2)

What we need to do is find the c vector that minimizes the error between the 
"known" data points and the function "predictions." We do this with fsolve, a 
procedure for solving a set of (possibly) non-linear equations. In this case, 
we have 358 equations with 5 unknowns; each equation formed by setting:
 f(x) - y = 0
for one set of data points. Since the equation set is overdetermined, fsolve 
uses least squares to minimize the the error between the solution and the data.

However, the unknown (independent variable) in (f(x) - y) we want is c, not x. 
Therefore, we cast (f(x)-y) in the form of an "anonymous function:"
             @(c)((c(1)-c(2).*x).*(1-exp(c(3)+c(4).*x+c(5).*x.^2))-y

The @(c) tells us that c is he independent variable while x and y are 
"constant" parameters. Note that .* and .^ are used instead of * and ^ since we 
want element by element operations, not matrix operations. fsolve needs an 
initial guess for c for which I chose: [10;.001;0;-.2;0]. The plot is attached. 
The fir is a little better than my previous effort, but still not perfect.

Attachment: PastedGraphic-3.pdf
Description: Adobe PDF document

   


reply via email to

[Prev in Thread] Current Thread [Next in Thread]