Post Reply 
Rational functions Polynomial expansion.....[partfrac or cpartfrac]:
08-20-2015, 09:57 AM (This post was last modified: 08-24-2015 01:58 AM by toshk.)
Post: #1
Rational functions Polynomial expansion.....[partfrac or cpartfrac]:
    coded to Solve!
    Prime Solve!
Don't have Hp prime to test it......but works on virtual fine.

PHP Code:
#pragma mode( separator(.,;) integer(h32) )
Residue1();
Residue2();
#cas
Residues(f)
BEGIN
local n
,a,ms,M1,denmnummm:=0;
L1:={};L0:={};L3:={};L4:={};L2:={};
f:=exact(f);
f1:=numer(f);
f2:=denom(f);
numm:=coeff(numer(expand(f)));
denm:=coeff(denom(expand(f)));
IF 
degree(numm)>=degree(denmTHEN a:=quo(numm,denm); else a:=0;END;
M1:=proot(denm);
M1:=sort(M1);
ms:=size(M1);
L0:=(mat2list(M1));
A:=0;B:=1;
REPEAT ms:=size(L0); L2:=remove(L0(1),L0); ms2:=size(L2);A:=ms-ms2;
IF 
A==OR A==0 then Residue1();else Residue2();end;
UNTIL size(L0)==0;
msgbox("F(x)=(r1/(x-p1))+(r2/x-p2)+.....+K[polynomial]");
msgbox("if p1=p2=!p3,then F(x)=(r1/(x-p1)^2)+r2/(x-p2)+r3/(x-p3)+....+K[polynomial]");
return{
r=list2mat(L4,1),p=trn(M1),k=a};
END;
#end

#cas
Residue1()
BEGIN
local n
,fa,derf,derfa
derf:=diff(f2,x);
fa:=subst(f1,x=L0(1));
derfa:=subst(derf,x=L0(1));
n:=fa/derfa;
L4(B):=n;
B++;
L0:=L2;
END;
#end

#cas
Residue2()
BEGIN
local n
,ffa,c,ff1,ff2;
c:=A;
ff2:=subst(simplify(f*(x-L0(1))^c),x,L0(1)); L4(B):=ff2B++;
ff1:=simplify(f*(x-L0(1))^c);
FOR 
n FROM 1 TO A-1 STEP 1 DO
ff1:=simplify(diff(ff1,x));
ffa:=1/(A-1)!*subst(ff1,x=L0(1));
L4(B):=ffa;
B++;
end;
L0:=L2;
END;
#end 
Find all posts by this user
Quote this message in a reply
08-20-2015, 11:33 AM
Post: #2
RE: Rational functions.....partfac( ):
Shouldn't it be partfrac()?

partfrac(((x^4+x^3-2*x^2+x+1)/(x^5+2*x^2+7*x+1/2))) -->
(2*x^4+2*x^3-4*x^2+2*x+2)/(2*x^5+4*x^2+14*x+1)
Find all posts by this user
Quote this message in a reply
08-20-2015, 03:30 PM
Post: #3
RE: Rational functions.....partfac( ):
Try using partfrac() or cpartfrac() (the last for the complex field) ;-)
Find all posts by this user
Quote this message in a reply
08-20-2015, 05:52 PM (This post was last modified: 08-20-2015 05:53 PM by Tim Wessman.)
Post: #4
RE: Rational functions Polynomial expansion.....[partfrac or cpartfrac]:
Works here for me.

[Image: pic.png]

There was an issue with c/partfrac in the current release bernard fixed a while back as a result of another thread where having an approximate value wasn't happy in c/partfrac. Apparently it was not keeping the approximate values grouped nicely. Basically, for the moment keep floats out and everything is happy.

TW

Although I work for HP, the views and opinions I post here are my own.
Find all posts by this user
Quote this message in a reply
08-21-2015, 05:35 AM (This post was last modified: 08-24-2015 01:50 AM by toshk.)
Post: #5
RE: Rational functions Polynomial expansion.....[partfrac or cpartfrac]:
   
   
Find all posts by this user
Quote this message in a reply
08-24-2015, 01:56 AM (This post was last modified: 08-24-2015 02:38 AM by toshk.)
Post: #6
RE: Rational functions Polynomial expansion.....[partfrac or cpartfrac]: ilaplace()
Use this in conjunction with ilaplace() which Prime finds difficult to solve:
PHP Code:
#pragma mode( separator(.,;) integer(h32) )
Residue1();
Residue2();
#cas
Residues(f)
BEGIN
local n
,a,ms,ms2,M1,denmnumm;
L0:={};L4:={};L2:={};
f:=exact(f);
f1:=numer(f);
f2:=denom(f);
numm:=coeff((expand(f1)));
denm:=coeff((expand(f2)));
IF 
degree(numm)>=degree(denmTHEN a:=quo(numm,denm); else a:=0;END;
M1:=proot(denm);
M1:=sort(M1);
ms:=size(M1);
L0:=mat2list(M1);
A:=0;B:=1;
REPEAT ms:=size(L0); L2:=remove(L0(1),L0); ms2:=size(L2);A:=ms-ms2;
IF 
A==OR A==0 then Residue1();else Residue2();end;
UNTIL size(L0)==0;
return(
ΣLIST(L4)+poly2symb(a));
END;
#end

#cas
Residue1()
BEGIN
local n
,fa,derf,derfa
derf:=diff(f2,x);
fa:=subst(f1,x=L0(1));
derfa:=subst(derf,x=L0(1));
n:=fa/derfa;
L4(B):=n/(x-L0(1));
B++;
L0:=L2;
END;
#end

#cas
Residue2()
BEGIN
local n
,ffa,c,ff1,ff2;
c:=A;
ff2:=subst(simplify(f*(x-L0(1))^c),x,L0(1)); L4(B):=ff2/(x-L0(1))^cB++;
ff1:=simplify(f*(x-L0(1))^c);
FOR 
n FROM 1 TO A-1 STEP 1 DO
ff1:=simplify(diff(ff1,x));
ffa:=1/(A-1)!*subst(ff1,x=L0(1));
L4(B):=ffa/(x-L0(1))^(c-n);
B++;
end;
L0:=L2;
END;
#end 
   
Find all posts by this user
Quote this message in a reply
Post Reply 




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