Carl Love

Carl Love

28115 Reputation

25 Badges

13 years, 133 days
Himself
Wayland, Massachusetts, United States
My name was formerly Carl Devore.

MaplePrimes Activity


These are answers submitted by Carl Love

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.

restart
:

#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.
%BVP:=
    %seq(
        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})

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

Download eigvBVP.mw

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.

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
;

12*Psi^3*rho__3^2*((D@@2)(w))(phi)+(-3*Psi*rho__2^2+4*omega*rho__3^2)*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.
    Eq21,
    [
        h__1= 0,
        kappa__0= -5/2*kappa__1,
        Psi= kappa__1/12*sqrt(-6*rho__1 - 12*rho__3)
    ]
);

(1/144)*kappa__1^4*(-6*rho__1-12*rho__3)^(3/2)*rho__3^2*((19*exp(phi)/exp(-2*phi)+8*(1+exp(phi))/exp(-2*phi))*exp(-2*phi)/(1+exp(phi))-3*(5*exp(phi)/exp(-2*phi)+4*(1+exp(phi))/exp(-2*phi))*(exp(phi)/exp(-2*phi)+2*(1+exp(phi))/exp(-2*phi))*(exp(-2*phi))^2/(1+exp(phi))^2+2*(exp(phi)/exp(-2*phi)+2*(1+exp(phi))/exp(-2*phi))^3*(exp(-2*phi))^3/(1+exp(phi))^3)+(-(1/4)*rho__2^2*kappa__1*(-6*rho__1-12*rho__3)^(1/2)+4*omega*rho__3^2)*(-(5/2)*kappa__1+kappa__1*(exp(phi)/exp(-2*phi)+2*(1+exp(phi))/exp(-2*phi))*exp(-2*phi)/(1+exp(phi)))+(1/12)*kappa__1*(-6*rho__1-12*rho__3)^(1/2)*rho__3^2*(rho__1+2*rho__3)*(-(5/2)*kappa__1+kappa__1*(exp(phi)/exp(-2*phi)+2*(1+exp(phi))/exp(-2*phi))*exp(-2*phi)/(1+exp(phi)))^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}

 

Download Xi.mw

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 

 

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

showstat(`tools/genglobal`);

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 
    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.

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.

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.

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 16 17 18 19 20 21 22 Last Page 18 of 396