Message Boards Message Boards

Recursive function, and input format, how to, fix it

Posted 1 year ago

I have the following question, I got a recursive function from my adviser, that has the following form

InterX[phi,phiV,omegaas_List,e_List,h_List,vars_List]=    
varin=vars[[2;;]];
varout=vars[[1]];


If[Length[varin]>0,
omin=omegas[[2;;]];
omot=omegas[[1]];

eInner=If[Length[varin]>=2Length[vars],e[[2;;]],e[[2]]];
hInner=If[Length[varin]>=2Length[vars],h[[2;;]],h[[2]]];

eCur=If[Length[varin]==1,eInner,eInner[[1]]];
hCur=If[Length[varin]==1,hInner,hInner[[1]]];

CMatrix={{1}};
CMatrix=InterX[eCur,hCur,omin,eInner,hInner,varin];

phiN=InterX[phi,hCur,omin,eInner,hInner,varin];
phiN=phiN.Inverse[CMatrix];

phiVN=InterX[eCur,phiV,omin,eInner,hInner,varin];
phiVN=Inverse[CMatrix].phiVN;

Omega=InterX[D[eCur,varout]+omot.eCur,omin,eInner,hInner,varin];
Print[Omega]
;
out=DeqRes[varout,Omega,phiN],phiVN];

  ];

Further, I wrote the function,

DeqRes=Function[{varout,Omega,phiN,phiVN},
Module[{polesol,aaa1,eks2,eks3,poles,aa,nu,
max,pole,varrule,jac,phiNuse,phiNVuse,omegause,psiansatz,
zeroeks,zeroser,zerolist,solvevars,eqs,zerosol,psieks,Expiseks,contribution,result
,rulp,Fzerolist},

aaa1=Map[Denominator[Factor[#]]&,Omega/aa];
Print[aaa1];
eks2=Table[Apply[List,aaa1[[i]]],{i,Length[aaa1]}];(*for 2 and 3 i get an Eror*)
eks3=Apply[Times,Union[Flatten[eks2]]/. {aa->1}];
polesol=Solve[eks3==0,phiN]//Union;
poles=Append[Table[polesol[[i,1,2]],{i,Length[polesol]}],Infinity];


result=0;
max=1;
nu=Length[phiN];

Do[
 pole=poles[[i]];
 Print[i];
 varrule=If[pole===Infinity,{varout->1/y,jac->-1/y^2},{varout->y+pole,jac->1}];
 phiNuse=phiN*jac/. varrule;
 phiNVuse=phiVN*jac/. varrule;
 omegause=Omega*jac/. varrule;
 psiansatz=Table[Sum[psi[i,j]*y^i,{i,-1,max}],{j,1,nu}];
 zeroeks=D[psiansatz,y]+psiansatz.omegause-phiNuse;
 zeroser=Series[zeroeks,{y,0,max-1}];
 zerolist=Table[Coefficient[zeroser,y,i],{i,-3,max-1}];
 Fzerolist=Flatten[zerolist];
 (*Print[Fzerolist];*);
 solvevars=Union[Cases[psiansatz,psi[__],All]];
 eqs=Map[(0==#)&,Fzerolist];
 zerosol=Solve[eqs,solvevars];(*Empty way*) 
 psieks=psiansatz/. zerosol[[1]];
 rulp={psi[__]:>0};
 Expiseks=Normal[Series[psieks.CMatrix.phiNVuse,{y,0,0}]]/.rulp;
 contribution=Residue[Expiseks,{y,0}];
 result+=contribution;
 Print[result];
 ,{i,1,1+0*Length[poles]}];
];
]

Which individually works, for a given input, however, if I run both pieces of code together for the following example,

phi={1/z1/z2/(1-z1-z2)};
phiV={1/z1^2/z2/(1-z1-z2)};
omegas={q/z2-r/(1-z1-z2),p/z1-r/(1-z1-z2)};
e={{0},{1/z1/(1-z1-z2)}};
h={{0},{1/z1/(1-z1-z2)}};
vars={z2,z1};

i got the, Following error messages

ReplaceAll::reps: {True,True,True,True,True,True,0==<<1>>,0=={Power[<<2>>] psi[<<2>>]+psi[0,1]+y psi[<<2>>],Power[<<2>>] psi[<<2>>]+psi[0,2]+y psi[<<2>>]}.(-(InterX[{Plus[<<2>>]},{Plus[<<2>>]},{Times[<<2>>]},{Times[<<2>>]},{z1}]/y^2))+((InterX[<<6>>].Inverse[<<1>>]-psi[<<2>>])/y^2+(Power[<<2>>] Dot[<<2>>] Plus[<<4>>]+Power[<<2>>] Dot[<<2>>] (<<1>>^(<<1>>))[<<1>>] Plus[<<5>>])/y+(psi[1,2]+Power[<<2>>] Dot[<<2>>] (<<1>>^(<<1>>))[<<1>>] Plus[<<4>>] Plus[<<5>>]+Dot[<<2>>] Plus[<<15>>]+Dot[<<2>>] Plus[<<2>>])+O[y]^1)} is neither a list of replacement rules nor a valid dispatch table, and so cannot be used for replacing

ReplaceAll::reps: {True,True,True,True,True,True,0==<<1>>,0=={Power[<<2>>] psi[<<2>>]+psi[0,1]+y psi[<<2>>],Power[<<2>>] psi[<<2>>]+psi[0,2]+y psi[<<2>>]}.(-(InterX[{Plus[<<2>>]},{Plus[<<2>>]},{Times[<<2>>]},{Times[<<2>>]},{z1}]/y^2))+((InterX[<<6>>].Inverse[<<1>>]-psi[<<2>>])/y^2+(Power[<<2>>] Dot[<<2>>] Plus[<<4>>]+Power[<<2>>] Dot[<<2>>] (<<1>>^(<<1>>))[<<1>>] Plus[<<5>>])/y+(psi[1,2]+Power[<<2>>] Dot[<<2>>] (<<1>>^(<<1>>))[<<1>>] Plus[<<4>>] Plus[<<5>>]+Dot[<<2>>] Plus[<<15>>]+Dot[<<2>>] Plus[<<2>>])+O[y]^1)} is neither a list of replacement rules nor a valid dispatch table, and so cannot be used for replacing.

ReplaceAll::reps: {True,True,True,True,True,True,0==<<1>>,0=={Power[<<2>>] psi[<<2>>]+psi[0,1]+y psi[<<2>>],Power[<<2>>] psi[<<2>>]+psi[0,2]+y psi[<<2>>]}.(-(InterX[{Plus[<<2>>]},{Plus[<<2>>]},{Times[<<2>>]},{Times[<<2>>]},{z1}]/y^2))+((InterX[<<6>>].Inverse[<<1>>]-psi[<<2>>])/y^2+(Power[<<2>>] Dot[<<2>>] Plus[<<4>>]+Power[<<2>>] Dot[<<2>>] (<<1>>^(<<1>>))[<<1>>] Plus[<<5>>])/y+(psi[1,2]+Power[<<2>>] Dot[<<2>>] (<<1>>^(<<1>>))[<<1>>] Plus[<<4>>] Plus[<<5>>]+Dot[<<2>>] Plus[<<15>>]+Dot[<<2>>] Plus[<<2>>])+O[y]^1)} is neither a list of replacement rules nor a valid dispatch table, and so cannot be used for replacing.

General::stop: Further output of ReplaceAll::reps will be suppressed during this calculation.
Attachments:
POSTED BY: Toni Teschke
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract