Carl Love

Carl Love

26109 Reputation

25 Badges

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

MaplePrimes Activity

These are answers submitted by Carl Love

The way that you present the function f(x,y) suggests to me that you want a plot of a vector field rather than a pair of surfaces. Otherwise, my suggestion is very similar to @mmcdara :

    plots:-fieldplot([-a*x/(1+y^2), x+b*y], (x,y)=~ -5..5),

    (a,b)=~ -2.0 .. 2.0

Change the argument of arctan to D(z)(x) or D(z)(0). Since x=0 at this point in your code, your derivative expression is asking for the "derivative with respect to 0", which, of course, is nonsense. Using D(z)(x) tells it to first take the symbolic derivative of z, and then evaluate that at x (which could be simply a number, like 0 in this case).

Unrelated issue: A design "wart" of Maple's units implementation is that 0 cannot "hold onto" its units, because the Maple representation is number x unit. If the number is 0, that simplifes to just 0. This may or may not cause you problems later on; it's just something to be mindful of. But using with a unit as you did will not in and of itself cause you any problems, and it helps make your code more clear.

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

You can use

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

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

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.


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

F := `&psi;__1`, `&psi;__2`

Vector[column](%id = 36893490949928852284)

# %-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.
        diff~(<F(x)>, x$2) %+
        (<diff(F[1](x), x) - F[1](x), x^3; -x^4, -F[2](x)>) %. E
    F(0)=~ 1, F(1), D~([F])(0)[]

%BVP := %seq(`%+`(Vector(2, {(1) = diff(`&psi;__1`(x), x, x), (2) = diff(`&psi;__2`(x), x, x)}), `%.`(Matrix(2, 2, {(1, 1) = diff(`&psi;__1`(x), x)-`&psi;__1`(x), (1, 2) = x^3, (2, 1) = -x^4, (2, 2) = -`&psi;__2`(x)}), Vector(2, {(1) = e__1, (2) = e__2})))), `&psi;__1`(0) = 1, `&psi;__2`(0) = 1, `&psi;__1`(1), `&psi;__2`(1), (D(`&psi;__1`))(0), (D(`&psi;__2`))(0)

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

{-x^4*e__1-psi__2(x)*e__2+diff(diff(psi__2(x), x), x), (diff(psi__1(x), x)-psi__1(x))*e__1+x^3*e__2+diff(diff(psi__1(x), x), x), psi__1(1), psi__2(1), (D(psi__1))(0), (D(psi__2))(0), psi__1(0) = 1, psi__2(0) = 1}

<BVP[]>; #just for neat columnar display

Vector(8, {(1) = -x^4*e__1-`&psi;__2`(x)*e__2+diff(diff(`&psi;__2`(x), x), x), (2) = (diff(`&psi;__1`(x), x)-`&psi;__1`(x))*e__1+x^3*e__2+diff(diff(`&psi;__1`(x), x), x), (3) = `&psi;__1`(1), (4) = `&psi;__2`(1), (5) = (D(`&psi;__1`))(0), (6) = (D(`&psi;__2`))(0), (7) = `&psi;__1`(0) = 1, (8) = `&psi;__2`(0) = 1})

dsol:= dsolve(BVP, numeric):

dsol(0);  #Any number in interval 0..1 can be used.

[x = 0., psi__1(x) = HFloat(1.0000000000000004), diff(psi__1(x), x) = HFloat(0.0), psi__2(x) = HFloat(1.0000000000000004), diff(psi__2(x), x) = HFloat(0.0), e__1 = HFloat(-1.495772468090626), e__2 = HFloat(-2.3193208032471087)]

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

Vector(2, {(1) = e__1 = -1.4957724680906257, (2) = e__2 = -2.319320803247108})

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


You have nested add commands of the form

add(add(add(..., r= 0..k), p= 0..r), l= 0..p)

add(add(add(add(..., r= 0..k), p= 0..r), l= 0..p), j= 0..l)

You have the nesting order completely backwards. They should be

add(add(add(...., l= 0..p), p= 0..r), r= 0..k)

add(add(add(add(..., j= 0..l), l= 0..p), p= 0..r), r= 0..k)

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]));

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.


    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);

proc (phi) options operator, arrow; kappa__0+kappa__1*(D(Xi)/Xi)(phi)+h__1*(Xi/D(Xi))(phi) end proc

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

proc (phi) options operator, arrow; (1+exp(phi))/exp(-2*phi) end proc

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


solve({Eq21a}, {omega});

{omega = -(1/192)*(rho__1*rho__3^2*kappa__1^2+2*rho__3^3*kappa__1^2-12*rho__2^2)*(-6*rho__1-12*rho__3)^(1/2)*kappa__1/rho__3^2}



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

       (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

           520516421045147049578893562855729553103 x 


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. 

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

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

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


Admittedly, this requires substantially more effort than reading a help page.

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 

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.

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.

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.

1 2 3 4 5 6 7 Last Page 1 of 379