Carl Love

## 26837 Reputation

11 years, 298 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

## "Remember plot attributes when re-execut...

From the menus, go to Tools => Options => Interface and check the box "Remember plot attributes when re-executing", then click Apply Globally.

## C||(1..numelems(V)):= seq(V);...

You can use

C||(1..numelems(V)):= seq(V);

Edit: Thanks to @nm for noticing that I'd erroneously used nops instead of numelems.

## Numerical solution of BVP eigenvalue pro...

Maple's numerical ODE solver can solve BVP eigenvalue problems. It will give a solution, if it can find one. It doesn't guarantee uniqueness or minimality.

 > restart :
 > #Declare convenient variable abbreviations for the unknown functions (F) and eigenvalues (E): F:= psi__||(1,2); E:= ;

 > # %-signs are used to make an operation inert, which is only used here so that the displayed # formulae help to elucidate the exposition, # Non-equations are implicitly equated to 0. %BVP:=     %seq(         diff~(, x\$2) %+         () %. E     ),     F(0)=~ 1, F(1), D~([F])(0)[] ;

 > BVP:= value({%BVP});  #The value command removes inertness.

 > ; #just for neat columnar display

 > dsol:= dsolve(BVP, numeric):
 > dsol(0);  #Any number in interval 0..1 can be used.

 > EV:= E=~ eval(E, dsol(0.5));  #Get just the eigenvalues.

 > plots:-odeplot(     dsol, `[]`~(x, [F](x)), legend= [F], gridlines= false,     caption= typeset("\nThe eigenvalues are ", evalf[4](EV)) );

## Reverse order of nested adds...

You have nested add commands of the form

You have the nesting order completely backwards. They should be

## plot with useunits...

The regular plot command can be used for this. You just need to group the X and Y into a single argument:

plot(<X1 | Y>, style= point, symbolsize= 15, useunits= Unit~(['m', 1]));

## Simple Maple code...

Your only have 1 equation (Eq 21), so it can only be solved for 1 variable at a time. Your stated "solutions" have solutions for 4 variables: omegaPsikappa__0, and h__1. If we take 3 of these as "given", we can easily solve for the 4th. In the worksheet below, I solve for omega.

 > restart:
 > Eq21:=     12*Psi^3*rho__3^2*D[1,1](w)(phi) +     (4*omega*rho__3^2 - 3*rho__2^2*Psi)*w(phi) +     Psi*rho__3^2*(rho__1 + 2*rho__3)*w(phi)^3 ;

 > w:= phi-> kappa__0 + kappa__1*(D(Xi)/Xi)(phi) + h__1*(Xi/D(Xi))(phi);

 > Xi:= phi-> (1+exp(phi))/exp(-2*phi);

 > Eq21a:= eval(  #Use given solutions for h__1, kappa__0, and Psi.     Eq21,     [         h__1= 0,         kappa__0= -5/2*kappa__1,         Psi= kappa__1/12*sqrt(-6*rho__1 - 12*rho__3)     ] );

 > solve({Eq21a}, {omega});

 >

## Extracting the odd part...

If 2 is the only base for which you want to do this, and you don't actually need the prime factorization of the remaining odd part, then there's a much faster way to do this. I mention this because factoring out the highest-possible power of 2 is a very common preliminary step in number-theory algorithms; so I'm guessing that that may be your goal. Here's how:

```OddPart:= (n::posint, x::algebraic)->
(k-> x^k*integerdivq2exp(n,k))(Bits:-FirstNonzeroBit(n, 'higher'))
:
#Random test case:
(p1,p2):= nextprime~(['rand(2^64..2^65)()'\$2])[];
p1, p2 := 24421176063119381659, 21314142271437361117
N:= 2^rand(9..99)()*p1*p2;
N := 266504407575115289384393504182133531188736

CodeTools:-Usage( ifactor(N) );
memory used=14.24MiB, alloc change=0 bytes,
cpu time=172.00ms, real time=175.00ms, gc time=0ns

9
(2)  (21314142271437361117) (24421176063119381659)

CodeTools:-Usage( OddPart(N,x) );
memory used=1.49KiB, alloc change=0 bytes,
cpu time=0ns, real time=0ns, gc time=0ns

9
520516421045147049578893562855729553103 x

```

## pde2 is not an equation, don't use lhs...

Your pde2 is not explicitly an equation because it doesn't consist of two expressions separated by =. Thus, it has neither a left side nor a right side. Thus, the command lhs (which stands for left-hand side) can't be used. This error is purely due to syntax, not math. If you intend pde2 to represent an expression implicitly equated to 0 (which is a very common and totally acceptable thing to do), then simply proceed with normal(pde2) instead of normal(lhs(pde2)), and your entire worksheet completes without error.

Regarding your tanh question: Did you intend that question to be in connection to the error? If so, the error has nothing to do with math. If you intended the tanh question to be independent of the error, I can attempt to answer it.

## simplify with side relations...

The simplify with side relations (see ?simplify,siderels) command can do it:

simplify(x^2+y^2, {x-y, y+a}, [x,y]);

## unprotect(_Z); `tools/genglobal`(_Z, 0, ...

The command to clear the counter on an automatically generated global variable such as _Z1 is `tools/genglobal`. Before each solve command, including the first, do

unprotect(_Z); `tools/genglobal`(_Z, 0, 'clear'):

However, it would be a better programming practice to "improve the program" in the manner @acer suggests. One reason that this is more robust is that if you and other people are developing the same code, they might not be aware that you've reset the counter.

`tools/genglobal` is undocumented. I figured out how to use it by reading its code via

showstat(`tools/genglobal`);

## p < 2%...

The following simulation, sampling over 2 million random drawings, shows that the probability that a random drawing would have no intra-family pairings is less than 2%:

```Fams:= [{\$1..3}, {\$4..7}, {\$8..11}, {\$12..15}, {16}]:
ValidDraw?:= (M::list(integer[1..16]))->
andmap(f-> f intersect {M[[f[]]][]} = {}, Fams)
:
V:= [
to 2^21 do
M:= combinat:-randperm(16);
if ValidDraw?(M) then M fi
od
]:
nops(V);
37276
evalf(%/2^21);
0.01777458191```

Using formal Statistics language, the p-value is less than 2%.

A well-known formula for combinatorial derangement says that the probability that no person is paired with themself is very close to exp(-1) ~ 36.8%. The exact value is  15549624751/42268262400, which equals exp(-1) to 14 decimal places.

## Allowed since Maple 2019...

Despite what @nm and @igor.v.proskurin said, what you want to do has been allowed since Maple 2019. It looks like you're using an older version, Maple 2018. Now, local declarations are allowed in a large number of positions within a procedure. I guess that that Programming Guide entry needs to be updated.

## D to differentiate procedures...

You should use D to define g, like this:

g:= D(f);

The problem with your g:= x-> diff(f(x), x) is that g(1) evaluates to diff(2, 1), which is nonsense because 1 isn't a variable.

## rsolve(..., makeproc)...

Your reqn has two solutions for f(n+1), and each of them specifies a different recurrence:

psol:= solve({f(n+1)=f(n)+sqrt(2*f(n+1)-f(n))}, {f(n+1)});

I don't think that there's any hope of a symbolic solution for either of these (and the rsolves return unevaluated), but you may be able to make a numeric asymptotic analysis. In the following command, note that I've specified the initial condition as 15., with a decimal point, to force floating-point evaluations. If you don't do this, the expressions become extremely large with deeply nested square roots very fast.

F:= rsolve({psol[1], f(1)=15.}, f(n), makeproc);

Now you can explore, for example,

seq(F(k), k= 1..99);

If I used psol[2] instead, the solution rapidly decays to 0.

## RootedVector, PlotVector...

Using package VectorCalculus, I'd do it with the commands RootedVector and PlotVector (definitely not PlotPositionVector). For example, we're given the following initial tail point, base, and vectors u and v:

base:= [1,1,1]:  u:= <1,2,3>:  v:= <4,5,6>:

We want to represent the vector sum u + v head-to-tail in that order:

VC:= VectorCalculus:
VC:-PlotVector([VC:-RootedVector(root= base, u), VC:-RootedVector(root= base+~u, v)]);

There are numerous options to PlotVector to control the size, color, shape, etc., of the vectors; see its help page.

The same process works just as well for a 2D plot if all vectors and points have 2 components.

 First 6 7 8 9 10 11 12 Last Page 8 of 386
﻿