Question: Select powers and coeffs on a general type polynomial.

I was experimenting on and found coeff and degrees  do not work with algebraic type powers. So I set aboud dismanteling  a example polynomial. I certainly went around the houses doing this. I wanted to put the powers and coefficinets of x in an array.

I sure there must be a simpler way.

restart

NULLNULL

r := proc (x) options operator, arrow; a[0]+a[1]*x-a[2]*x^2+a[8]*x^(8/5)-a[h]*x^h+k*x^(-b/a) end proc

proc (x) options operator, arrow; a[0]+a[1]*x-a[2]*x^2+a[8]*x^(8/5)-a[h]*x^h+k*x^(-b/a) end proc

mnmls := [op(r(x))]

[a[0], a[1]*x, -a[2]*x^2, a[8]*x^(8/5), -a[h]*x^h, k*x^(-b/a)]

A := Array(1 .. 2, 1 .. nops(mnmls))

Array(%id = 36893489621187187044)

mnmls, x0 := selectremove(has, mnmls, x)

[a[1]*x, -a[2]*x^2, a[8]*x^(8/5), -a[h]*x^h, k*x^(-b/a)], [a[0]]

NULL

A[2, 1] := op(x0)

a[0]

coeff(r(x), x, 2)

Error, unable to compute coeff

coeffs(r(x), x)

Error, invalid arguments to coeffs

degree(mnmls[1], x)

1

degree(mnmls[4], x)

FAIL

degree(mnmls[5], x)

FAIL

indets(r(x))

{a, b, h, k, x, a[0], a[1], a[2], a[8], a[h], x^h, x^(-b/a), x^(8/5)}

bits := [seq([op(mnmls[i])], i = 1 .. nops(mnmls))]

[[a[1], x], [-1, a[2], x^2], [a[8], x^(8/5)], [-1, a[h], x^h], [k, x^(-b/a)]]

deeperbits := [seq(op(op(bits)[i]), i = 1 .. nops(bits))]

[a[1], x, -1, a[2], x^2, a[8], x^(8/5), -1, a[h], x^h, k, x^(-b/a)]

varpwrs, cofsl := selectremove(has, deeperbits, x)

[x, x^2, x^(8/5), x^h, x^(-b/a)], [a[1], -1, a[2], a[8], -1, a[h], k]

is(nops(vars) = nops(cofsl))

false

cofs := convert(cofsl, Array)

Array(%id = 36893489621220545228)

for i to numelems(cofs)-1 do if cofs[i] = -1 then cofs[i] := 0; cofs[i+1] := -cofs[i+1]; i = i+2 end if end do; cofs; cofs := remove[flatten](has, cofs, 0)

Array(%id = 36893489621220530764)

cofs

Array(%id = 36893489621220530764)

is(nops(vars) = numelems(cofs))

false

NULL

pwrs := `assuming`([simplify(`~`[log[x]](varpwrs))], [x > 0, a::'real', b::'real', h::'real'])

[1, 2, 8/5, h, -b/a]

A

Array(%id = 36893489621187187044)

for i to nops(mnmls) do A[1, i+1] := pwrs[i]; A[2, i+1] := cofs[i] end do; A

Array(%id = 36893489621187187044)

 

NULL


Download Q_11-9-22_monomial_powers_and_coeffs.mw

Please Wait...