|
Prev: Extract integer from weird string
Next: SVD output
From: Alex Berkovich on 6 May 2008 09:03 Hello, Is there a function like 'polyfit' but one that can make sure that the resulting curve passes through certain points or points? Thank you very much Alex
From: John D'Errico on 6 May 2008 09:52 "Alex Berkovich" <alexber(a)tx.technion> wrote in message <fvpku7$11a$1(a)fred.mathworks.com>... > Is there a function like 'polyfit' but one that can make > sure that the resulting curve passes through certain > points or points? Its trivial to do with lsqlin, so if you have the optimization toolbox, then no problem. If not, then its is as trivial to use my lse code, as found on the file exchange. http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do? objectId=13835&objectType=FILE For example: x = randn(20,1); err = randn(size(x))/10; y = 1 - x + x.^2 + err; % simple polyfit, unconstrained p0 = polyfit(x,y,2) p0 = 0.97807 -1.0345 0.98762 % Note that at x = 0.5, we know this curve % must pass through y = 0.75. polyfit was % close, but not exact. polyval(p0,0.5) ans = 0.71487 xf = 0.5; Aeq = [xf.^2,xf,1]; Beq = 0.75; % using lse, we get pf = lse([x.^2,x,ones(size(x))],y,Aeq,Beq) pf = 0.9844 -1.0087 1.0083 polyval(pf,0.5) ans = 0.75 HTH, John
|
Pages: 1 Prev: Extract integer from weird string Next: SVD output |