Post Reply 
Rational functions Polynomial expansion.....[partfrac or cpartfrac] Partial Fraction
09-22-2015, 05:58 AM (This post was last modified: 01-03-2019 07:38 AM by toshk.)
Post: #1
Rational functions Polynomial expansion.....[partfrac or cpartfrac] Partial Fraction
Partial Fraction Decomposition
Residues(1/(2*x^2+3*x+4)) or
Residues([1],[2,3,4])->answer in { residues (if multiplicity>=2 residues are in ascending order of multiplicity, poles and their multiplicity, factor}
eg.
Residues((1/(x^4-8*x^2+19))) or Residues([1],[1,0,-8,0,19])

Code:

#pragma mode( separator(.,;) integer(h32) )
Residue2();
#cas
Residues(f,ff=[])
//Residues(1/(2*x^2+3*x+4)) or
//Residues([1],[2,3,4])->answer in { residues (if multiplicity>=2 residues are in ascending order of multiplicity, 
//poles and their multiplicity, factor}
BEGIN
LOCAL a,f1,f2,q,n;
LOCAL L1,L11a,u,L5,b;
u:=0; b:=0; Z:=0; L5:={};
IF SIZE(ff)==0 THEN f:=exact(normal(f)); f1:=numer(f); f2:=denom(f); END;
IF SIZE(ff)<>0 THEN f1:=poly2symb(exact(f),'x'); f2:=poly2symb(exact(ff),'x');  f:=exact(normal(f1/f2)); Z:=1256; END;
IF degree(f1)>=degree(f2) THEN a:=quo(f1,f2,'x'); ELSE a:=0; END;
L1:=exact(mat2list(froot(f2)));
IF size(L1)==0 THEN L1:=froot(poly2symb(exact(ff),'X')); END;
IF size(L1)==0 THEN return f; END;
IF Z==1256 THEN a:=symb2poly(a); L11a:=L1; END;
REPEAT
q:=size(L1);
IF L1(q)==1 THEN  b++; n:=residue(f,'x',L1(q-1)); u:=u+evalf(n)/(x-L1(q-1));   L1:=suppress(L1,size(L1)-1,size(L1)); 
IF Z==1256 THEN L5(b):=n;  END;
ELSE Residue2(); END;
UNTIL size(L1)==0;
IF Z==0 THEN
return(u+poly2symb(a));
ELSE
return{r=list2mat(reverse(L5),1),p=list2mat(L11a,2),k=coeff(a,'x')};
END;
END;

Residue2()
BEGIN
LOCAL ff1,q,c,n;
q:=size(L1); c:=L1(q);
REPEAT
b++;
ff1:=simplify(f*(x-L1(q-1))^(c-1));
n:=residue(ff1,'x',L1(q-1)); u:=u+evalf(n)/(x-L1(q-1))^c;
IF Z==1256 THEN L5(b):=n; END;
c--;
UNTIL c==1;
n:=residue(f,'x',L1(q-1)); b++; u:=u+evalf(n)/(x-L1(q-1));
IF Z==1256 THEN L5(b):=n; END;
L1:=suppress(L1,size(L1)-1,size(L1));
IF size(L1)==0 THEN
IF Z==0 THEN
return(u+poly2symb(a));
ELSE
return{r=list2mat(reverse(L5),1),p=list2mat(L11a,2),k=coeff(a,'x')};
END;
END;
END;
#end
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)