views:

279

answers:

2

I want to divide p(x) by q(x) given that:

p(x)=-5x^4+3x^2-6x
q(x)=x^2+1

I tried:

p=inline('-5*(x^4)+3*(x^2)','x')

p =
     Inline function:
     p(x) = -5*(x^4)+3*(x^2)

q=inline('x^2+1','x')

q =
     Inline function:
     q(x) = x^2+1

deconv(p,q)

but got error:

??? Undefined function or method 'filter' for input arguments of type 'inline'.

Error in ==> deconv at 32
   [q,zf] = filter(b, a, [1 zeros(1,nb-na)]);

WHY?

A: 

r = sym(p) \ sym(q) would do the trick. The result would be a symbolic function, of course. To convert that to inline, s = inline(r).

Edit: As for the "WHY": you cannot divide two inline functions. Instead, they must first be converted to their symbolic representation.

AASoft
got error: >> r = sym(p) \ sym(q)??? Undefined function or method 'sym' for input arguments of type 'inline'.
izzat
how to convert it to their symbolic representation?
izzat
I don't know why you are having this problem with 'sym' - it works fine here. Perhaps you are using an older version of MATLAB? I am on 7.9.0 (R2009b) and it works correctly.
AASoft
@izzat - Do you have the Symbolic Math Toolbox installed? I believe that you need this to use sym().
Ethan White
Yes, sym() is part of the Symbolic Math Toolkit, that is why it does not work.
kigurai
+8  A: 

Inline functions are just matlab expressions that it will evaluate. It has no idea whether they are polynomials or not.

You want this:

p = [-5 0 3 -6 0];
q = [2 0 1];

[quotient remainder] = deconv(p, q)

No need for Symbolic Math Toolbox here.

Nzbuu
I suppose this is much more correct than the symbolic computations. I vote for this more correct answer )
AASoft

related questions