acer

32328 Reputation

29 Badges

19 years, 317 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

Another way to accomplish this is to construct them as names (entities).

This has an added benefit that they display directly in the Maple GUI without doublequotes when using regular print. As shown below, they also work with printf.

There are two choices for lowercase sigma. I have chosen the lowercase sigma σ, that is more often used in mathematics, rather than the lowercase sigma ς for word-final position.

restart;

Greek_uppers:=["Alpha","Beta","Gamma","Delta","Epsilon","Zeta","Eta", 
               "Theta","Iota","Kappa","Lambda","Mu","Nu","Xi","Omicron",
               "Pi","Rho","Sigma","Tau","Upsilon","Phi","Chi","Psi","Omega"]:
Greek_lowers:=map(StringTools:-LowerCase,Greek_uppers):
Greek:=table([seq(Greek_uppers[i]=nprintf(`&#%ld;`,912+i),i=1..17),
               seq(Greek_uppers[i]=nprintf(`&#%ld;`,912+i+1),i=18..24),
               seq(Greek_lowers[i]=nprintf(`&#%ld;`,944+i),i=1..17),
               seq(Greek_lowers[i]=nprintf(`&#%ld;`,944+i+1),i=18..24)]):

seq(printf(" %s  %s   %s\n", Greek[g], Greek[StringTools:-LowerCase(g)], g),g=Greek_uppers);
 Α  α   Alpha
 Β  β   Beta
 Γ  γ   Gamma
 Δ  δ   Delta
 Ε  ε   Epsilon
 Ζ  ζ   Zeta
 Η  η   Eta
 Θ  θ   Theta
 Ι  ι   Iota
 Κ  κ   Kappa
 Λ  λ   Lambda
 Μ  μ   Mu
 Ν  ν   Nu
 Ξ  ξ   Xi
 Ο  ο   Omicron
 Π  π   Pi
 Ρ  ρ   Rho
 Σ  σ   Sigma
 Τ  τ   Tau
 Υ  υ   Upsilon
 Φ  φ   Phi
 Χ  χ   Chi
 Ψ  ψ   Psi
 Ω  ω   Omega

note. I course, you can also easily convert the strings that Carl constructed into names, eg, convert(...,name) , etc.

[edit] Also, the methodology that Carl used, with the StringTools:-Char command, will also work in the plaintext console-driven Maple Command-Line Interface (CLI) and not just the Maple GUI.

For fun, see also this old Question.

You could look at the Help page for the unassign command.

It doesn't appear that Ag2O is one of the chemical names recognized by the ThermophysicalData package in current Maple.

Also, programmatically,

map(proc(s) `if`(StringTools:-Search("Ag",s)>0,s,NULL); end proc,
    ThermophysicalData:-Chemicals:-GetSpecies());

        ["Ag(g)", "Ag+(g)", "Ag-(g)", "Ag(cr)", "Ag(l)"]

The reference seems to be this:
McBride, Bonnie J.; Zehe, Michael J.; and Gordon, Sanford. NASA Glenn Coefficients
for Calculating Thermodynamic Properties of Individual Species; 2002

Why not try the factor command, to attempt to factor out a term of a common power?

expr := y^2+y^3*sin(x)+3*x*y^5;

                         2    3               5
                expr := y  + y  sin(x) + 3 x y 

aa := factor(expr);

                       2 /     3               \
                aa := y  \3 x y  + sin(x) y + 1/

For this example the factored form is not "smaller" by the metrics used by simplify. But you can avoid that with an option:

simplify(expr, size=false);

                    2 /     3               \
                   y  \3 x y  + sin(x) y + 1/

Fwiw, using these metrics,

H := ee->[`simplify/size/size`(ee),
          MmaTranslator:-Mma:-LeafCount(ee),length(ee)]:

H(expr), H(aa);

          [48, 16, 41], [48, 16, 45]

[edit] You can also use factor with frontend. That works for the example involving rational powers (radicals) you added in an edit to your Question (one of two ways which handle that example, which I showed in my Reply to that new information first presented under mmcdara's Answer).

You've stated a goal of factoring. So useful commands can include:

factor(...)
evala(Normal(...))
frontend(factor,...)
simplify(..., size=false)
simplify(...)
evala(Factor(...))

depending on your (as yet unstated) goal requirements, restrictions, and problem class.

Add the explicit option to your call to the solve command, if you want roots in terms of explicit radicals instead of implicit RootOf.

help_ac.mw

You could also read the Help page for topic solve,details.

You could use an overlay of lines and point-plots, and legends, to illustrate the close curves.

The final call to plots:-display uses them in a particular order, so that they are laid over each other in a particular order.

restart:
f1:=x->0.95*x:
f2:=x->0.99*x:
f3:=x->0.991*x:
# adjust these, to taste
N:=10: ptsize:=8: th:=1:
(a,b) := 0,2:
p1:=plot(f1(x),x=a..b,color=red,thickness=th,legend=f1(x)):
p1a:=plot(f1(x),x=a..b,color=red,
          style=point,symbol=solidcircle,symbolsize=ptsize,
          adaptive=false,numpoints=N+1):
p2:=plot(f2(x),x=a..b,color=blue,thickness=th,legend=f2(x)):
p2f:=plot(f2(x),x=a..b,color=blue,thickness=th+2):
p2a:=plot(f2(x),x=a+(b-a)/(N*2)..b-(b-a)/(N*2),color=blue,
          style=point,symbol=solidcircle,symbolsize=ptsize,
          adaptive=false,numpoints=N):
p3:=plot(f3(x),x=a..b,color=green,thickness=th,legend=f3(x)):
p3a:=plot(f3(x),x=a..b,color=green,
          style=point,symbol=solidcircle,symbolsize=ptsize,
          adaptive=false,numpoints=N+1):
plots:-display(p1,p2,p2f,p3,p3a,p2a,p1a);

plots_close.mw

Another way is to overlay with a duplicate having different linestyle.

restart:
f1:=x->0.95*x:
f2:=x->0.99*x:
f3:=x->0.991*x:
(a,b) := 0,2:
p1:=plot(f1(x),x=a..b,color=red,legend=f1(x)):
p2:=plot(f2(x),x=a..b,color=blue,legend=f2(x)):
p2a:=plot(f2(x),x=a..b,color=blue,linestyle=dash):
p3:=plot(f3(x),x=a..b,color=green,legend=f3(x)):
plots:-display(p1,p2,p3,p2a);

From the Help page for topic I,

"

I is implemented as Complex(1), and therefore, unlike many other Maple constants, type(I, name) returns false."

It is not a protected name, because it is not implemented to evaluate as a name.

That distinguishes it from other initially known names and constants.

dismantle(I);

COMPLEX(2)
   INTPOS(2): 1

type(I, name);

             false

Complex(1);

               I

dismantle(Pi);

NAME(4): Pi #[protected]

Pi;                                                                                
               Pi

[edit] Also,

op(0,I), [op(I)];

           Complex, [1]

It is like that by design. From one point of view this is beneficial because it allows you to construct an exploration for which you can subsequently redefine variables or assigned names.

If you upload and attach your worksheet then we may be able to show you more than one way to work with the design, so that your example works more as you want.

You mentioned "variables", which could mean parameters (in the Explore sense) or additional variables with assigned values. An explicit example from you would make you meaning more clear. Explore parameters have to be unassigned global names -- but even for them it is often possible to programmatically work around some issues.

In one sense this is part of a broader Maple worksheet subject: execution of previous parts can be re-executed out-of-order, and if that is the intention then the burden is on the user to set up examples which guard against collision in the namespace. [edit. I see that Carl made this same point, while I was typing.]

I have not yet pinpointed the precise cause of the problem.

But here is something quick, in my Maple 2020.1.

restart;

(-1)^v*(alpha*GAMMA(k-v)/v!/GAMMA(k-2*v-1)/GAMMA(k-2*v))^(1/2)
*exp(-1/2*k*exp(-alpha*x))*(k*exp(-alpha*x))^(1/2*k-v-1/2)
*LaguerreL(v,k-2*v-1,k/exp(alpha*x))/binomial(k-v-1,v):

CodeTools:-Usage(
  seq((evalf[15](Int(unapply(simplify(eval(%, [k=30.5, v=j, alpha=2.5]))^2, x),
                     -1..infinity))), j=0..5) );

memory used=27.47MiB, alloc change=34.00MiB, cpu time=260.00ms, real time=261.00ms, gc time=24.22ms

     0.999999999999992, 0.999999999999994, 1.00000000000001,
     1.00000000000001, 1.00000000000001, 0.999999999999959

Here is a way to substitute names c[i] for the _Cn constants, which also forces the reordering so that specified names c[i] are first in the product subterms. It uses subs for the substitution, as opposed to alias.

This uses sort, and can forcibly correct the example even when the "uniquified" expression (stored by the kernel as the sole representation) has been inadvertantly reordered in a manner contrary to your goal.

sorting_fun.mw

Unfortunately inlining of uploaded worksheets is currently broken on Mapleprimes.

It also finds the _Cn names as they appear, alleviating need to hard code a fixed number of replacements up front. (Other Answers hard-coded 10 substitutions.)

If you come across an example which it cannot handle directly then the procedure could be adjusted accordingly.

Some of the other suggestions (in other Answers) are not always assured to produce the desired ordering of the terms, eg. in cases where the misordered expression have previously existed in the session. So the ability to force the ordering seems useful.

The vertical view is negative, ie. the squares are placed with position at negative y-values. That why you don't see your y-tickmarks, which you've created to be placed at positive vertical postions. They are out of viewing range.

You can adjust this, naturally.

restart;

M := LinearAlgebra:-RandomMatrix(20,density=0.25,generator=0 .. 1):

plots:-sparsematrixplot(
   M, matrixview
  ,axis[1]=[tickmarks=[seq(i=i-1, i in [seq](1..20, 5))]]
  ,axis[2]=[tickmarks=[seq(-j=j-1, j in [seq](1..20, 5))]]
);

 

Download sparsematrixplot_yticks.mw

If you are allowed to let Maple do all the work, then you could get by with something short, eg.

is( sin(2*x) = 2*sin(x)*cos(x) );

           true

simplify( sin(2*x) - 2*sin(x)*cos(x) );

             0

Let's suppose that you don't want the work to be hidden in calls to combine and expand or other powerful simplification commands, but that you do know and are allowed to use the sum rule for sin(A+B). Then you can get by with only making various kinds of substitutions.

restart;

This identity you should know, sometimes called a sum rule.

rule := sin(x + y) = sin(x)*cos(y) + cos(x)*sin(y);

sin(x+y) = sin(x)*cos(y)+cos(x)*sin(y)

expr := sin(2*x);

sin(2*x)

Turn one of the two x's into y.

eval( expr, x = (x+y)/2 );

sin(x+y)

applyrule( rule, % );

sin(x)*cos(y)+cos(x)*sin(y)

Turn y back into x.

eval( %, y = x );

2*sin(x)*cos(x)


Now the other direction, for fun...

Here we'll use the reverse of the rule.

revrule := (rhs = lhs)(rule)

sin(x)*cos(y)+cos(x)*sin(y) = sin(x+y)

expr := 2*sin(x)*cos(x);

2*sin(x)*cos(x)

Change some of the x's into y's.
Take half of expr and change one of the x's into y.
Take the other half of expr and change another of the x's into y.

eval( expr/2, cos(x)=cos(y) ) + eval( expr/2, sin(x)=sin(y) );

sin(x)*cos(y)+cos(x)*sin(y)

Use the reverse of the given sum rule.

applyrule( revrule, % );

sin(x+y)

Turn y back into x.

eval( %, y = x );

sin(2*x)

Download double_angle_sine.mw

Your expression assigned to A is a product of terms.

I believe that the only one of those multiplicative terms which attains zero for real-valued lambda (if evaluated at adequate working precision to avoid spurious roots due to numeric roundoff error) is this one. This behaves well even at default Digits=10.

restart;
p:=-.1141301418e17*lambda^9+.9737052862e16*lambda^8
   -.3682582968e16*lambda^7+.8102838405e15*lambda^6
   -.1142983789e15*lambda^5+.1071802621e14*lambda^4
   -.6680654662e12*lambda^3+.2668788927e11*lambda^2
   -619949976.6*lambda+6379681.930:

fsolve(p);
           0.07016568203, 0.07350618818, 0.1121166384

You can also achieve those with the following, using your A, even at default Digits=10,

Digits := 10;
sols := [fsolve(numer(A), lambda = -0.1 .. 1, maxsols = 4)];

  sols := [0.07016568203, 0.07350618818, 0.1121166384]

You can use higher working precision to show accurately the residual errors.

forget(evalf);
seq(evalf[max(20, Digits)](A), lambda = sols);

                            -9                           -8  
   -7.4318703347473954061 10  , -1.2463236113255786800 10  , 

                             -8
     3.8410294096271317263 10  

I get the following, in Maple 2019.0 or Maple 2019.2.

restart;
kernelopts(version);

   Maple 2019.2, X86 64 LINUX, Oct 30 2019, Build ID 1430966

assume(x, 'real'); assume(y, 'real');
verify(x^2 + y^2, 0, {'greater_equal'});

                    true

restart;
verify(x^2 + y^2, 0, {'greater_equal'}) assuming x::real, y::real;

                    true

T__e_np := sqrt(r^2+1)/(r^2+sqrt(r^2+1)*r+1);

(r^2+1)^(1/2)/(r^2+(r^2+1)^(1/2)*r+1)

evala(T__e_np);

(r^2+1)^(1/2)-r

1/evala(1/T__e_np);

1/((r^2+1)^(1/2)+r)

Download simp_ex_2.mw

There is also this (but it's easier to let evala figure it out.

factor(T__e_np, sqrt(r^2 + 1));
1/factor(1/T__e_np, sqrt(r^2 + 1));
First 98 99 100 101 102 103 104 Last Page 100 of 336