[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: leasqr question
From: |
seektime |
Subject: |
Re: leasqr question |
Date: |
Fri, 24 Aug 2012 08:35:18 -0700 (PDT) |
Thanks everyone for the input, I feel less alone now. Apologies for my
ignorance beforehand. Yes, I was running the first demo contained in
"leasqr.m" (code pasted below). I always thought that the whole point of
fitting experimental data is to describe them by a function. Now that said,
how can a function depend on the number of points? It's a function, no? But
nevertheless, I will look into it in more detail.
By "crash" I mean that Octave exits when I ran the script with the variable
"niter" set to more than 500. I was unable to replicate that on my Debian
6.0 (squeeze) running 3.2.4 (for the hell of it I tried niter=50,000 and it
ran just fine, blazing fast). I've experience a lot of those
exits/crashes/error-out's on my XP system, not only with this script. Those
events are unfortunately not consistent and that's why I never bothered
filing a bug report. Don't get me wrong, I truly appreciate the skill, time
and effort of the folks who compiled Octave for Windoze with installer and
everything but I have to say that speed and reliability is a far cry from
running it on Linux.
Could anyone give me a quick answer on what the major differences are
between fsolve and leasrq? There only a dozen data points per fit and speed
is not really an issue for my current project.
========the code==============
%!demo from "leasqr.m"
% works, MK, Aug 23, 2012
%! % Define functions
leasqrfunc = @(x, p) p(1) * exp (-p(2) * x);
leasqrdfdp = @(x, f, p, dp, func) [exp(-p(2)*x), -p(1)*x.*exp(-p(2)*x)];
%!
%! % generate test data
t = [1:10:100]';
p = [1; 0.1];
data = leasqrfunc (t, p);
rnd = [0.352509; -0.040607; -1.867061; -1.561283; 1.473191; ...
0.580767; 0.841805; 1.632203; -0.179254; 0.345208];
% add noise
% wt1 = 1 /sqrt of variances of data
% 1 / wt1 = sqrt of var = standard deviation
wt1 = (1 + 0 * t) ./ sqrt (data);
data = data + 0.05 * rnd ./ wt1;
% Note by Thomas Walter <address@hidden>:
%
% Using a step size of 1 to calculate the derivative is WRONG !!!!
% See numerical mathbooks why.
% A derivative calculated from central differences needs:
% step = 0.001...1.0e-8
% And onesided derivative needs:
% step = 1.0e-5...1.0e-8 and may be still wrong
F = leasqrfunc;
dFdp = leasqrdfdp; % exact derivative
% dFdp = dfdp; % estimated derivative
dp = [0.001; 0.001];
pin = [.8; .05];
stol=0.001; niter=50;
minstep = [0.01; 0.01];
maxstep = [0.8; 0.8];
options = [minstep, maxstep];
global verbose;
verbose = 1;
[f1, p1, kvg1, iter1, corp1, covp1, covr1, stdresid1, Z1, r21] = ...
leasqr (t, data, pin, F, stol, niter, wt1, dp, dFdp, options);
--
View this message in context:
http://octave.1599824.n4.nabble.com/leasqr-question-tp4643194p4643233.html
Sent from the Octave - General mailing list archive at Nabble.com.