Mercurial > hg > octave-nkf
view scripts/polynomial/deconv-tuwien.m @ 2121:bc6ecd8f1175
[project @ 1996-05-12 06:45:55 by jwe]
author | jwe |
---|---|
date | Sun, 12 May 1996 06:45:55 +0000 |
parents | 4fcd2e68dd3b |
children |
line wrap: on
line source
function [x, r] = deconv(a, b) # # Returns x and r such that a = conv(b, x) + r. # If a and b are vectors of polynomial coefficients, x and r are the # vectors of coefficients of quotient and remainder in the polynomial # division of a by b. # written by KH (Kurt.Hornik@ci.tuwien.ac.at) on Dec 27, 1993 # copyright Dept of Probability Theory and Statistics TU Wien if !(nargin == 2) error("usage: deconv(a, b)"); endif f = find(b); l_b = length(f); if (l_b == 0) error("deconv(a, b): b has to be nonzero"); endif l_a = length(a); if (l_a < l_b) x = 0; r = a; else b = reshape(b(f(1):f(l_b)), 1, l_b); a = reshape(a, 1, l_a); # the stupid way: if (l_b == 1) x = a / b; else x(1) = a(1) ./ b(1); for i = 2:l_a-l_b+1; x(i) = (a(i) - b(i:-1:2) * x(1:i-1)) ./ b(1); endfor endif r = a - conv(b, x); endif endfunction