|
From: | Doug Stewart |
Subject: | Re: Fwd: leasqr problem in the partial derivative |
Date: | Fri, 22 Sep 2017 11:49:08 -0400 |
On Thu, Sep 21, 2017 at 10:12:31PM -0400, Doug Stewart wrote:
> added Olaf Till
> ---------- Forwarded message ----------
> From: Doug Stewart <address@hidden>
> Date: Thu, Sep 21, 2017 at 8:08 PM
> Subject: leasqr problem in the partial derivative
> To: Help GNU Octave <address@hidden>
>
>
> I went to the examples of leasqr and copied example #2, then adjusted it
> for my data.
>
> % Define functions
> leasqrfunc = @(x, p) p(1) * exp (-p(2) * x ) +p(3);
> leasqrdfdp = @(x, f, p, dp, func) [exp(-p(2)*x),
> -p(1)*x.*exp(-p(2)*x),0*x+1];
>
> what I did was added +p(3) to the original function. I then calculated the
> partial diff with respect to p(3). this is " 1 ".
> when I put a 1 in the 3rd position in leasqrdfdp, then the program does not
> work. but when I make the 3rd term to by 0*x + 1 then the program runs and
> gives the correct answer.
>
> should just +1 work???
'x' is a vector, no scalar, and 'leasqrdfdp' returns a (numel(x) by 3)
matrix, not a vector... So '1' is wrong (error: horizontal dimensions
mismatch (10x2 vs 1x1)), 'ones(numel(x), 1)' is ok (no spaces between
'ones' or 'numel' and '('), which is the same as '0*x+1'.
Off topic: I recommend to use nonlin_curvefit instead of leasqr, the
default algorithm is the same.
Olaf
--
public key id EAFE0591, e.g. on x-hkp://pool.sks-keyservers.net
[Prev in Thread] | Current Thread | [Next in Thread] |