help-octave
[Top][All Lists]
Advanced

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

Re: independent variable in function for leasqr


From: oxyopes
Subject: Re: independent variable in function for leasqr
Date: Tue, 10 Jul 2007 11:56:55 +0200

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);



reply via email to

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