-
Notifications
You must be signed in to change notification settings - Fork 14
/
polypower.m
51 lines (50 loc) · 1.22 KB
/
polypower.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
function [term ifail r]=polypower(varname,m,p)
ifail=0;
sp=num2str(p);
NN='[n1';
str=sp;
command=['k=0;for n1=0:' str ';'];
myend='end;';
for i=2:m
NN=strcat(NN,sprintf(' n%d',i));
str=strcat(str,sprintf('-n%d',i-1));
command=strcat(command,sprintf('for n%d=0:',i),str,';');
myend=strcat(myend,'end;');
end
NN=strcat(NN,sprintf(' n%d]',m+1));
str=strcat(str,sprintf('-n%d',m));
command=strcat(command,sprintf('n%d=',m+1),str,';','k=k+1;N(k,:)=',NN,';nfc(k)=multinom(',sp,',',NN,');',myend);
disp(length(command));
eval(command,'ifail=4;');
if ifail>0
term=0;
r=0;
return
end
nterm=k-1;
for i=1:nterm
if nfc(i)>1
tt=sprintf('sqrt(%d).*',nfc(i));
else
tt='';
end
for j=2:m
switch N(i,j)
case 0
case 1
tt=strcat(tt,sprintf('%s(%d,:).*',varname,j-1));
otherwise
tt=strcat(tt,sprintf('%s(%d,:).^%d.*',varname,j-1,N(i,j)));
end
end
switch N(i,m+1)
case 0
tt=tt(1:length(tt)-2);
case 1
tt=strcat(tt,sprintf('%s(%d,:)',varname,m));
otherwise
tt=strcat(tt,sprintf('%s(%d,:).^%d',varname,m,N(i,m+1)));
end
term{i,1}=tt;
end
r=[nfc' N];