PatrickT

Dr. Patrick T

2108 Reputation

18 Badges

16 years, 304 days

MaplePrimes Activity


These are replies submitted by PatrickT

@Deadstar 

yes you're right, I changed the Ns into ns as an afterthought, not remembering what I was doing a minute earlier.

The first step, I think, would be to write your functions in the general format, to make use of seq. I don't know if this will be efficient, but it's worth a shot.

so you've got a very general function of x, f,  with coefficients a[i], and then another function of x, g, with coefficients that are complicated functions of the a[i], and you want to equate some of the coefficients (not all, since you are neglecting higher terms), does the following compute the desired functions and coefficients? I may not have properly set up g, please check.

N := 6: Order := 3*N: #just to make sure we're not truncating too soon
f := (x,n) -> 1 + add(a[2*i]*x^(2*i),i=1..n):
g := (x,n) -> convert(series( f(f(x*f(1,N),N),N)/f(1,N) ,x ,n ),polynom):
seq(a[2*i]=coeff(g(x,N),x^i),i=1..N);

then something like the following should solve for the coefficient-equations.

solve({%},{seq(a[2*i],i=1..N)},AllSolutions=true);

Once that is set up properly, you may want to set N as a variable and use seq to increment over N

The best would be to spot a "formula" (recurrence for instance) linking the a[i]s.

for you info,

http://www.maplesoft.com/support/help/Maple/view.aspx?path=sum

The sum command (sum) is for symbolic summation.

http://www.maplesoft.com/support/help/Maple/view.aspx?path=add

The add command is used to add up an explicit sequence of values.

I still don't understand what you're doing, sorry, hopefully someone else may be able to help.

@Wang Gaoteng 

your English is very clear, don't worry.

@Wang Gaoteng 

your English is very clear, don't worry.

well, it didn't work here when I copy-pasted...

why don't you copy the code you have? it may be easier to understand, and at least we can make progress step by step.

copy the code from the worksheet, not a screenshot, something that we can also copy and paste into a worksheet and try.

remove the output before copying the code, as I did below.

I reordered the equations because I couldn't do [evalf(solve(A = select(has, g, x^4), a))][1]; without first knowing A and a. But perhaps your worksheet already defines A and a on some earlier lines. Show it all.

restart:
f := x -> 1 - lambda*x^2 + a*x^4;
g := 1 - lambda*x^2 + a*x^4;
alpha := 1/f(1);
A := select(has, collect(alpha*f(f(x/alpha)),x), x^4);
a := [evalf(solve(A = select(has, g, x^4), a))][1];
lambda := [evalf(solve(A = select(has, g, x^2), a))];
                               []


the last line shows that Maple didn't come up with anything useful.

well, it didn't work here when I copy-pasted...

why don't you copy the code you have? it may be easier to understand, and at least we can make progress step by step.

copy the code from the worksheet, not a screenshot, something that we can also copy and paste into a worksheet and try.

remove the output before copying the code, as I did below.

I reordered the equations because I couldn't do [evalf(solve(A = select(has, g, x^4), a))][1]; without first knowing A and a. But perhaps your worksheet already defines A and a on some earlier lines. Show it all.

restart:
f := x -> 1 - lambda*x^2 + a*x^4;
g := 1 - lambda*x^2 + a*x^4;
alpha := 1/f(1);
A := select(has, collect(alpha*f(f(x/alpha)),x), x^4);
a := [evalf(solve(A = select(has, g, x^4), a))][1];
lambda := [evalf(solve(A = select(has, g, x^2), a))];
                               []


the last line shows that Maple didn't come up with anything useful.

@PatrickT 

For some reason applying sort after coeffs yields the desired result, while sorting before coeffs does not.

(well, it looks that way with my simple Vectors, but only limited testing done)

Perhaps what's going on is either coeffs does some sorting of its own or sorting has different rules for polynomials and for lists of coefficients or both (or neither).

It gives me the a1,a2,a3,a4,a5 you'd expect from Taylor expansion style sorting of terms.

V := X-> Vector([[a4*X[2]^2+a1*X[1]+a5*X[1]*X[2]+a2*X[2]+a3*X[1]^2],[(b1*X[1]+b2*X[2])^2]]): V(X);
ExtractCoeffs := proc(V,X)
local d,i;
d:=[op(1,V(X))][1];
Matrix([seq([op(sort([coeffs(collect(
expand(V(X)[i])                      #expand vector
,[seq(X[i],i=1..d)],'distributed')   #collect options
,[seq(X[i],i=1..d)]                  #coeffs option
)]))],i=1..d)]);
end proc:
ExtractCoeffs(V,X);

almost surely this proc has some unnecessary op and []



P.S. I made a very lame attempt to test the use of sort on the coefficients of Taylor expansions, I copy it below for future reference in case I need that sort of thing again, but if anyone looks at it they'll see that I wasn't able to properly enter the factorial term of the multivariate expansion, how sad...

restart:
m:=2: n:=3:
X:=seq(x[i],i=1..m):
L:=map(op,[seq(combinat:-choose([seq(i$n,i=1..m)],k),k=0..n)]):
taylor_polynomial := mtaylor(f(X),[seq(x[i]=0,i=1..m)],n+1);
taylor_coefficients := eval( seq(D[op(s)](f)(X) = a[op(s)],s=L), X=op([seq(0,i=1..m)]));
general_polynomial := subs(taylor_coefficients,taylor_polynomial):
general_polynomial := subs({a[1,1]=2*a[1,1],a[2,2]=2*a[2,2],a[2,2,2]=6*a[2,2,2],a[1,1,1]=6*a[1,1,1],a[1,1,2]=2*a[1,1,2],a[1,2,2]=2*a[1,2,2]},general_polynomial);
# This line is here because of my inability to write the formula for the factorials in the coefficients of the Taylor expansion, works only for m=2,n=3
sort(general_polynomial);
polynomial_coefficients := [coeffs(general_polynomial,[seq(x[i],i=1..m)])];

sorted_coefficients := sort(polynomial_coefficients);
   [a[], a[1], a[2], a[1, 1], a[1, 2], a[2, 2], a[1, 1, 1],

     a[1, 1, 2], a[1, 2, 2], a[2, 2, 2]]

Now that's the order I expect!

@PatrickT 

For some reason applying sort after coeffs yields the desired result, while sorting before coeffs does not.

(well, it looks that way with my simple Vectors, but only limited testing done)

Perhaps what's going on is either coeffs does some sorting of its own or sorting has different rules for polynomials and for lists of coefficients or both (or neither).

It gives me the a1,a2,a3,a4,a5 you'd expect from Taylor expansion style sorting of terms.

V := X-> Vector([[a4*X[2]^2+a1*X[1]+a5*X[1]*X[2]+a2*X[2]+a3*X[1]^2],[(b1*X[1]+b2*X[2])^2]]): V(X);
ExtractCoeffs := proc(V,X)
local d,i;
d:=[op(1,V(X))][1];
Matrix([seq([op(sort([coeffs(collect(
expand(V(X)[i])                      #expand vector
,[seq(X[i],i=1..d)],'distributed')   #collect options
,[seq(X[i],i=1..d)]                  #coeffs option
)]))],i=1..d)]);
end proc:
ExtractCoeffs(V,X);

almost surely this proc has some unnecessary op and []



P.S. I made a very lame attempt to test the use of sort on the coefficients of Taylor expansions, I copy it below for future reference in case I need that sort of thing again, but if anyone looks at it they'll see that I wasn't able to properly enter the factorial term of the multivariate expansion, how sad...

restart:
m:=2: n:=3:
X:=seq(x[i],i=1..m):
L:=map(op,[seq(combinat:-choose([seq(i$n,i=1..m)],k),k=0..n)]):
taylor_polynomial := mtaylor(f(X),[seq(x[i]=0,i=1..m)],n+1);
taylor_coefficients := eval( seq(D[op(s)](f)(X) = a[op(s)],s=L), X=op([seq(0,i=1..m)]));
general_polynomial := subs(taylor_coefficients,taylor_polynomial):
general_polynomial := subs({a[1,1]=2*a[1,1],a[2,2]=2*a[2,2],a[2,2,2]=6*a[2,2,2],a[1,1,1]=6*a[1,1,1],a[1,1,2]=2*a[1,1,2],a[1,2,2]=2*a[1,2,2]},general_polynomial);
# This line is here because of my inability to write the formula for the factorials in the coefficients of the Taylor expansion, works only for m=2,n=3
sort(general_polynomial);
polynomial_coefficients := [coeffs(general_polynomial,[seq(x[i],i=1..m)])];

sorted_coefficients := sort(polynomial_coefficients);
   [a[], a[1], a[2], a[1, 1], a[1, 2], a[2, 2], a[1, 1, 1],

     a[1, 1, 2], a[1, 2, 2], a[2, 2, 2]]

Now that's the order I expect!

As it turns out, my problem is really related to the proper use of sort.

My polynomials are generated by Taylor expansions, so I would like to order them from the lower order to the higher order.

Suppose I have the polynomials below, where my preferred order of the coefficients, after sorting, is given by a0,a1,a2,a3,a4,a5,a6,a7,a8,a9.

Can Maple's sort command produce any one of these two orders?

These orders are how I would have intuitively ordered the polynomial myself with pen and paper. I would have taken the order in p1 as a first choice, the order in p2 as a second choice.

Is this intuitive ordering so much at variance with mathematical conventions about ordering terms in polynomials?

p1 := a0 + a1*x + a2*y + a3*z + a4*x^2 + a5*x*y + a6*x*z + a7*y^2 + a8*y*z + a9*z^2;
p2 := a0 + a1*x + a2*y + a3*z + a4*x^2 + a5*y^2 + a6*z^2 + a7*x*y + a8*x*z + a9*y*z;
sort(p1,order=plex(z,y,x),'ascending');
sort(p2,order=plex(z,y,x),'ascending');

If there is no simple way to generate the orderings in p1 or p2, what would be a conventional ordering of coefficients, in your view (from lower to higher powers of x)?

below are 4 examples of how I can order polynomials with sort.

p := y*z + y^2 + x + x*y + x^2 + 1 + z + x*z + y + z^2 + x*y*z + x^3 + z^3 + x^2*y +y^2*z;
sort(p,order=plex(x,y,z),'ascending');
sort(p,order=plex(x,y,z),'descending');
sort(p,order=plex(z,y,x),'ascending');
sort(p,order=plex(z,y,x),'descending');

As it turns out, my problem is really related to the proper use of sort.

My polynomials are generated by Taylor expansions, so I would like to order them from the lower order to the higher order.

Suppose I have the polynomials below, where my preferred order of the coefficients, after sorting, is given by a0,a1,a2,a3,a4,a5,a6,a7,a8,a9.

Can Maple's sort command produce any one of these two orders?

These orders are how I would have intuitively ordered the polynomial myself with pen and paper. I would have taken the order in p1 as a first choice, the order in p2 as a second choice.

Is this intuitive ordering so much at variance with mathematical conventions about ordering terms in polynomials?

p1 := a0 + a1*x + a2*y + a3*z + a4*x^2 + a5*x*y + a6*x*z + a7*y^2 + a8*y*z + a9*z^2;
p2 := a0 + a1*x + a2*y + a3*z + a4*x^2 + a5*y^2 + a6*z^2 + a7*x*y + a8*x*z + a9*y*z;
sort(p1,order=plex(z,y,x),'ascending');
sort(p2,order=plex(z,y,x),'ascending');

If there is no simple way to generate the orderings in p1 or p2, what would be a conventional ordering of coefficients, in your view (from lower to higher powers of x)?

below are 4 examples of how I can order polynomials with sort.

p := y*z + y^2 + x + x*y + x^2 + 1 + z + x*z + y + z^2 + x*y*z + x^3 + z^3 + x^2*y +y^2*z;
sort(p,order=plex(x,y,z),'ascending');
sort(p,order=plex(x,y,z),'descending');
sort(p,order=plex(z,y,x),'ascending');
sort(p,order=plex(z,y,x),'descending');

Thanks for the suggestion Roman,

I had a very quick look at Algebraic:-RecursiveDensePolynomial last night, at my office where I have Maple 13, and nice things happened, but it was late so I thought I'd give it a better look from home. I have Maple 14 at home and the package doesn't work there. See the output below.

Now from what I remember seeing last night, coefficients would be extracted into a Matrix with one simple command. But I didn't have time to find out whether I could select the order of the coefficients myself, which is my problem. So it remains an open question whether the package can help me for this particular purpose.

But I did have a question: if my polynomials are generated by mtaylor, how can I convert them to the nice format that RecursiveDensePolynomial would be able to convert? The package works on your F but not on your f. I've got polynomials of the f type.

Patrick.

 

with(Algebraic:-RecursiveDensePolynomials);
Warning, Algebraic:-RecursiveDensePolynomials is not a correctly formed package - option `package' is missing
[AGCD, GFqGCD_wrapper, GFqMUL_wrapper, GFqREM_wrapper, MGCD,

  NEXTPRIME, NGCD, PGCD, RPolyInterface, addrpoly, charrpoly,

  checkconsistency, chremrpoly, coeffrpoly, coeffsrpoly, compdeg,

  consrpoly, contrpoly, defectrpoly, degrpoly, diffrpoly,

  discrpoly, divrpoly, evalrpoly, extrpoly, gcdexrpoly, gcdrpoly,

  getalgext, getalgexts, getcofring, getpolvars, ichremrpoly,

  icoeffrpoly, icoeffsrpoly, icontrpoly, idenomrpoly, ilcrpoly,

  interprpoly, invrpoly, ipprpoly, iquorpoly, irecofs,

  irredrpoly, irrrpoly, isFibonacci, isconstant, isdefectzero,

  ismonomial, isretrpoly, issubring, isunivariate, itcrpoly,

  keeplastFn, lcbad, lcmrpoly, lcrpoly, ldegrpoly, liftrpoly,

  linsolrpoly, list2rpoly, makemainrpoly, maple2rpoly, maprpoly,

  maxnrpoly, mergerings, mindeg, minrpoly, modprpoly, modrpoly,

  modsrpoly, monrpoly, mulrpoly, negrpoly, nmirpoly, normrpoly,

  nrpoly, nrprpoly, nullspacerpoly, onenrpoly, phirpoly,

  pnormrpoly, powmodrpoly, powrpoly, pprpoly, premrpoly,

  primesplits, projring, pthrootrpoly, quorpoly, randffelem,

  randrpoly, recadd_wrapper, recchrem, reccof, recdeg, recdiv,

  receval_wrapper, recext, recgcd_wrapper, recgcdex, recichrem,

  recinv_wrapper, reciquo, recirrr, recldeg, recmap,

  recmon_wrapper, recmul_wrapper, recneg_wrapper, recnmp, recnp,

  recofs, recphi, recran, recrem_wrapper, recrr, recsca_wrapper,

  recshift, recsub_wrapper, rectdeg, redrpoly, remrpoly,

  resrpoly, retcharpoly, retextsrpoly, retvarpoly, rpoly,

  rpoly2maple, rrefrpoly, rring, rrrpoly, scafix, scamul_wrapper,

  scarpoly, shiftrpoly, subresrpoly, subrpoly, tcrpoly,

  tdegrpoly, trampoline, whichsplit, zerodivisor]
F := rpoly(f, [x,y,z]);  # prints nicely
Error, (in Algebraic:-RecursiveDensePolynomials:-rpoly) unable to convert

Thanks for the suggestion Roman,

I had a very quick look at Algebraic:-RecursiveDensePolynomial last night, at my office where I have Maple 13, and nice things happened, but it was late so I thought I'd give it a better look from home. I have Maple 14 at home and the package doesn't work there. See the output below.

Now from what I remember seeing last night, coefficients would be extracted into a Matrix with one simple command. But I didn't have time to find out whether I could select the order of the coefficients myself, which is my problem. So it remains an open question whether the package can help me for this particular purpose.

But I did have a question: if my polynomials are generated by mtaylor, how can I convert them to the nice format that RecursiveDensePolynomial would be able to convert? The package works on your F but not on your f. I've got polynomials of the f type.

Patrick.

 

with(Algebraic:-RecursiveDensePolynomials);
Warning, Algebraic:-RecursiveDensePolynomials is not a correctly formed package - option `package' is missing
[AGCD, GFqGCD_wrapper, GFqMUL_wrapper, GFqREM_wrapper, MGCD,

  NEXTPRIME, NGCD, PGCD, RPolyInterface, addrpoly, charrpoly,

  checkconsistency, chremrpoly, coeffrpoly, coeffsrpoly, compdeg,

  consrpoly, contrpoly, defectrpoly, degrpoly, diffrpoly,

  discrpoly, divrpoly, evalrpoly, extrpoly, gcdexrpoly, gcdrpoly,

  getalgext, getalgexts, getcofring, getpolvars, ichremrpoly,

  icoeffrpoly, icoeffsrpoly, icontrpoly, idenomrpoly, ilcrpoly,

  interprpoly, invrpoly, ipprpoly, iquorpoly, irecofs,

  irredrpoly, irrrpoly, isFibonacci, isconstant, isdefectzero,

  ismonomial, isretrpoly, issubring, isunivariate, itcrpoly,

  keeplastFn, lcbad, lcmrpoly, lcrpoly, ldegrpoly, liftrpoly,

  linsolrpoly, list2rpoly, makemainrpoly, maple2rpoly, maprpoly,

  maxnrpoly, mergerings, mindeg, minrpoly, modprpoly, modrpoly,

  modsrpoly, monrpoly, mulrpoly, negrpoly, nmirpoly, normrpoly,

  nrpoly, nrprpoly, nullspacerpoly, onenrpoly, phirpoly,

  pnormrpoly, powmodrpoly, powrpoly, pprpoly, premrpoly,

  primesplits, projring, pthrootrpoly, quorpoly, randffelem,

  randrpoly, recadd_wrapper, recchrem, reccof, recdeg, recdiv,

  receval_wrapper, recext, recgcd_wrapper, recgcdex, recichrem,

  recinv_wrapper, reciquo, recirrr, recldeg, recmap,

  recmon_wrapper, recmul_wrapper, recneg_wrapper, recnmp, recnp,

  recofs, recphi, recran, recrem_wrapper, recrr, recsca_wrapper,

  recshift, recsub_wrapper, rectdeg, redrpoly, remrpoly,

  resrpoly, retcharpoly, retextsrpoly, retvarpoly, rpoly,

  rpoly2maple, rrefrpoly, rring, rrrpoly, scafix, scamul_wrapper,

  scarpoly, shiftrpoly, subresrpoly, subrpoly, tcrpoly,

  tdegrpoly, trampoline, whichsplit, zerodivisor]
F := rpoly(f, [x,y,z]);  # prints nicely
Error, (in Algebraic:-RecursiveDensePolynomials:-rpoly) unable to convert

I meant it in the Greek sense, which is all good. Not sure how the English language came to distort the original meaning. Perhaps English speakers don't like to be taught? I love it and I've greatly enjoyed your lessons Dave, thanks.

@Preben Alsholm 

thanks a lot, that clarifies it all, many thanks.

First 53 54 55 56 57 58 59 Last Page 55 of 93