help-octave
[
Top
][
All Lists
]
Advanced
[
Date Prev
][
Date Next
][
Thread Prev
][
Thread Next
][
Date Index
][
Thread Index
]
non-linear fitting , syntax-problem
From
:
Stefan Neumann
Subject
:
non-linear fitting , syntax-problem
Date
:
Fri, 12 Mar 2010 23:29:13 +0100
Hi,
here is a working script using function leasqr() to fit a function to a data-set:
filename = "tmp/non-lin.02.dat";
fid = fopen (filename, "r");
nc = 3 ; %Number of columns
nr = 98 ; %Number of data points
[val,count] = fscanf(fid,'%f %f %f',[nc,nr]); %Read matrix : x,y,z
val = val'; %Transpose
fclose (fid);
x = val(1:nr,1:(nc-1)); %Independent variables
y = val(1:nr,nc); %Dependent variable
pin=ones(1,3); %There are 7 parameters
F = inline(" p(1)*x(:,1) + p(2)*x(:,2) + p(3) ", "x", "p");
[f,p,kvg,iter,corp,covp,covr,stdresid,Z,r2]=leasqr(x,y,pin,F);
and here is one that doesn't work:
filename = "tmp/non-lin.02.dat";
fid = fopen (filename, "r");
nc = 3 ; %Number of columns
nr = 98 ; %Number of data points
[val,count] = fscanf(fid,'%f %f %f',[nc,nr]); %Read matrix : x,y,z
val = val'; %Transpose
fclose (fid);
x = val(1:nr,1:(nc-1)); %Independent variables
y = val(1:nr,nc); %Dependent variable
pin=ones(1,2); %There are 7 parameters
% Function to fit
F = inline(" p(1)*x(:,1)*x(:,2)+p(2) ", "x", "p");
[f,p,kvg,iter,corp,covp,covr,stdresid,Z,r2]=leasqr(x,y,pin,F);
The datafile 'tmp/non-lin.02.dat" contains 98 rows of 3 colums each, with column 3 (y) calculated from columns 1+2 (x1 and x2).
(FYI: The script is adapted from the example here:
http://knol.google.com/k/multidimensional-non-linear-least-squares-in-octave#
)
The first example assumes a linear function y = p1*x1 + p2*x2 + p3
The second example assumes a non-linear function y = p1*x1*x2 + p2
Obviously the second example does not work because of the multiplication of 2 vectors x(:,1) * x(:,2)
What is the correct syntax in this case, or how should I rewrite the script?
TIA, stn
reply via email to
[Prev in Thread]
Current Thread
[
Next in Thread
]
non-linear fitting , syntax-problem
,
Stefan Neumann
<=
Re: non-linear fitting , syntax-problem
,
Ben Abbott
,
2010/03/12
Re: non-linear fitting , syntax-problem
,
Sergei Steshenko
,
2010/03/12
Prev by Date:
Re: Differences between imrotate on Octave and in MatLab
Next by Date:
Re: kernel density smoother?
Previous by thread:
Two arrays specifying index pairs for a another array -- how to vectorize?
Next by thread:
Re: non-linear fitting , syntax-problem
Index(es):
Date
Thread