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: Mon, 9 Jul 2007 16:51:39 +0200

Hi James,
thanks for the help. Unfortunately this code does not work for me (details at
the end). I cannot make a function work if not all letter constants are
specified as variables. Example: this works
F=inline("Ao*exp(-D*x.^2*k)","Ao","D","x","k"); F(1,2,3,4)

But only if Ao, D, x and k are specified as variables, even if i want
Ao, D, and k to be constants. So this wont work
F=inline("Ao*exp(-D*x.^2*k)","Ao","D","x"); k=1; F(1,2,3)

As a results, i do not know how to tell leasqr which is the
independent variable and which constants are to
be optimized when i type leasqr(g,A, guess, F ).
How to give this information to leasqr?

Following your last email I had the following result:
octave-2.1.73:116> g=(1:2:10)'; A=exp(g); Ao=1; k=2; guess=[1 0.1]';
octave-2.1.73:118> F = inline("Ao*exp(-D*x^2*k)","Ao","D","x")
octave-2.1.73:121> leasqr(g,A, guess, F )
error: `x' undefined near line 117 column 23
error: evaluating binary operator `^' near line 117, column 24

Is it maybe the octave version?
Thanks again for any help ...

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



reply via email to

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