HP Forums

Full Version: Rational functions Polynomial expansion.....[partfrac or cpartfrac]:
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
[attachment=2447] coded to Solve!
[attachment=2448] 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 
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)
Try using partfrac() or cpartfrac() (the last for the complex field) ;-)
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.
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 
[attachment=2466]
Reference URL's