Carl Love

Carl Love

26344 Reputation

25 Badges

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

MaplePrimes Activity


These are answers submitted by Carl Love

For example, to do it for year 2024:

select(m-> Calendar:-DayOfWeek(2024, m, 13) = 6, [$1..12]);
                          [9, 12]

So the 9th and 12th months have a Friday-the-13th, i.e., September and December. The 6 represents Friday (considered the 6th day of the week).

Use 

if indets(r, suffixed('_')) <> {} then . .

You could also change '_' to _Z, etc.

There are two anomalies happening in your example:

1. Left-associativity: All infix operators beginning with a single are left-associative (and those beginning with && are right-associative). So 2 &^ 2 &^ 2 &^ 2 is interpreted as ((2 &^ 2) &^ 2) &^ 2 rather than 2 &^ (2 &^ (2 &^ 2)). This happens in the kernel before mod sees the expression.

2.Distributivity: mod doesn't distribute over exponentiation because it's usually not mathematically valid. In other words, a &^ b mod c isn't interpreted as (a mod c) ^ (b mod c) mod c. An example for which it isn't valid is a=2, b=4, c=3

I wouldn't use testeq at all. It's returned FAIL every time that I've ever tried to apply it to a transcendental function. But plain simplify or is works fine here. All of these return the information that you want:

is(expr=x), evalb(simplify(expr)=x), evalb(simplify(expr-x) = 0);

Here are two more-efficient algorithms for the sum of the proper divisors. The first of these (SPD2 below) is much faster than your original; the second (SPD3 below) is much faster than that.

I think that this will all work in your Maple 13; if not, let me know.

restart
:
(* Sum of Proper Divisors (original version):
---------------------------------------------
This is your original procedure. The only changes I made were removing things
not directly related to getting the answer, such as print statements.
*)
SPD0:= proc(n)
local Sum1, b;
    Sum1:= 1;
    for b from 2 to ceil(n/2) do
        if floor(n/b) = n/b then Sum1:= Sum1 + b fi
    od;
    Sum1
end proc
:
(* Sum of Proper Divisors (version 1):
--------------------------------------
This is the same algorithm as yours, recoded. The changes that I made were 
to use operators that are more efficient for integer arithmetic: add, modp,
and iquo instead of `for`, ceil, `/`, and floor.
*)
SPD1:= proc(n::posint)
local d;
    1 + add(`if`(modp(n,d) = 0, d, 0), d= 2..iquo(n,2))
end proc
:
(* Sum of Proper Divisors (version 2):
--------------------------------------
This algorithm uses this idea: 
Let n be a positive integer. Let s = floor(sqrt(n)). For every divisor d of n, 
q = n/d is also a divisor, and d <= s iff q >= s. If s^2 = n, we need to adjust
for the double counting of s.
*)
SPD2:= proc(n::posint)
local d, q, s;
    s:= isqrt(n);  #same as floor(sqrt(n)) but faster
    #irem gives the integer remainder and quotient in one step:
    add(`if`(irem(n, d, 'q') = 0, d+q, 0), d= 2..s)  +  1 - `if`(s^2=n, s, 0)
end proc
:
(* Sum of Divisors of a Prime Power:
------------------------------------
For prime p, the divisors of p^e are clearly
    {1, p, p^2, ..., p^e}.
The sum of those is a simple geometric sum:
    sum(p^k, k= 0..e) = (p^(e+1) - 1)/(p - 1).
*) 
SDPP:= (p::prime, e::posint)-> (p^(e+1) - 1)/(p-1)
:
(* Sum of Proper Divisors (version 3):
--------------------------------------
This uses the classic formula for the sum of divisors, then subtracts
the number itself.

This uses ifactors, which returns the same information as ifactor, but in a
list of lists format:
   ifactors(n) = [-1 or +1, [[p1,e1], [p2,e2], ..., [pk,ek]]],
such that the prime factorization is 
    n = p1^e1 * p2^e2 * ... * pk^ek.
*)
SPD3:= proc(n::posint) 
local P; 
    mul(SDPP(P[]), P= ifactors(n)[2]) - n 
end proc
: 
#Test all 4 on your example:
SPD||(0..3)(945);
                       975, 975, 975, 975

#Construct a much larger random example:
seq('rand(2..99)(), nextprime(rand(10^5..10^7)())', k= 1..9);
    94, 8633311, 97, 9909901, 60, 1584343, 70, 3888067, 97, 3079871, 
    91, 5954371, 19, 8014679, 57, 682901, 84, 4397777

n:= `*`(%);
n := 7153933542604628643414930949912947237856549377795642829298491576067369227200

CodeTools:-Usage( SPD3(n) );
memory used=9.62MiB, alloc change=0 bytes, 
cpu time=94.00ms, real time=160.00ms, gc time=0ns

28515792740732679749844128611744262891259901154773757373417700467974788852800

 

Here's something. You'll probably want some adjustments, but it's a good start.

Pl:= plots:  PT:= plottools:
Pl:-display(
    PT:-line~(
        [[0,1,1], [0,-1,-1], [5,1,-1]], [[0,1,-1]$3], 
        linestyle= dash, color= red
    )[],
    PT:-line~(
        [
            [0,1,1], [5,-1,1], [0,-1,-1],
            [0,-1,-1], [5,-1,1], [5,1,-1],
            [0,1,1], [5,-1,1], [5,1,-1]
        ], 
        [[0,-1,1]$3, [5,-1,-1]$3, [5,1,1]$3],
        color= red
    ),
    PT:-line~(
        [[0.5,-1.3,-1.3], [3,-1.3,-1.3]], 
        [[2.5,-1.3,-1.3], [5.0,-1.3,-1.3]],
        color= blue
    ),
    Pl:-textplot3d([2.75, -1.3, -1.3, `&ell;`], color= blue),
    Pl:-textplot3d(
        [2.5, 0, 0, typeset(Q(x,z,t) = Q[0]*delta(x - v*t)*sin(p*z))],
        color= black, align= below
    ),
    axes= normal, axis[1,2,3]= [color= blue, tickmarks= 0],
    scaling= constrained, view= [0..6, (-2..2)$2],
    labels= [x,y,z], projection= 0.7, orientation= [-91,65,-15]
);

Replace your ID with thistype.

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 :

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

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

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