help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Non linear equations: howto?


From: Ivan Sutoris
Subject: Re: Non linear equations: howto?
Date: Sun, 19 Oct 2008 22:38:04 +0200

Hello

if I understood your post correctly, you are trying to fit function
with 5 parameters through 6 points, which might be impossible to do
exactly. Another option would be to fit curve approximately in the
least squares sense, for example for your problem, this seems to find
quite a good fit:

% define function of x and parameters
f = @(x,p) (p(1)*x+p(2)) .* exp(p(3)*x+p(4)) + p(5);
% define data
data_x = [1; 2; 3; 4; 5; 6];
data_y = [0; 2; 3; 4; 2.5; -4];
% define objective function as sum of squares of differences
minfun = @(p) sumsq(f(data_x, p) - data_y);
p0 = ones(5,1); % initial guess
% minimize
[p, fval, INFO, ITER, NF] = sqp (p0, minfun)
% draw plot
xplot = 0:0.01:7;
yplot = f(xplot,p);
plot(xplot,yplot,'b-',data_x,data_y,'ro');

Regards
Ivan Sutoris


reply via email to

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