[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: independent variable in function for leasqr
From: |
Guillem Borrell Nogueras |
Subject: |
Re: independent variable in function for leasqr |
Date: |
Tue, 10 Jul 2007 13:56:21 +0200 |
User-agent: |
KMail/1.9.5 |
It is much better to use an anonymous function to fit this purpose.
In this case would be:
>> k = 2
>> f = @(x) k*x^2
To make this thing work you must upgrade to octave 2.9.x. In earlier versions
of octave the anonymous function won't find the constant k.
You can find more information about anonymous functions and function handles
here: http://www.mathworks.com/access/helpdesk/help/techdoc/matlab.html.
look for anonymous functions in the index.
guillem
On Tuesday 10 July 2007 11:56, address@hidden wrote:
> Hi James,
> thanks again, my code runs :-)
> Just one last question, I cannot declare a function using letter constants:
>
> octave-2.1.73:12> k = 2;
> octave-2.1.73:13> F = inline("k*x^2", "x");
> octave-2.1.73:14> F(2)
> error: `k' undefined near line 12 column 6
> error: evaluating binary operator `*' near line 12, column 7
> error: called from `?unknown?'
>
> This is not crucial, but would just look better in my script.
> Maybe is your version of octave newer and can do that.
> Is it that?
> Thanks a lot anyway, the code is running ...
>
> > k = 2;
> > F = inline("k*x^2", "x");
> > then,
> > F(2) = 8;
> > Now even if I change k after this, the function F will be unchanged.
> >
> > Furthermore for leasqr, when you define F like this:
> > F = inline("Ao*exp(-D*x^2*k)","Ao","D","x")
> > You still have the problem that leasqr expects a function of the form:
> > f(x,p)
> > This implies two important things:
> > 1) the function has exactly 2 input arguments
> > 2) the x variable is the first argument.
> > This is the reason that I said to let p(1) be your Ao and p(2) be your D,
> > so that you can fit both the parameters that you want to optimize into
> > one input variable (namely p).
> > For leasqr your function (if it is inline) should always look like this:
> > F = inline("<some function with x and p>", "x", "p");
> >
> > (Note: Notice this is not the same as writing F = inline("<some
> > function>", "p", "x"); The order you list the parameters after the
> > function is the order that octave will expect them when you call F, so
> > "x" must be first for leasqr)
> >
> > This is also how you tell octave which variable is the independent one
> > (it is always the first argument of F) and the parameters to be optimized
> > (always the second argument of F).
> > So after you put it into this form and run leasqr, you can get the
> > estimates of Ao and D by doing:
> > estimateAo = p1(1);
> > estimateD = p1(2);
>
> _______________________________________________
> Help-octave mailing list
> address@hidden
> https://www.cae.wisc.edu/mailman/listinfo/help-octave
- independent variable in function for leasqr, oxyopes, 2007/07/08
- Re: independent variable in function for leasqr, James Sherman Jr., 2007/07/08
- Re: independent variable in function for leasqr, oxyopes, 2007/07/09
- Re: independent variable in function for leasqr, James Sherman Jr., 2007/07/09
- Re: independent variable in function for leasqr, oxyopes, 2007/07/10
- Re: independent variable in function for leasqr, David Bateman, 2007/07/10
- Re: independent variable in function for leasqr,
Guillem Borrell Nogueras <=
- Re: independent variable in function for leasqr, David Bateman, 2007/07/10
- Useless functions in matlab function library., Guillem Borrell Nogueras, 2007/07/10
- Re: Useless functions in matlab function library., Qingshan Chen, 2007/07/10
- Re: Useless functions in matlab function library., Jordi GutiƩrrez Hermoso, 2007/07/10
- Re: Useless functions in matlab function library., Guillem Borrell Nogueras, 2007/07/11
- Re: Useless functions in matlab function library., Paul Kienzle, 2007/07/11