[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: fixed points piecewise-linear fitting
From: |
Martin Helm |
Subject: |
Re: fixed points piecewise-linear fitting |
Date: |
Tue, 20 Mar 2012 01:42:18 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:11.0) Gecko/20120312 Thunderbird/11.0 |
I want to add my poor man's solution for least squares fit of the
piecewise polynomials
returns the node values as first argument (makes only sense for the
piecewise linear case) and the function values at all nodes as second
argument.
Simplistic but fast.
function [y, yy] = ppfit2(x, xf, yf, method)
a = zeros (length (xf), length (x));
for ii = 1:length (x)
p = zeros (length (x), 1);
p(ii) = 1;
a(:, ii) = interp1 (x(:), p, xf(:), method);
endfor
y = a\yf(:);
if (nargout==2)
yy = interp1 (x(:), y, xf(:), method);
endif
endfunction
%!demo
%! clf
%! x = [0 1 2 3];
%! xf = linspace(0, 3, 1000);
%! yf = xf.^3 + rand(size(xf))*2.5;
%! plot (xf, yf, "y-")
%! hold on
%! [y, yy] = ppfit2(x,xf,yf, "linear");
%! plot (xf, yy, "r-")
%! [y, yy] = ppfit2(x,xf,yf, "cubic");
%! plot (xf, yy, "g-")
%! [y, yy] = ppfit2(x,xf,yf, "spline");
%! plot (xf, yy, "b-")
- Re: fixed points piecewise-linear fitting, (continued)
- Re: fixed points piecewise-linear fitting, Ben Abbott, 2012/03/17
- Re: fixed points piecewise-linear fitting, Juan Pablo Carbajal, 2012/03/17
- Re: fixed points piecewise-linear fitting, c., 2012/03/18
- Re: fixed points piecewise-linear fitting, Sergei Steshenko, 2012/03/18
- Re: fixed points piecewise-linear fitting, c., 2012/03/18
- Re: fixed points piecewise-linear fitting, Sergei Steshenko, 2012/03/18
- Re: fixed points piecewise-linear fitting, c., 2012/03/18
- Re: fixed points piecewise-linear fitting, Ben Abbott, 2012/03/18
- Re: fixed points piecewise-linear fitting, CdeMills, 2012/03/17
- Re: fixed points piecewise-linear fitting, Sergei Steshenko, 2012/03/17
- Re: fixed points piecewise-linear fitting,
Martin Helm <=
- Re: fixed points piecewise-linear fitting, Ben Abbott, 2012/03/19
- Re: fixed points piecewise-linear fitting, Martin Helm, 2012/03/20
- Re: fixed points piecewise-linear fitting, Martin Helm, 2012/03/20
- Re: fixed points piecewise-linear fitting, Ben Abbott, 2012/03/20
- Re: fixed points piecewise-linear fitting, Martin Helm, 2012/03/20
- Re: fixed points piecewise-linear fitting, Ben Abbott, 2012/03/20
- Re: fixed points piecewise-linear fitting, Ben Abbott, 2012/03/20
- Re: fixed points piecewise-linear fitting, Martin Helm, 2012/03/20
- Re: fixed points piecewise-linear fitting, Ben Abbott, 2012/03/21
Re: fixed points piecewise-linear fitting, Macy, 2012/03/17