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: James Sherman Jr.
Subject: Re: independent variable in function for leasqr
Date: Sun, 8 Jul 2007 16:07:50 -0400

When you have the line

F = inline("  Ao*exp(-D*x^2*k)   ");

octave tries to automagically find out what is a input variable, a function, a constant, etc.  So if you look at F after the above line, you would see:

F =

f(Ao, D, k, x) =   Ao*exp(-D*x^2*k) 

So, octave thinks that F is a function of 4 variables (Ao, D, k, and x)

The thing is, leasqr wants a function of two variables, x and p.  So what I think you want to do is this:
Lets let p(1) = Ao and p(2) = D.
Now our function is defined this way:
k=2;
F = inline("  p(1)*exp(-p(2)*x.^2*k)   ", "x", "p");

The "x" and the "p" denote that they are the only input variables.  Notice also the .^ there because when leasqr calls F it will put in the whole vector x (in this case your variable g) and expects the output of F to be a vector the same size as y (or in your case A).  So, my code looks like:

g=(1:2:10)';
A=exp(g);
k=1;
F = inline("  p(1)*exp(-p(2)*x.^2*k)   ", "x", "p");
guess=[1 0.1]';
[f1, p1, kvg1, iter1, corp1, covp1, covr1, stdresid1, Z1, r21] = leasqr(g,A, guess, F );

And seems to work as expected.  Hope this helps.

James


On 7/8/07, address@hidden <address@hidden> wrote:
Hi people,
i do not understand why leasqr does not read my function correctly.
In the function A = inline("  Ao*exp(-D*x^2*k)   "), x is the independent
variable and A the observed values. Ao and D are constants to be optimized.
k is a known constant. I am trying sth like:
g=(1:2:10)';
A=exp(g);
F = inline("  Ao*exp(-D*x^2*k)   ");
Ao=1; k=2; guess=[1 0.1]';
[f1, p1, kvg1, iter1, corp1, covp1, covr1, stdresid1, Z1, r21] = ...
leasqr(g,A, guess, F )

Well, how do i tell leasqr that i want to optimize D and not K at the exponent
of F function? What is wrong with this sequence?
Sorry that it is so similar to the example, but i really did not get it :-o
Thanks in advance for any help ...
_______________________________________________
Help-octave mailing list
address@hidden
https://www.cae.wisc.edu/mailman/listinfo/help-octave


reply via email to

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