tomleslie

13876 Reputation

20 Badges

15 years, 164 days

MaplePrimes Activity


These are replies submitted by tomleslie

@janhardo 

through the command

unapply( f, indets(f, 'name')[])~(..)

with appropriate help pages

#
# Now suppose you have an expression
#
  f:=x^2+2*x+1;

x^2+2*x+1

(1)

#
# indets(f, 'name') returns all of the unevaluated
# names in the expression 'f' as a set. In this example
# the set only containes one entry.
#
  help(indets);
  indets(f, 'name');

{x}

(2)

#
# On this occasion, we don't want this command
# to return a 'set', we just want the 'entries'.
# There are (at least) a couple of ways to do this
#
# So all this part does is to return the 'unknown'
# variable in the original expression 'f'.
#
  help(list);
  op(indets(f, 'name')); #or
  indets(f, 'name')[];

x

 

x

(3)

#
# By using uanpply(f , indets(f, 'name')[]) the
# original supplied expression is converted to an
# appliable (nameless) function, as in
#
  help(unapply);
  unapply( f, indets(f, 'name')[]);

proc (x) options operator, arrow; x^2+2*x+1 end proc

(4)

#
# This (nameless) function can be applied to an
# argument as in
#
  unapply( f, indets(f, 'name')[])(2);
  unapply( f, indets(f, 'name')[])(a+b);

9

 

(a+b)^2+2*a+2*b+1

(5)

#
# In a similar way, this (nameless) function can be
# applied 'elementwise' to every element in a "container"
# - ie a list, an array, vector etc, by using the '~'
# operator. This will return a container of the same type,
# but with updated entries.
#
# So for the list with entries 1,2,3 and check the returned
# type
#
  help(elementwise);
  unapply( f, indets(f, 'name')[])~([1,2,3]);
  whattype(%);

[4, 9, 16]

 

list

(6)

#
# And for the Array( 1,,2, 1..3, [[1,2,3],[4,5,6]]),
# and check the returned
#
  unapply( f, indets(f, 'name')[])~(Array( 1..2, 1..3, [[ 1,2,3],[4,5,6]]));
  whattype(%);

Matrix(2, 3, {(1, 1) = 4, (1, 2) = 9, (1, 3) = 16, (2, 1) = 25, (2, 2) = 36, (2, 3) = 49})

 

Array

(7)

 


 

Download steps.mw

 

@Reshu Gupta 

which contains

  1. an expression for the the sum f[i](x) for i=0..N
  2. a plot of the expression in (1) above for x=0..5
  3. a matrix containing values of x and sum f[i](x) for i=0..N, where x varies from 0..5 in steps of 0.1

see the attached

  restart;

  N := 4:
#
# Change lhs of the assignment from f(x) to F(x)
# to avoid potential conflict arising from using
# the same name in both indexed and unindexed
# contexts
#
# Also changed sum() to add()
#
  F(x) :=  add(p^i*f[i](x), i = 0..N);
#
# Changed dependent variable throughout from f(x)
# to F(x)
#
  HPMEq := (1 - p)*diff(F(x), x $ 3) + p*(diff(F(x), x $ 3) + 1/2*diff(F(x), x, x)*F(x));
#
# Initialise sol as an empty list
#
  sol:=[]:
  for i from 0 to N do
      sol:= [ sol[],
              dsolve
              ( [ eval
                  ( coeff(HPMEq, p, i) = 0,
                    sol
                  ),
                  f[i](0) = 0,
                  D(f[i])(0) = 0,
                  D(f[i])(5) = 1
                ]
              )
            ];
  end do:
  sol;

 

f[0](x)+p*f[1](x)+p^2*f[2](x)+p^3*f[3](x)+p^4*f[4](x)

 

(1-p)*(diff(diff(diff(f[0](x), x), x), x)+p*(diff(diff(diff(f[1](x), x), x), x))+p^2*(diff(diff(diff(f[2](x), x), x), x))+p^3*(diff(diff(diff(f[3](x), x), x), x))+p^4*(diff(diff(diff(f[4](x), x), x), x)))+p*(diff(diff(diff(f[0](x), x), x), x)+p*(diff(diff(diff(f[1](x), x), x), x))+p^2*(diff(diff(diff(f[2](x), x), x), x))+p^3*(diff(diff(diff(f[3](x), x), x), x))+p^4*(diff(diff(diff(f[4](x), x), x), x))+(1/2)*(diff(diff(f[0](x), x), x)+p*(diff(diff(f[1](x), x), x))+p^2*(diff(diff(f[2](x), x), x))+p^3*(diff(diff(f[3](x), x), x))+p^4*(diff(diff(f[4](x), x), x)))*(f[0](x)+p*f[1](x)+p^2*f[2](x)+p^3*f[3](x)+p^4*f[4](x)))

 

[f[0](x) = (1/10)*x^2, f[1](x) = -(1/6000)*x^5+(73/480)*x^2, f[2](x) = (11/20160000)*x^8-(73/144000)*x^5+(18089/80640)*x^2, f[3](x) = -(1/532224000)*x^11+(803/322560000)*x^8-(36553/32256000)*x^5+(2467369/7741440)*x^2, f[4](x) = (9299/1452971520000000)*x^14-(73/6386688000)*x^11+(808291/108380160000)*x^8-(5108363/2322432000)*x^5+(80546766031/185980354560)*x^2]

(1)

#
# Idle curiosity - what do these functions
# look like
#
  plot( [ seq
          ( rhs(sol[j]),
            j=1..N+1
          )
        ],
        x = 0..5,
        legend = [ seq
                   ( lhs(sol[j]),
                     j=1..N+1
                   )
                 ]
      );

 

#
# Expression for the sum of the functions f[i](x)
# for i from 0..N
#
  fsum:= add
         ( rhs(sol[j]),
           j=1..N+1
         );
#
# And what does the plot of the sum of these
# functions look like
#
  plot( fsum,
        x=0..5
      );
#
# And generate a matrix whose columns are the
# independent variable 'x' and sum(f[i](x)) for
# x=0..5 in steps of 0.1
#
  interface(rtablesize=60):
  M:= Matrix( [ seq
                ( [ i, eval
                       ( add
                         ( rhs(sol[j]),
                           j=1..N+1
                         ),
                         x=i
                       )
                  ],
                  i=0..5, 0.1
                )
              ]
            );
  interface(rtablesize=10):

fsum := (45684823931/37196070912)*x^2-(1860919/464486400)*x^5+(227447/21676032000)*x^8-(17/1277337600)*x^11+(9299/1452971520000000)*x^14

 

 

Matrix(%id = 18446744074536222102)

(2)

 

 

Download odeSols2.mw

@acer 

Funny how often version numbers appear after I complain that they did not exist

Now I can't debug anything in Maple 11 ( released in 2007 ) because I only have the last seven Maple versions (going back to Maple 18 released in 2014). So the only thing I can suggest is to "break down" the offending command into "simple" steps, and see which one fails.

See the highlighted-green execution group in the attached -and report at which stage does it throw an error message in Maple 11. This worksheet (like the one I originally posted) works perfectly in all Maple version from Maple 18 onwards

  restart;
#
# Assorted parameters
#
  T:= 0.1: beta:= 0.6: k:= 3.5:
  A1:= (2*k-1)/(2*k-3):
  A2:= 8*sqrt(2/Pi)*(beta-1)*k*GAMMA(k)/(3*GAMMA(k-0.5)*(2*k-3)**(3/2)):
  A3:= (4*k**2-1)/(2*(2*k-3)**2):
  M1:= 0.1+sqrt(T+(1/A1)):
#
# define ODES and ICs
#
  odes:= diff(U1(x),x)=-diff(phi(x),x)/(U1(x)-T/U1(x)),
         diff(phi(x),x$2)=(1+A1*phi(x)+A2*phi(x)**(3/2)+A3*phi(x)**2)-(M1/U1(x)):
  bcs:= U1(0)=M1, phi(0)=0, D(phi)(0)=0.001:
#
# Solution and plots
#
  sol:= dsolve( [odes, bcs], numeric):
  plots:-odeplot( sol,
                  [ [x, U1(x)],
                    [x, phi(x)],
                    [x, diff(phi(x),x)]
                  ],
                  x=0..20,
                  color= [red ,blue, green]
                );

 

#
# Some tests OP should apply
# What does sol(1) return?
# It should return a list of the values of x (=1)
# U1(x), phi(x) and diff(phi(x),x), all evaluated at x=1
#
  sol(1);
#
# so sol(1)[1..2] should return the first two elements of
# the above list, as in
#
  sol(1)[1..2];
#
# And rhs~( sol(1)[1..2]) ought to return the right hand
# side of the expression in the above list, as in
#
  rhs~( sol(1)[1..2]);
#
# And all the seq() command does, is the above calculation
# for values of x from 0..20, as in
#
  seq( rhs~(sol(j)[1..2]), j=0..20);
#
# And the Matrix() wrapper on this command inserts the data
# into a Matrix wher the firsdt row has been explicitly inserted
# as in x U1(x)
#
  Matrix( [ [ x, U1(x)],
                  seq( rhs~(sol(j)[1..2]), j=0..20)
                ]
              );

[x = 1., U1(x) = .974388249766323, phi(x) = 0.105283221637071e-2, diff(phi(x), x) = 0.115886642863348e-2]

 

[x = 1., U1(x) = .974388249766323]

 

[1., .974388249766323]

 

[0., .975595035800000], [1., .974388249766323], [2., .972803454731538], [3., .970376033430992], [4., .966438414822947], [5., .959991784836733], [6., .949578265984448], [7., .933233907171832], [8., .908762259662163], [9., .874925831097515], [10., .834645490079363], [11., .800094186054956], [12., .790956031097270], [13., .814033485232378], [14., .853460668257642], [15., .891614294714236], [16., .921149911904074], [17., .941628092024671], [18., .954973968794679], [19., .963349571761450], [20., .968492424099562]

 

Matrix(%id = 18446744074330314982)

(1)

#
# Generate the values of x and U1(x) for
# x=0..20 in unit steps
#
  interface(rtablesize=25):
  res:= Matrix( [ [ x, U1(x)],
                  seq( rhs~(sol(j)[1..2]), j=0..20)
                ]
              );
  interface(rtablesize=10):
#
# Now you could use Maple's export() command
# to output the Matrix 'res' in any number of
# different formats - dependin on which format
# the target application understands
#
# But why bother?
#
# After what kind of data processing is available
# is available in the target application, which
# isn't available in Maple?
#
# If I had to guess-the answer would be none at all
#

Matrix(22, 2, {(1, 1) = x, (1, 2) = U1(x), (2, 1) = 0., (2, 2) = .9755950358000001, (3, 1) = 1., (3, 2) = .9743882497663228, (4, 1) = 2., (4, 2) = .9728034547315375, (5, 1) = 3., (5, 2) = .9703760334309917, (6, 1) = 4., (6, 2) = .9664384148229473, (7, 1) = 5., (7, 2) = .9599917848367329, (8, 1) = 6., (8, 2) = .9495782659844485, (9, 1) = 7., (9, 2) = .9332339071718317, (10, 1) = 8., (10, 2) = .9087622596621625, (11, 1) = 9., (11, 2) = .8749258310975149, (12, 1) = 10., (12, 2) = .8346454900793634, (13, 1) = 11., (13, 2) = .8000941860549555, (14, 1) = 12., (14, 2) = .7909560310972703, (15, 1) = 13., (15, 2) = .8140334852323781, (16, 1) = 14., (16, 2) = .8534606682576422, (17, 1) = 15., (17, 2) = .8916142947142357, (18, 1) = 16., (18, 2) = .9211499119040738, (19, 1) = 17., (19, 2) = .941628092024671, (20, 1) = 18., (20, 2) = .9549739687946793, (21, 1) = 19., (21, 2) = .9633495717614502, (22, 1) = 20., (22, 2) = .9684924240995624})

(2)

  restart;
#
# Convert the whole of the above to a procedure
# will accept any values of T, beta, k amd return
# the desired plot
#
  getODESol:= proc( T, beta, k)
                    local A1:= (2*k-1)/(2*k-3),
                          A2:= 8*sqrt(2/Pi)*(beta-1)*k*GAMMA(k)/(3*GAMMA(k-0.5)*(2*k-3)**(3/2)),
                          A3:= (4*k**2-1)/(2*(2*k-3)**2),
                          M1:= 0.1+sqrt(T+(1/A1)),
                        #
                        # define ODES and ICs
                        #
                          odes:= [ diff(U1(x),x)=-diff(phi(x),x)/(U1(x)-T/U1(x)),
                                   diff(phi(x),x$2)=(1+A1*phi(x)+A2*phi(x)**(3/2)+A3*phi(x)**2)-(M1/U1(x))
                                 ],
                          bcs:= [ U1(0)=M1, phi(0)=0, D(phi)(0)=0.001],
                        #
                        # Solution and plots
                        #
                          sol:= dsolve( [odes[], bcs[]], numeric):
                    return plots:-odeplot( sol,
                                           [ [x, U1(x)],
                                             [x, phi(x)],
                                             [x, diff(phi(x),x)]
                                           ],
                                           x=0..20,
                                           color= [red, blue, green]
                                         );
               end proc:
#
# Now plot all sorts of combinations - after all who
# knows what the OP wants/needs
#
  plots:-display( [seq( getODESol( j, 0.6, 3.5), j=0.1..0.5,0.1)]);
  plots:-display( [seq( getODESol( 0.1, j, 3.5), j=0.3..1.0,0.1)]);
  plots:-display( [seq( getODESol( 0.1, 0.6, j), j=3..4,0.1)]);
#
# This one gernartes some singularity warnings which
# I haven't bothered to nail down - and I won't until
# the OP provides details of which combinations of
# parameters (s)he is interested in
#
  plots:-display( [ seq
                    ( seq
                      ( seq
                        ( getODESol( i, j, k),
                          i=0.5..0.7, 0.1
                        ),
                        j=0.5..0.7, 0.1
                      ),
                      k=3.4..3.6, 0.1
                    )
                   ]
                  );

 

 

 

Warning, cannot evaluate the solution further right of 19.820552, probably a singularity

 

Warning, cannot evaluate the solution further right of 19.926938, probably a singularity

 

Warning, cannot evaluate the solution further right of 19.494114, probably a singularity

 

Warning, cannot evaluate the solution further right of 19.785144, probably a singularity

 

 

 

 


 

Download dbg.mw

@michalkvasnicka 

And follow the instructions given by  Edgardo S. Cheb-Terrab then you, like me, will probably(?) obtain a functional installation. Certainly worked for me.!

@Reshu Gupta 

when it it perfectly obvious from the original worksheet I posted that the my code does run!

What you mean is that you took some perfectly functional, serviceable code and "hacked" it for your own reasons - and your incompetently "hacked" code doesn't run

Now before we go any further - don't edit my code, don't touch my code. The only thing you are allowed to do is

  1. download it to your Maple installation
  2. execute it by toggling the !!! icon in the toolbar

And if you are really interested in why your incompetently hacked code doesn't run, you might contemplate why (in my original) I wrote

dsolve
( [ eval
   ( coeff(HPMEq, p, i) = 0,
     sol
   ),
   f[i](0) = 0,
   D(f[i])(0) = 0,
   D(f[i])(5) = 1
 ]
)

And in your incompetenly hacked version this becomes

sol:=[sol[],dsolve([eval(coeff(HPMEq,p,i)=0,sol), F[i](0)=0, D(F[i])(0)=0, D(F[i])(5)=1])]

Now precisely why did you decide to use an uppercase 'F' in the boundary conditions? I mean why?

I have colour-highlighted the discrepancy in the above code snippets, just so that even you can't miss the difference

@mary120 

  1. My code runs with no error messages - now this may be a version issue, but to examine this, I'd have to know which Maple version you are running. Insert the command "interface(version);" at the top of your worksheet so I can figure out which version is causing a problem
  2. I deliberateyl produced a matrix (called 'res' in my original worksheet).  You can use the command ExportMatrix( filename, res, option) to "export" this matrix to any filename you specify as 'filename', and in a variety of formats. See the help at ?ExportMatrix()
  3. As I said in my original response, I cannot come up with any combination of parameters, for which the condition U1(x)>20 would ever be triggered - so I chose to ignore it then, and I am ignoring it now. If you want to come up with a condition can realistically be triggerd then please post it, and I will consider how to dela with it.

@mary120 

The extra execution groups I have added in the attached will solve your bullet items (1) and (2).

Since I cannot vome up with any combination of parameters where U1(x)>20, I have ignored the third item in your request. Convince me I have to deal with this!

  restart;
#
# Assorted parameters
#
  T:= 0.1: beta:= 0.6: k:= 3.5:
  A1:= (2*k-1)/(2*k-3):
  A2:= 8*sqrt(2/Pi)*(beta-1)*k*GAMMA(k)/(3*GAMMA(k-0.5)*(2*k-3)**(3/2)):
  A3:= (4*k**2-1)/(2*(2*k-3)**2):
  M1:= 0.1+sqrt(T+(1/A1)):
#
# define ODES and ICs
#
  odes:= diff(U1(x),x)=-diff(phi(x),x)/(U1(x)-T/U1(x)),
         diff(phi(x),x$2)=(1+A1*phi(x)+A2*phi(x)**(3/2)+A3*phi(x)**2)-(M1/U1(x)):
  bcs:= U1(0)=M1, phi(0)=0, D(phi)(0)=0.001:
#
# Solution and plots
#
  sol:= dsolve( [odes, bcs], numeric):
  plots:-odeplot( sol,
                  [ [x, U1(x)],
                    [x, phi(x)],
                    [x, diff(phi(x),x)]
                  ],
                  x=0..20,
                  color= [red ,blue, green]
                );

 

#
# Generate the values of x and U1(x) for
# x=0..20 in unit steps
#
  interface(rtablesize=25):
  res:= Matrix( [ [ x, U1(x)],
                  seq( rhs~(sol(j)[1..2]), j=0..20)
                ]
              );
  interface(rtablesize=10):
#
# Now you could use Maple's export() command
# to output the Matrix 'res' in any number of
# different formats - dependin on which format
# the target application understands
#
# But why bother?
#
# After what kind of data processing is available
# is available in the target application, which
# isn't available in Maple?
#
# If I had to guess-the answer would be none at all
#

Matrix(22, 2, {(1, 1) = x, (1, 2) = U1(x), (2, 1) = 0., (2, 2) = .9755950358000001, (3, 1) = 1., (3, 2) = .9743882497663228, (4, 1) = 2., (4, 2) = .9728034547315375, (5, 1) = 3., (5, 2) = .9703760334309917, (6, 1) = 4., (6, 2) = .9664384148229473, (7, 1) = 5., (7, 2) = .9599917848367329, (8, 1) = 6., (8, 2) = .9495782659844485, (9, 1) = 7., (9, 2) = .9332339071718317, (10, 1) = 8., (10, 2) = .9087622596621625, (11, 1) = 9., (11, 2) = .8749258310975149, (12, 1) = 10., (12, 2) = .8346454900793634, (13, 1) = 11., (13, 2) = .8000941860549555, (14, 1) = 12., (14, 2) = .7909560310972703, (15, 1) = 13., (15, 2) = .8140334852323781, (16, 1) = 14., (16, 2) = .8534606682576422, (17, 1) = 15., (17, 2) = .8916142947142357, (18, 1) = 16., (18, 2) = .9211499119040738, (19, 1) = 17., (19, 2) = .941628092024671, (20, 1) = 18., (20, 2) = .9549739687946793, (21, 1) = 19., (21, 2) = .9633495717614502, (22, 1) = 20., (22, 2) = .9684924240995624})

(1)

  restart;
#
# Convert the whole of the above to a procedure
# will accept any values of T, beta, k amd return
# the desired plot
#
  getODESol:= proc( T, beta, k)
                    local A1:= (2*k-1)/(2*k-3),
                          A2:= 8*sqrt(2/Pi)*(beta-1)*k*GAMMA(k)/(3*GAMMA(k-0.5)*(2*k-3)**(3/2)),
                          A3:= (4*k**2-1)/(2*(2*k-3)**2),
                          M1:= 0.1+sqrt(T+(1/A1)),
                        #
                        # define ODES and ICs
                        #
                          odes:= [ diff(U1(x),x)=-diff(phi(x),x)/(U1(x)-T/U1(x)),
                                   diff(phi(x),x$2)=(1+A1*phi(x)+A2*phi(x)**(3/2)+A3*phi(x)**2)-(M1/U1(x))
                                 ],
                          bcs:= [ U1(0)=M1, phi(0)=0, D(phi)(0)=0.001],
                        #
                        # Solution and plots
                        #
                          sol:= dsolve( [odes[], bcs[]], numeric):
                    return plots:-odeplot( sol,
                                           [ [x, U1(x)],
                                             [x, phi(x)],
                                             [x, diff(phi(x),x)]
                                           ],
                                           x=0..20,
                                           color= [red, blue, green]
                                         );
               end proc:
#
# Now plot all sorts of combinations - after all who
# knows what the OP wants/needs
#
  plots:-display( [seq( getODESol( j, 0.6, 3.5), j=0.1..0.5,0.1)]);
  plots:-display( [seq( getODESol( 0.1, j, 3.5), j=0.3..1.0,0.1)]);
  plots:-display( [seq( getODESol( 0.1, 0.6, j), j=3..4,0.1)]);
#
# This one gernartes some singularity warnings which
# I haven't bothered to nail down - and I won't until
# the OP provides details of which combinations of
# parameters (s)he is interested in
#
  plots:-display( [ seq
                    ( seq
                      ( seq
                        ( getODESol( i, j, k),
                          i=0.5..0.7, 0.1
                        ),
                        j=0.5..0.7, 0.1
                      ),
                      k=3.4..3.6, 0.1
                    )
                   ]
                  );

 

 

 

Warning, cannot evaluate the solution further right of 19.820552, probably a singularity

 

Warning, cannot evaluate the solution further right of 19.926938, probably a singularity

 

Warning, cannot evaluate the solution further right of 19.494114, probably a singularity

 

Warning, cannot evaluate the solution further right of 19.785144, probably a singularity

 

 

 

 

Download odeSol2.mw

@janhardo 

and this site probably(?) isn't the place to receive tuition on basic Maple coding/syntax, but I'm preoare to try

  1. the expression 'f' is passed to the procedure. Now you may pass x^2+2*x+1 or t^2+2*t+1 or  zzzz^2+2*zzzz+1 - what diifference does it make, since all of these expressions are essentially the same? The only difference it makes is that for the purposes of subsequent computation, it is convenient to know what the 'name' of the independent variable is. So the sub-expression I have used, ie indets(f, 'name')[] will return 'x' if 'f' is x^2+2*x+1, or 't' if 'f' is t^2+2*t+1, or zzzz if 'f' is zzzz^2+2*zzzz+1.
  2. Since (1) above will return the 'name' of the independent variable, the command unapply( f, name_Of_The_Independent_Variable) will convert the expression x^2+2*x+1 to the function x->x^2+2*x+1, or t^2+2*t+1 to the function t->t^2+2*t+1, or zzzz^2+2*zzzz+1 to the function zzzz->zzzz^2+2*zzzz+1. In other words one now has a simple function definition.
  3. Since (2) above will generate a function which might be written as arg->someFunctionOfarg, then this can be applied to any supplied argument, by writing, for example, (arg->someFunctionOfarg)(2) - think of this as defining a function 'f' and then evaluating f(2). Since we have multiple values of the independent variable (ie everything in the Array xv in the original example), one can apply this function to every element in the Array 'xv' by using the elementwise operator '~' - so the command (arg->someFunctionOfarg)~(xv) will apply the required function to every element of the container xv.
  4. So the command yv:=unapply( f, indets(f, 'name')[])~(xv) basically means
    1. figure out the name of the idependent variable in the expression 'f'
    2. Using 'f' and the name of its independent variable, convert these to an appliable function
    3. Apply this function to every element in the container 'xv'

@jestrup 

but that oculd be becuase in all th etime I have been using Maple I have never used the "Numeric Formatting Window".

Assuming that you bought a "Swedish" version of Maple and/or specified Swedish as the language during installation, I'm slightly surprised that 'kr' or some appropriate symbol does not appear in the currency list.

Since I'm British - I get a choice of $, £, €, and #

@Carl Love 

In my original response I was trying to make two points (and I obviously did it badly), which are that the resukts of any kind of pattern matching depend on two different things

  1. the precise way the expression-to-match is written
  2. the precise way the pattern-to-match is defined

Slight variations in either can produce very different results and I'm not sure that your code resolves these issues. Consider the attached: all of the answer are "correct", but what would the OP have expected?

I'd bet on the last one - but I'm quite happy to admit that this might be completely incorrect - in which case we go back to the issues in the above bullet points

  restart;
  SplitProduct:= (e::algebraic, t::name)-> local `1`;
                                           eval([selectremove](depends, `1`*e, t), `1`= 1)[]:

  expr:=(a+b)*(t^2+y):


 

  SplitProduct(expr,t);
  SplitProduct(expand(expr),t);
  SplitProduct(collect(expand(expr),t),t);

t^2+y, a+b

 

a*t^2+b*t^2+a*y+b*y, 1

 

(a+b)*t^2+a*y+b*y, 1

(1)

  patmatch( expr,
            P::nonunit(freeof(t))*Q::dependent(t)+R::freeof(t),
            'p'
          ):
  p;
  patmatch( expand(expr),
            P::nonunit(freeof(t))*Q::dependent(t)+R::freeof(t),
            'p'
          ):
  p;
  patmatch( collect(expand(expr),t),
            P::nonunit(freeof(t))*Q::dependent(t)+R::freeof(t),
            'p'
          ):
  p;

[P = a+b, Q = t^2+y, R = 0]

 

[P = a+b, Q = t^2+y, R = 0]

 

[P = a+b, Q = t^2, R = a*y+b*y]

(2)

 

Download patmat3.mw

 

@acer 

I was trying to make clear that the results of  patmatch() were highly dependent on the precise "form" in which the initial expression was supplied. And that the original expression might have to "massaged" in a particular way to "fit" the patmatch() - or alternaively the matching template with the  patmatch() might have to be extended/generalised in an appropriate manner

@Scot Gould 

The worksheet I posted was writtten using Maple 2020.1

When this worksheet is executed within Maple, there are no "double brackets" on the units

The "double brackets" only occur when the worksheet is "rendered" on this site

I can only assume that whatever controls the "rendering" on this website is running a little behind what Maple worksheets actually display - so download my worksheet, re-execute and see the "double brackets" disappear

@acer 

So dependent on the precise form in which the original expression is given. A simple expand() around each of the examples provided changes the answer for  three outseven examples :-(

See the attached

restart;

F := proc(ee::algebraic, nm::name)
       local s,o;
       if not ee::`*` then return false; end if;
       (s,o) := selectremove(depends,[op(ee)],nm);
       if nops(s)=0 or nops(o)=0 then false;
       else true; end if;
end proc:

F( expand((a+b)*(t^2+y)), t );

false

(1)

F( expand((a+b)*(t^2+y)*t^5), t );

false

(2)

F( expand((t^2+y)*t^5), t );

false

(3)

F( expand((a+b)*c*(t^2+y)*t^5), t );

false

(4)

F( expand(3*t),t );

true

(5)

F( expand(a*b*c), t );

false

(6)

F( expand(a+b+c), t );

false

(7)

 


 

Download starchk2.mw

@ecterrab 

When I first had problems - I tried the route of atarting Maple with "administrator" rights. That's pretty much equivalent to "root" on a unix system - so unconditional privilege to write anything, anywhere. This still failed with the mserver.exe crash.

The only thng I have ascertained is that after very attempted installation, the "default" installation directory was missing a level in the hierarchy, because the directory

C:\Users\TomLeslie\maple\toolbox

was of the following structure

2018
           Physics Uodates
                                      lib
                                      uninstall_manifest.mtxt
                                      version.txt
2019
           Physics Uodates
                                      lib
                                      uninstall_manifest.mtxt
                                      version.txt
Physics Uodates
                           version.txt

So it sort of seems that the 2020.1 installation omitted the folder level 2020 in the hierarchy. Is this significant? I don't know!

But when (following your advice) I manually fixed this to include a 2020 "folder" along with required contents, everything works.

So I'd have to ask - why does the PhysicsUpdates installer for Maple 2020 not install it in a directory called 2020 - like all previous installations? Is this significant? Is it the source/cause of the problem?               
                      


 

 

 

@Fancypants 

So much so that I have trouble figuring out what you intend - so the followinbg is a couple of things I "suspect" that you are probably(?) getting wrong

The difference between assignments and equations.

Just because you enter an equation in Maple and subsequently use the left-hand side of this equation in a subsequent expression/equation/assignment, the former will not be automatically substitued into the latter. Now obviously this is quite a common mathematical operation, so there are many ways within Maple to perform such a substitution/evaluation - but they aren't going to happen by "magic"!

 

Inert and non-inert superscripts and subscripts.

There is a significant conceptual difference between entering (say) x[1] and x__1. Both of these will be "prettyprinted" in Maple output as x1 However the first (ie x[1]) of these represents the first entry in an indexable quantity 'x' - ie 'x' is a vector/list/set whatever and wish to use its first entry. The second (ie x__1) is an "inert" subscript, there is no suggestion of "indexing".

The situation is rather simpler for superscripts - as far as you are concerned, Maple does not use inert superscripts (It may be possible in the Physics package - but that is Maple at whole new level, and trust me you are not using it!), Superscripts are used for the mathematical function of exponentiation

As an illustration, your worksheet contains the quantity S1y but the way you have entered this means that Maple considers it to be the first entry in the indexable quantity S, raised to the power of the (variable) 'y'. I'm guessing that it not what you intended.

 

There are other problems - but most of your issues are related to the desire to use over-complicated(?) typography, so my advice would be not to use the latter, until you really (really!) understand what you are doing

 

 

 

 

First 47 48 49 50 51 52 53 Last Page 49 of 207