forked from Aurelius-Nero/Maxima-References
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPolynomials.wxm
More file actions
218 lines (191 loc) · 6.58 KB
/
Polynomials.wxm
File metadata and controls
218 lines (191 loc) · 6.58 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
/* [wxMaxima batch file version 1] [ DO NOT EDIT BY HAND! ]*/
/* [ Created with wxMaxima version 22.04.0 ] */
/* [wxMaxima: input start ] */
/* Date: Sat Dec 18 23:13:31 WET 2004 */
/* Contributor: Viktor T. Toth */
/* Description: returns a list of the terms of a (univariate) polynomial*/
pargs(x):=if atom(x) or length(x)=0 or op(x)#"+" then x else args(x);
pargs(x):=if atom(x) or length(x)=0 or op(x)#"+" then x else substpart("[",x,0);
/* [wxMaxima: input end ] */
/* [wxMaxima: input start ] */
/* Date: Sat Apr 14 05:04:30 WEST 2001 */
/* Contributor: Richard Fateman */
/* Description: Function that returns the exponents of the dependent terms of a (univariate) polynomial */
mypowers(r,x):=block(
[ h:hipow(r,x)],
if h=0 then [] else cons (h, mypowers(second(bothcoeff(r,x^h)),x))
)$
/* [wxMaxima: input end ] */
/* [wxMaxima: input start ] */
/* Date: Tue Apr 16 22:40:26 WEST 2013 */
/* Contributor: Stavros Macrakis */
/* Description: Returns the coefficients of an univariate polynomial (in this form does not work; it is necessary to put p:rat(p,v) in the list of variables of the block) */
coefs(p,v):=block(
[l:[]],
while p # 0 do (
l:cons(r:ratcoef(p,v,0),l),
p:(p-r)/v),
l
)$
/* [wxMaxima: input end ] */
/* [wxMaxima: input start ] */
/* Date: Fri Apr 19 10:10:53 WEST 2013 */
/* Contributor: Wilhelm Haager */
/* Description: Lists the coefficients of a univariate polynomial n ascendin order
(for the usual order for polynomials put makelist(i,i,n,0,-1) instead of makelist(i,i,0,n) */
coefficient_list(p,s) :=block(
[n:floor(hipow(p,s))],
p:expand(p),
map(lambda([u],coeff(p,s,u)),makelist(i,i,0,n))
)$
/* [wxMaxima: input end ] */
/* [wxMaxima: input start ] */
/* Date: Thu Apr 24 18:28:49 WEST 2008 */
/* Contributor: Andre Maute */
/* Description: Tries to extract the coefficients of a multivariate polynomial */
my_coeff(v,exps,poly) := block(
[c,k,l,h],
c : [],
for k : 1 thru length(exps) do block(
h : poly,
for l : 1 thru length(v) do block(
if exps[k][l] # 0 then block(
h : coeff(h,v[l],exps[k][l])
)
),
for l : 1 thru length(v) do block(
h : subst(0,v[l],h)
),
h : ratsimp(h),
c : append(c,[h])
),
return(c)
)$
/* [wxMaxima: input end ] */
/* [wxMaxima: input start ] */
/* Date: Thu Apr 24 20:16:34 WEST 2008 */
/* Contributor: Andre Maute */
/* Description: Tries to extract the coefficients of a multivariate polynomial */
my_coeff2(v,exps,poly) := block(
[c,k,l,h,rpoly],
rpoly : rat(poly,v),
c : [],
for k : 1 thru length(exps) do block(
h : rpoly,
for l : 1 thru length(v) do block(
h : ratcoeff(h,v[l],exps[k][l])
),
c : append(c,[h])
),
return(c)
)$
/* [wxMaxima: input end ] */
/* [wxMaxima: input start ] */
/* Date: Thu Apr 24 20:16:34 WEST 2008 */
/* Contributor: Andre Maute */
/* Description: Tries to extract the coefficients of a multivariate polynomial */
my_coeff3(v,exps,poly) := block(
[c,k,l,h,rpoly],
rpoly : rat(poly,v),
c : [],
for k : 1 thru length(exps) do block(
h : rpoly,
for l : 1 thru length(v) do block(
h : ratcoeff(h,v[length(v)+1-l],exps[k][length(v)+1-l])
),
c : append(c,[h])
),
return(c)
)$
/* [wxMaxima: input end ] */
/* [wxMaxima: input start ] */
/* Date: Thu Apr 24 20:26:16 WEST 2008 */
/* Contributor: Richard Fateman */
/* Description: Tries to extract the coefficients of a multivariate polynomial */
my_coeff4(v,exps,poly) := block(
[c:[],k,l,h,rpoly,lv:length(v)],
rpoly : rat(poly,v),
for k : 1 thru length(exps) do block(
h : rpoly,
for l : 1 thru length(v) do block(
h : ratcoeff(h,v[lv+1-l],exps[k][lv+1-l])
),
c : cons(h,c)
),
return(reverse(c))
)$
/* [wxMaxima: input end ] */
/* [wxMaxima: input start ] */
/* Date: Thu Apr 24 20:30:43 WEST 2008 */
/* Contributor: Richard Fateman */
/* Description: Tries to extract the coefficients of a multivariate polynomial */
my_coeff5(v,exps,poly) := block(
[c:[],k,l,h,rpoly,lv:length(v), ratvars:v], /*maybe should be ratvars:reverse[v] ?*/
rpoly : rat(poly),
for k : 1 thru length(exps) do block(
h : rpoly,
for l : 1 thru lv do block(
h : ratcoeff(h,v[lv+1-l],exps[k][lv+1-l])
),
c : cons(h,c)
),
return(reverse(c))
)$
/* [wxMaxima: input end ] */
/* [wxMaxima: input start ] */
/* Date: Thu Apr 24 22:01:39 WEST 2008 */
/* Contributor: Andre Maute */
/* Description: Tries to extract the coefficients of a multivariate polynomial */
my_coeff6(v,exps,poly) := block(
[c,k,l,h],
c : [],
for k : 1 thru length(exps) do block(
h : poly,
for l : 1 thru length(v) do block(
h : coeff(h,v[l],exps[k][l])
),
h : ratsimp(h),
c : append(c,[h])
),
return(c)
)$
/* [wxMaxima: input end ] */
/* [wxMaxima: input start ] */
/* Date: Fri Apr 25 15:29:18 WEST 2008 */
/* Contributor: Richard Fateman */
/* Description: Tries to extract the coefficients of a multivariate polynomial */
my_coeff7(v,exps,poly) := block(
[c:[],rpoly:rat(poly), ratvars:reverse(v)],
for k in exps do block(
[h:rpoly],
for L in v do block(
[e: k],
h : ratcoeff(h,L,first(e)),
e : rest(e)
),
c : cons(h,c)
),
return(reverse(c))
)$
/* [wxMaxima: input end ] */
/* [wxMaxima: input start ] */
/* Date: Sat Jan 15 20:23:32 WET 2005 */
/* Contributor: Boris Gaertner */
/* Description: Collects all the terms of a polynomial w.r.t. a variable */
rewriteAsPolynomialIn (p, t) :=block(
[expanded, degreeInT, result],
expanded : expand(p),
degreeInT: hipow(expanded, t),
result : 0,
for idx : 0 thru degreeInT do result : result + t^idx*ratcoeff(expanded, t, idx),
result
);
/* [wxMaxima: input end ] */
/* [wxMaxima: input start ] */
/* Date: Sun Jan 16 18:46:52 WET 2005 */
/* Contributor: Stavros Macrakis */
/* Description: Collects all the terms of a polynomial w.r.t. a variable */
polyform(expr,var):= ev(ratdisrep(rat(isolate(expr,var),var)),eval);
/* [wxMaxima: input end ] */
/* Old versions of Maxima abort on loading files that end in a comment. */
"Created with wxMaxima 22.04.0"$