2 added 936 characters in body
source | link

You get the poles with

p = x /. Solve[apoly == 0, x]

and the residues with

r = RootReduce[Residue[f, {x, #}]] & /@ p

I don't know how to get k directly though, except to do a difference (very inefficient):

k = f - Total[r/(x - p)] // Together // FullSimplify

All together in one function:

residue[num_, denom_] := Module[{apoly, bpoly, f, p, r, k},
  bpoly = FromDigits[num, x];
  apoly = FromDigits[denom, x];
  f = bpoly/apoly;
  p = x /. Solve[apoly == 0, x];
  r = RootReduce[Residue[f, {x, #}]] & /@ p;
  k = f - Total[r/(x - p)] // Together // FullSimplify;
  {r, p, CoefficientList[k, x]}]

Let's go through Nasser's examples:

residue[{2, 1, 0, 0}, {1, 0, 1, 1}]
(*    {{-0.0708358, 0.535418 - 1.03899 I, 0.535418 + 1.03899 I},
       {-0.682328, 0.341164 - 1.16154 I, 0.341164 + 1.16154 I},
       {2}}                                                         *)

residue[{-4, 8}, {1, 6, 8}]
(*    {{-12, 8},
       {-4, -2}, 
       {}}          *)

residue[{2, 0, 0, 1, 0}, {1, 0, 1}]
(*    {{1/2 + I, 1/2 - I},
       {-I, I},
       {-2, 0, 2}}            *)

You get the poles with

p = x /. Solve[apoly == 0, x]

and the residues with

r = RootReduce[Residue[f, {x, #}]] & /@ p

I don't know how to get k directly though, except to do a difference (very inefficient):

k = f - Total[r/(x - p)] // FullSimplify

You get the poles with

p = x /. Solve[apoly == 0, x]

and the residues with

r = RootReduce[Residue[f, {x, #}]] & /@ p

I don't know how to get k directly though, except to do a difference (very inefficient):

k = f - Total[r/(x - p)] // Together // FullSimplify

All together in one function:

residue[num_, denom_] := Module[{apoly, bpoly, f, p, r, k},
  bpoly = FromDigits[num, x];
  apoly = FromDigits[denom, x];
  f = bpoly/apoly;
  p = x /. Solve[apoly == 0, x];
  r = RootReduce[Residue[f, {x, #}]] & /@ p;
  k = f - Total[r/(x - p)] // Together // FullSimplify;
  {r, p, CoefficientList[k, x]}]

Let's go through Nasser's examples:

residue[{2, 1, 0, 0}, {1, 0, 1, 1}]
(*    {{-0.0708358, 0.535418 - 1.03899 I, 0.535418 + 1.03899 I},
       {-0.682328, 0.341164 - 1.16154 I, 0.341164 + 1.16154 I},
       {2}}                                                         *)

residue[{-4, 8}, {1, 6, 8}]
(*    {{-12, 8},
       {-4, -2}, 
       {}}          *)

residue[{2, 0, 0, 1, 0}, {1, 0, 1}]
(*    {{1/2 + I, 1/2 - I},
       {-I, I},
       {-2, 0, 2}}            *)
1
source | link

You get the poles with

p = x /. Solve[apoly == 0, x]

and the residues with

r = RootReduce[Residue[f, {x, #}]] & /@ p

I don't know how to get k directly though, except to do a difference (very inefficient):

k = f - Total[r/(x - p)] // FullSimplify