Maple 2024 Questions and Posts

These are Posts and Questions associated with the product, Maple 2024

I experience Maple 2024 not beeing responsive.

It happens often that nothing is happening for 10 to 15 seconds after placing the cursor in an input line.

When the cursor is back, typing is normal for a little while and then again Maple is not reacting to user input.

The worksheets I am working with are between 50 and 100 Mb large in file size (containing plot3d structures, approx 1000 frames distributed across several plots:-display statements). It looks to me that the GUI has to do some house keeping from time to time which keeps it buisy with all the plot structures.

I could delete (plot) output, but this would require execution of the worksheet (before deleting the output) each time I want to continue working normally. This takes several minutes to be ready to work.

Anything else that I can do?

I am learning patten matching in Maple. 

Any one could explain why patmatch(1, (x::anything)^(n::'nonunit'(anything)))   gives true but patmatch(2, (x::anything)^n::'nonunit'(anything)); gives false?

interface(version);

`Standard Worksheet Interface, Maple 2024.2, Windows 10, October 29 2024 Build ID 1872373`

restart;

patmatch(1, (x::anything)^(n::'nonunit'(anything)))

true

patmatch(2, (x::anything)^n::'nonunit'(anything));

false

Download patmatch_question_nov_16_2024.mw

I was expecting result similar to using this other software

I do not understand Maple's result. How could I change the patmatch so it does not match 1 to the pattern x::anything^n::anything where n is not 1 ?

Update

To give context, I was trying to write this example from the other software  in Maple:

But when I wrote this

expr:=1 + x^2 + x^4;

F:=proc(X::anything,x::symbol)
    local la,y,n;
    if patmatch(X, (y::anything)^(n::'nonunit'(anything)) ,'la') then  
       f(eval(n,la));
     else
        X;
     fi;
end proc;

map(X->F(X,x), expr);

Maple gave 

So I modified the code now to check for explicit 1,  to avoid this bad match, like this

expr:=1 + x^2 + x^4;

F:=proc(X::anything,x::symbol)
    local la,y,n;
    if patmatch(X, (y::anything)^(n::'nonunit'(anything)) ,'la') then  
        if eval(y,la)=1 then #bug in maple?
           X;
        else
           f(eval(n,la));
        fi;
     else
        X;
     fi;
end proc;

map(X->F(X,x), expr);

And now it gives expected result

Given list L:=[3,4,x,x^2,x^3]; return list of all exponents of x (other than 1). So result should be [2,3]

But this has to be done using patmatch, as this is what I am learning. Not using other means. This is my current code that does this.

restart;
L:=[3,4,x,x^2,x^3];
f:=proc(X::anything,x::symbol)
 local la,n;
 if patmatch(X,x^n::nonunit(anything),'la') then
    assign(la);
    RETURN(n);
 else
    RETURN(NULL);
 fi;
end proc;

map(X->f(X,x),L);

Returns [2,3]

I wanted to shorten it using `if` so that no need to call external function f() as shown. So I wrote

L:=[3,4,x,x^2,x^3];
map(X->`if`( patmatch(X,x^n::anything,'la'),[assign(la), n],NULL),L);

But the problem is that on first entry, the assign(la) now assigns value to and hence it is no longer a name for the next element in the list L. This gives error

Error, (in PatternMatching:-AlgStruct:-Match) first operand of `::' must be a name
So I added  unassign('n') like this

restart;
L:=[3,4,x,x^2,x^3];
map(X->[unassign('n'),`if`( patmatch(X,x^n::nonunit(anything),'la'),[assign(la), n],NULL)][],L);

And now this returns 

            [[2], [3]]

How to make it return [2,3]? Why did it add extra []? How can the above be shortened more? and still return [2,3]

edit: I found how to get rid of the extra [], like this

restart;
L:=[3,4,x,x^2,x^3];
map(X->[unassign('n'),`if`( patmatch(X,x^n::nonunit(anything),'la'),[assign(la), n][],NULL)][],L);

Now it returns [2,3] , needed to add extra [] after each closing [.....]

In another system, the code is 

Cases[{3, 4, x, x^2, x^3}, x^n_ -> n]

    {2, 3}
   

I was trying to make the Maple code as short as possible. I know it will not be as short as the above.

The question is: Can above code be made shorter but still use patmatch?

Again, I am looking for only solution using patmatch. I know I can use select and types in Maple to do this also.

Maple 2024.2

Is there another way to change the x-axis values other than tickmarks? For example on an interval [0,4*Pi]

restart; with(plots); with(DEtools)

Ode1 := diff(y(t), t, t) = cos(t)

diff(diff(y(t), t), t) = cos(t)

(1)

IC := (D(y))(0) = 0, y(0) = 1

(D(y))(0) = 0, y(0) = 1

(2)

gsol := dsolve(Ode1, y(t))

y(t) = -cos(t)+c__1*t+c__2

(3)

exactsol := dsolve({IC, Ode1}, y(t), numeric, output = listprocedure)

odeplot(exactsol, [t, y(t)], 0 .. 4*Pi, color = blue, title = "Solution to the Differential Equation", labels = ["t", "y(t)"])

 

Download directly_integrable.mw

A farmer has exactly 100m of wire mesh fence available to enclose a pasture. The fence must begin and end at his large oak tree. To do this, imagine the usual "north-south/west-east" cross of the cardinal directions in the drawing plane. The oak tree is at the center of this.

1. All land that lies west of the imaginary axis is not worth a cent.

2. All land that lies east of the oak tree becomes continuously more expensive the further it is from the north-south axis. The property value is based on the function y = k · x, where y represents the price per square meter and x represents the distance in meters to the north-south axis. k is a proportionality factor, which for the task is k = 1 euro/m^3.

a) On which curve must the fence run so that the enclosed pasture area has the greatest possible value?

b) On which curve must the fence run if instead of the distance x from the north-south axis the distance r from the oak tree is decisive with the same factor k?

I was watching Maple's video for conference 2024. In one of the presentation, this example is given

But in my Mapple 2024.2 I get an error typing the same command:

interface(version);

`Standard Worksheet Interface, Maple 2024.2, Windows 10, October 29 2024 Build ID 1872373`

restart;

my_ode:={diff(x(t),t$2)-t^2*x(t)=0, x(0)=1,D(x)(0)=1}:
MultivariatePowerSeries:-PowerSeries(my_ode,t,x);

Error, invalid input: too many and/or wrong type of arguments passed to MultivariatePowerSeries:-PowerSeries; first unused argument is t

 

 

Download powerSeries_nov_14_2024.mw

Link to the video is here  it is around 39:00 in time. 

Any one knows why I get an error using same command shown in the video?

I tried connecting Maple to Jupyter Notebook, but it seems that it is not keen on outputting everything within the for loop; it only outputs the last item.

for i from 1 to 24 do
    print(i);
end do;

I've noticed that the Maple interface is always white, and after a long time, it causes eye strain. I wonder if it's possible to adjust the interface color, similar to Mathematica. My system is Windows 11.

Currently, I often use VSCode as an alternative, but some mathematical symbols don't display very clearly.

I have noticed similar discussions, such as this one, but I don’t know how to do it

In the attachment are three plotting issues that might be (partially) related.

 
Jagged shading     

 

 

Loss of color and incomplete clipping

The last one is the most severe because it takes color away when a plotobject is inside another object.

 

How can this be fixed? Explanations always welcome.

Shading_artefacs_and_lost_labels_and_color.mw

I have been working on solving a system of PDEs and plotting the results. However I've been encountered issues with setting the spacestep and timestep parameters.

First of all, i attempted to plot graphs t=0..2 using the animate command,

with spacestep = 5*10-4 x 1/151,          timestep=1/1000

However, as shown in the image, an error ocurred indicating that calculations could not proceed after 1.57 sec.

Secondly, i kept the same spacestep but changed the timestep to 1/100 for plotting graphs 
t=0..2. This time, the graphs were plotted without any issues.

I initially beleved that larger spacesteps or timesteps would produce more accurate data. However, in my case, simply increasing these parameters did not work.

I would greatly appreciate if you could provide guidance on what factors should be considered when setting timestep and spacestep parameters, or any experiences in resolving similar issues.

Looks like this

From: dsolve_numeric_output_with_extra_brackets.mw

which was derived from a 2d document where I removed all unnecessary overhead.

When the option output=listprocedure is removed, this extra argument is not shown any more.

With that extra argument substitution of a solution into the corresponding ode(s) is not possible.

Any idea why that is? How to avoid or remove it?

What we are looking for is a flat polygon with N corners and side lengths 1,..., N, which has a maximum surface area.
BTW:
1.) I am a Maple newbie and would like to get to know the diversity and power of the Maple world. For this reason, I occasionally post tasks here from various areas of mathematics and of varying difficulty levels in order to learn from the answers. Of course, I know the solutions to these tasks. So these are not homework.
2.) I have difficulty subsequently inserting text at any point in working worksheets. I keep getting error messages because "or" or ";" is missing. What am I doing wrong?

Continuing from my previous post on "Exploring Oscillators: A Simple Pendulum Worksheet," we now dive deeper into the fascinating progression of oscillatory systems—from linear oscillations to complex, nonlinear dynamics with chaotic behaviors. This post examines how adjusting parameters in oscillatory models, such as the Duffing oscillator, reveal rich dynamics, including resonance and chaos.

LINEAR AND NON-LINEAR OSCILLATORS

Athanasios Paraskevopoulos

 

Imagine a block of mass m attached to a spring. The spring is fixed at one end, and the block is free to move horizontally on a frictionless surface.
 When the block is displaced from its equilibrium position and released, it oscillates back and forth


According to Hooke's Law, the restoring force Fexerted by the spring is proportional to the displacement
x from the equilibrium position and acts in the opposite direction:



F = -k*x

Using Newton's second law,
F = ma, where  a is the acceleration, we get:
"ma= - k x.   "
Since acceleration a is the second derivative of displacement xwith respect to time, the equation becomes:

 

m*(diff(x, t, t)) = -k*x
Rearranging terms, we get:

diff(x, t, t)+k*x/m = 0
Letting "omega^(2)=k/(m), "where ω is the angular frequency, the equation simplifies to

diff(x, t, t)+omega^2*x = 0
 

• 

Amplitude A: Maximum displacement from the equilibrium position.

• 

Angular Frequency omega: Related to the spring constant and mass by omega = sqrt(k/m).

• 

Period T: The time for one complete oscillation, given by "T=(2 Pi)/(omega)."

• 

Frequency f: The number of oscillations per unit time
"F=1/(T)=omega/(2 Pi). "

In a linear simple harmonic oscillator (SHO), the Hamiltonian energy represents the total energy of the system, which is a combination of its kinetic and potential energy.

1. 

Position and Momentum:

• 

Let xbe the displacement of the oscillator from its equilibrium position.

• 

Let pbe the momentum of the oscillator.

 

2. 

Hamiltonian (H):

• 

The Hamiltonian function H is expressed in terms of the kinetic energy (T) and the potential energy (V) of the system.

• 

For a linear SHO, it is given by:
H = T+V

 

3. 

Kinetic Energy (T):

Kinetic energy depends on the mass of the object and its velocity. In physics, it's expressed as:

T = (1/2)*m*u^2

where:

• 

m is the mass of the oscillator,

• 

Typesetting[delayDotProduct](u*is*the*velocity.In, terms, true)*of*momentum, p = mv, be*can*energy*kinetic*re*the-as*expressed; T = p^2/(2*m)
This equation shows that kinetic energy increases with the square of the momentum.

 

4. 

Potential Energy (V)

Potential energy in a simple harmonic oscillator arises from the restoring force of the spring. The potential energy is given by:

V = (1/2)*k*x^2
where

• 

k is the spring constant, and

• 

x is the displacement from the equilibrium position.

 

This means that the further the mass is displaced from equilibrium, the greater the potential energy stored in the system.

Suppose you have a spring with a spring constant k = 10*N/mand a mass m = .2*kg. If the mass is displaced by -.104*m from its equilibrium position and released, it will undergo SHM

restart; with(plots); with(DEtools)

k := 10; m := .2; omega := sqrt(k/m)

10

 

.2

 

7.071067812

(1)

T := 2*Pi/omega

.8885765876

(2)

plot(T, x = 0 .. 1, title = "Period vs Initial Amplitude (x)", axes = boxed, labels = ["Initial Amplitude (x)", "Period (T)"])

 

f := omega/(2*Pi)

1.125395395

(3)

Linear*Oscillator

ODE__1 := diff(x(t), t, t)+omega^2*x(t) = 0; IC := x(0) = A, (D(x))(0) = 0

diff(diff(x(t), t), t)+50.00000000*x(t) = 0

 

x(0) = A, (D(x))(0) = 0

(4)

sol := dsolve({IC, ODE__1}, x(t))

x(t) = A*cos(5*2^(1/2)*t)

(5)

plot_1 := subs(A = -.104, sol); plotsresult := plot([rhs(plot_1)], t = 0 .. 2, legend = ["-0.104cos( 7.07 t)"], color = [red])

 

x_t := rhs(subs(A = -.104, sol)); v_t := diff(x_t, t)

-.104*cos(5*2^(1/2)*t)

 

.520*2^(1/2)*sin(5*2^(1/2)*t)

(6)

T := (1/2)*m*v_t^2; V := (1/2)*k*x_t^2; H := T+V

0.5408000000e-1*sin(5*2^(1/2)*t)^2

 

0.5408000000e-1*cos(5*2^(1/2)*t)^2

 

0.5408000000e-1*sin(5*2^(1/2)*t)^2+0.5408000000e-1*cos(5*2^(1/2)*t)^2

(7)

energy_plot := plot([eval(T), eval(V), eval(H)], t = 0 .. 2, color = [red, blue, green], legend = ["Kinetic Energy", "Potential Energy", "Total Energy"], title = "Energy Exchange in Simple Harmonic Oscillator", labels = ["Time (s)", "Energy (Joules)"])

 

directionfield := DEplot([diff(x(t), t) = v(t), diff(v(t), t) = -omega^2*x(t)], [x(t), v(t)], t = 0 .. 10, x = -2 .. 2, v = -10 .. 10, arrows = medium, title = "Direction Field for Simple Harmonic Oscillator", axes = boxed)

sol1 := dsolve({ODE__1, x(0) = 1, (D(x))(0) = 0}, x(t)); sol2 := dsolve({ODE__1, x(0) = .5, (D(x))(0) = 0}, x(t)); sol3 := dsolve({ODE__1, x(0) = -1, (D(x))(0) = 0}, x(t)); sol4 := dsolve({ODE__1, x(0) = .7, (D(x))(0) = .5}, x(t))

x(t) = cos(5*2^(1/2)*t)

 

x(t) = (1/2)*cos(5*2^(1/2)*t)

 

x(t) = -cos(5*2^(1/2)*t)

 

x(t) = (1/20)*2^(1/2)*sin(5*2^(1/2)*t)+(7/10)*cos(5*2^(1/2)*t)

(8)

x1 := rhs(sol1); x2 := rhs(sol2); x3 := rhs(sol3); x4 := rhs(sol4); v1 := diff(x1, t); v2 := diff(x2, t); v3 := diff(x3, t); v4 := diff(x4, t)

cos(5*2^(1/2)*t)

 

(1/2)*cos(5*2^(1/2)*t)

 

-cos(5*2^(1/2)*t)

 

(1/20)*2^(1/2)*sin(5*2^(1/2)*t)+(7/10)*cos(5*2^(1/2)*t)

 

-5*2^(1/2)*sin(5*2^(1/2)*t)

 

-(5/2)*2^(1/2)*sin(5*2^(1/2)*t)

 

5*2^(1/2)*sin(5*2^(1/2)*t)

 

(1/2)*cos(5*2^(1/2)*t)-(7/2)*2^(1/2)*sin(5*2^(1/2)*t)

(9)

phase_plot := plot([[eval(x1, t = tval), eval(v1, t = tval), tval = 0 .. 10], [eval(x2, t = tval), eval(v2, t = tval), tval = 0 .. 10], [eval(x3, t = tval), eval(v3, t = tval), tval = 0 .. 10], [eval(x4, t = tval), eval(v4, t = tval), tval = 0 .. 10]], style = line, title = "Phase Portrait for Simple Harmonic Oscillator", labels = ["x (Displacement)", "v (Velocity)"], color = ["red", "blue", "green", "orange"], legend = ["A=1, v0=0", "A=0.5, v0=0", "A=-1, v0=0", "A=0.7, v0=0.5"], axes = boxed)

display(directionfield, phase_plot)

 

Damped Oscillators:


Consider a mass-spring-damper system, where a block of mass m is attached to a spring (with spring constant k) and a damper (with damping coefficient delta).
The damper provides resistance to the motion, simulating friction or air resistance.

Damped Oscillator Equation:
m*(diff(x, t, t))+delta*(diff(x, t))+k*x = 0

This is in the form of a homogeneous second order differential equation and has a solution of the form

x = exp(`λt`)

Substituting this form gives an auxiliary equation for lambda

`mλ`^2+`δλ`+`kλ` = 0

The roots of the quadratic auxiliary equation are

λ=(-delta+`&+-`(sqrt(delta^2-4*mk)))/(2*m)

The three resulting cases for the damped oscillator are

• 

delta^2-4*mk > 0Overdamped

• 

delta^2-4*mk = 0Critical damping

• 

delta^2-4*mk < 0Underdamped

The period T of a damped oscillator is primarily determined by the damped angular frequency `&omega;__d`; `&omega;__d` = sqrt(k/m-(delta/(2*m))^2)

Suppose a mass "m=0. 2 kg" is attached to a spring with k = 10*N/m and a damper with a damping coefficient "delta."

restart; with(plots); with(DEtools)

k := 10; m := .2; `&delta;__c` := 2*sqrt(k*m); delta := .6; omega := sqrt(k/m); `&omega;__d` := sqrt(omega^2-(delta/(2*m))^2); T := 2*Pi/`&omega;__d`; f := `&omega;__d`/(2*Pi)

10

 

.2

 

2.828427124

 

.6

 

7.071067812

 

6.910137481

 

.9092706654

 

1.099782538

(10)

ODE__2 := m*(diff(x(t), t, t))+delta*(diff(x(t), t))+k*x(t) = 0; IC := x(0) = -.104, (D(x))(0) = 0

.2*(diff(diff(x(t), t), t))+.6*(diff(x(t), t))+10*x(t) = 0

 

x(0) = -.104, (D(x))(0) = 0

(11)

sol := dsolve(ODE__2, x(t))

x(t) = c__1*exp(-(3/2)*t)*sin((1/2)*191^(1/2)*t)+c__2*exp(-(3/2)*t)*cos((1/2)*191^(1/2)*t)

(12)

sol := dsolve({IC, ODE__2}, x(t), numeric, output = listprocedure)

odeplot(sol, [t, x(t)], 0 .. 10, color = blue)

 

H := proc (t) local pos, vel, kinetic, potential; pos := rhs(sol(t)[2]); vel := rhs(sol(t)[3]); kinetic := (1/2)*m*vel^2; potential := (1/2)*k*pos^2; return kinetic+potential end proc

timeRange := 0 .. 35; plot(H(t), t = timeRange, title = "Hamiltonian Energy vs Time", labels = ["Time (t)", "Energy (H)"])

 

for meth in SolutionMethods do meth, H(100) end do

SolutionMethods, HFloat(1.6739566269541513e-16)

(13)

Mass-Spring System with a Non-Linear Spring

• 

Springs with large deflections are not linear and their forces can be approximated by a cubic term F = -a*x^3-k*x

• 

If beta > 0hardening spring (stiffer with larger deflection), if beta < 0softening spring (more flexible with larger deflection).

• 

So, the EOM fot a mass-spring system in free vibration will  be:

m*(diff(x(t), t, t))+k*x(t)+`&beta;x`^3 = 0

The period of oscillation will not be constant and depends on the applitude of oscillations and sign of "beta."

First case beta > 0

restart; with(plots); m := .2; k := 10; beta := 1

.2

 

10

 

1

(14)

EOM := m*(diff(x(t), `$`(t, 2)))+k*x(t)+beta*x(t)^3 = 0

.2*(diff(diff(x(t), t), t))+10*x(t)+x(t)^3 = 0

(15)

sol := dsolve({EOM, x(0) = -.104, (D(x))(0) = 0}, x(t), numeric, range = 0 .. 20, output = listprocedure)

odeplot(sol, [t, x(t)], 0 .. 10, title = "Nonlinear Oscillation (Hardening Spring)", labels = ["Time (s)", "Displacement (m)"], color = blue)

 

H := proc (t) local pos, vel, kinetic, potential; pos := rhs(sol(t)[2]); vel := rhs(sol(t)[3]); kinetic := (1/2)*m*vel^2; potential := (1/2)*k*pos^2+(1/4)*beta*pos^4; return kinetic+potential end proc; timeRange := 0 .. 10; plot(H(t), t = timeRange, 0 .. .1, title = "Hamiltonian Energy vs Time", labels = ["Time (t)", "Energy (H)"])

proc (t) local pos, vel, kinetic, potential; pos := rhs(sol(t)[2]); vel := rhs(sol(t)[3]); kinetic := (1/2)*m*vel^2; potential := (1/2)*k*pos^2+(1/4)*beta*pos^4; return kinetic+potential end proc

 

0 .. 10

 

 

In this non-linear mass-spring-damper system (without damping), the Hamiltonian  is essentially the total energy of the system, as there is no energy loss.

• 

The Hamiltonian remains relatively constant over time, as expected in an ideal undamped system, indicating energy conservation.

• 

Small numerical variations may occur due to the non-linear terms and the precision of numerical methods used for solving the differential equations.

eq1 := diff(x(t), t) = v(t); eq2 := diff(v(t), t) = -k*x(t)/m-beta*x(t)^3/m

diff(x(t), t) = v(t)

 

diff(v(t), t) = -50.00000000*x(t)-5.000000000*x(t)^3

(16)

initial_conditions := [[x(0) = -.104, v(0) = 0]]; with(DEtools); DEplot([eq1, eq2], [x(t), v(t)], t = 0 .. 1, x = -.3 .. .3, v = -2 .. 2, initial_conditions, title = "Phase Portrait for Nonlinear Oscillator", axes = boxed, labels = ["Displacement x", "Velocity v"], linecolor = blue)

[[x(0) = -.104, v(0) = 0]]

 

 

Second Case beta < 0

restart; with(plots)

m := .2; k := 10; beta := -1

.2

 

10

 

-1

(17)

EOM := m*(diff(x(t), `$`(t, 2)))+k*x(t)+beta*x(t)^3 = 0

.2*(diff(diff(x(t), t), t))+10*x(t)-x(t)^3 = 0

(18)

sol := dsolve({EOM, x(0) = -.104, (D(x))(0) = 0}, x(t), numeric, range = 0 .. 20, output = listprocedure)