Maple Questions and Posts

These are Posts and Questions associated with the product, Maple

Hello 

I have a 3D vector plot with 3 vectors. It would be nice to have a legend for this, but so far, I have struggled to find a solution.

At the moment, I use a caption for this, but I am not fully happy with this.legend_question.mw 

Is there a simple solution?

Thanks in advance 

This time domain diagram has been drawn, but if you want to draw its outer outline, how should you command it?
saopinjifen1230.mw

 

Is there an easy way to convert a maple worksheet to a command line .mpl file to be executed from command line?

Basically strips all the comments and just keep the commands.in the .mpl file.

The exports in the Maple interface do not produce command line executable code.

It is ok if there is a third party script also to do this.

When I attempt to solve for a specific parameter in Maple, it results in an error stating that the parameter does not exist. However, if I solve for all parameters, it successfully finds them, as shown in the figure. How can I resolve this issue?

parameter.mw

Hi

Following on from this question, https://www.mapleprimes.com/questions/200909-Roster-Choose-Teams
I wanted to create the sequence for n>3 teams, where n:: even and two byes.
Currently, my AI-modified code produces the wrong output, can someone modify it?

# Example usage with 8 teams and 2 byes
PrintPairings(8); 

Round 1:
  1 vs 2
  3 vs 4
  5 sits out
  8 sits out
....
:Round_Robin.mw
It should be
Round 1:
  1 vs 2
  3 vs 4
  5 vs 6
  7 sits out
  8 sits out
......
etc

I use this type ckect elsewhere inside a package and it works. I can't get it to work in a stand alone procedure.

This was originally provided by @acer (best answer) in this question Experimental format for projective vectors - MaplePrimes

restart

 

 

test:=proc(V::{And('Vector(1)',satisfies( v->type(v[1],'Vector[:-column](3)') ) ),
               And('Vector(1)',satisfies( v->type(v[1],'Vector[:-row](3)') ) )})
print("works",V);
end proc

proc (V::{And('Vector(1)', satisfies(proc (v) options operator, arrow; type(v[1], 'Vector[:-column](3)') end proc)), And('Vector(1)', satisfies(proc (v) options operator, arrow; type(v[1], 'Vector[:-row](3)') end proc))}) print("works", V) end proc

(1)

v1:=<[<1,3,2>]>;
v2:=<[<a|b|c>]>

Vector(1, {(1) = Vector(3, {(1) = 1, (2) = 3, (3) = 2})})

 

Vector[column](%id = 36893490573309309044)

(2)

test(v1)

Error, invalid input: test expects its 1st argument, V, to be of type {And('Vector[1]',satisfies(v -> type(v[1],'Vector[:-column](3)'))), And('Vector[1]',satisfies(v -> type(v[1],'Vector[:-row](3)')))}, but received Vector(1, [Vector(3, [1,3,2])])

 

test(v2)

Error, invalid input: test expects its 1st argument, V, to be of type {And('Vector[1]',satisfies(v -> type(v[1],'Vector[:-column](3)'))), And('Vector[1]',satisfies(v -> type(v[1],'Vector[:-row](3)')))}, but received Vector(1, [Vector[row](3, [a,b,c])])

 

whattype(v1)

Vector[column]

(3)

whattype(v1[1])

Vector[column]

(4)

whattype(v2)

Vector[column]

(5)

whattype(v2[1])

Vector[row]

(6)
 

 

Download 2024-12-29_Q_Type_checking_not_working.mw

A street of finite length has many houses on one side, which are numbered in consecutive order with 1, 2, 3, 4, ... Determine all house numbers where the sum of all house numbers before this house number is equal to the sum of all house numbers after it.

That's enough for this year.
I wish everyone a happy new year 2025.

Relative path does not seems to work on Linux.
 e.g. consider the read command
 `read  "/home/harpo/skits/slapstick/boguscalculus.mw"

At the moment I have to enter the full path above as stated to be able to read in "boguscalculus.mw"

This highly unfortunte, as generally you want to specify a path, independent of the home path.

That would mean

read "~/skits/slapstick/boguscalculus.mw"   , but this does not work. Any idea why ?

Furthermore using "currentdir" to set the current directory, I also have to use the full path from root "\" which is highly unusual.

Lastly given that I set a current directory with currentdir, how do I use the currentdir to read a file inside currentdir with read command ?

e.g.

currentdir "/home/harpo/skits"
how do I read the file in a worksheet using from the  currentdir

e.g. it should be

read "slapstick/boguscalculus.mw"

But that doesnt work either.

I think a new integer subtype is needed: integer greater than one, gtoint.

isgto := proc(x::anything)
  local X;
  X:=x;
  return type(X,integer) and (X>1);
end:

AddType(gtoint,z->not isgto(z));

Given 4 hummingbirds, each located at the vertex of a unit tetrahedron.
The birds begin to fly in such a way that all birds fly at the same speed and:
(1) Bird #1 always flies directly toward bird #2
(2) Bird #2 always flies directly toward bird #3
(3) Bird #3 always flies directly toward bird #4
(4) Bird #4 always flies directly toward bird #1
As one can imagine, the flying birds eventually meet and collide. (Assume the birds are very small.)

What is needed is the distance to the collision point of the hummingbirds.

Recently, I read an old article about how to call external subroutines to speed up the evaluation tremendously. The core of that article is: 

Evidently, the Typesetting:-mrow(Typesetting:-mi( is equivalent to  when b>0, and the `∸`(a, b) is equivalent to . 
The 𝙲 code in that article was composed separately. However, now that it is possible to generate external functions, compile and access them using a single Compiler:-Compile command, it is better to complete the entire process on the fly (in order to reduce oversights and typographical errors while coding). (Besides, the original 𝙼𝚊𝚙𝚕𝚎 implementation appears verbose and less elegant.) So I write: 

JonesM1 := Compiler:-Compile((n::posint) -> add(max(1 - max(add(ifelse(j = 0, max(j - 1, 0)!**2, irem(max(j - 1, 0)!**2, j)), j = 0 .. i) - n, 0), 0), i = 0 .. n**2), 'O' = 2): # literal translation of the above formula 

But unfortunately, I then get: 

JonesM1(1);
                               2

JonesM1(2);
                               3

JonesM1(3);
                               5

JonesM1(4);
Error, (in JonesM1) integer overflow detected in compiled code

How do I get rid of this error message? 

Note. Of course there exist a ready-to-use built-in function , but the chief aim is not to find the n-th prime number as quickly as possible; I want to see if 𝙼𝚊𝚙𝚕𝚎 can directly create a compiled version of the one-liner that implements the so-called Jones' algorithm instead of writing separate 𝙲 code like that article. (Don't confound the means with the ends.) 

I do not remember if I reported this before or not. Can't find it. Just in case, I am posting this.

If someone find it is duplicate, feel free to delete this. But this is in latest Maple 2024.2. May be this can be fixed in time by Maple 2025 version.

restart;

interface(version);

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

Physics:-Version();

`The "Physics Updates" version in the MapleCloud is 1840 and is the same as the version installed in this computer, created 2024, December 2, 10:11 hours Pacific Time.`

libname;

"C:\Users\Owner\maple\toolbox\2024\Physics Updates\lib", "C:\Program Files\Maple 2024\lib"

ode := diff(y(x),x)/y(x)-(3*(4*x^2+y(x)^2+1))/(2*x*(4*x^2+y(x)^2-2-2*x))=0;

(diff(y(x), x))/y(x)-(3/2)*(4*x^2+y(x)^2+1)/(x*(4*x^2+y(x)^2-2-2*x)) = 0

DEtools:-odeadvisor(ode);

[_rational]

dsolve(ode,y(x));

Error, (in dsolve) invalid subscript selector

restart;

infolevel[dsolve]:=5;

5

ode := diff(y(x),x)/y(x)-(3*(4*x^2+y(x)^2+1))/(2*x*(4*x^2+y(x)^2-2-2*x))=0:

dsolve(ode,y(x));

Methods for first order ODEs:

--- Trying classification methods ---

trying a quadrature

trying 1st order linear

trying Bernoulli

trying separable

trying inverse linear

trying homogeneous types:

trying Chini

differential order: 1; looking for linear symmetries

trying exact

Looking for potential symmetries

trying inverse_Riccati

trying an equivalence to an Abel ODE

equivalence obtained to this Abel ODE: diff(y(x),x) = 3/2*(4*x^2+1)/x/(2*x^2-x-1)*y(x)-(x^2+2*x+3)/x/(2*x^2-x-1)^2*y(x)^2+3/8*(2*x+3)/(2*x^2-x-1)^3/x*y(x)^3

trying to solve the Abel ODE ...

The relative invariant s3 is: -1/432*(8*x^4+40*x^3+45*x^2-270*x+135)/x^3/(x-1)^6/(2*x+1)^4

The first absolute invariant s5^3/s3^5 is: 729/16*(128*x^8+1152*x^7+3696*x^6+1744*x^5+8148*x^4-31500*x^3+6615*x^2-5670*x+8505)^3/(2*x+1)^4/(8*x^4+40*x^3+45*x^2-270*x+135)^5

The second absolute invariant s3*s7/s5^2 is: 1/3*(8*x^4+40*x^3+45*x^2-270*x+135)*(10240*x^12+133120*x^11+697600*x^10+1710080*x^9+3358592*x^8-1701568*x^7+6692592*x^6-18182448*x^5+2088072*x^4-7938000*x^3+2525985*x^2+1786050*x+2679075)/(128*x^8+1152*x^7+3696*x^6+1744*x^5+8148*x^4-31500*x^3+6615*x^2-5670*x+8505)^2

...checking Abel class AIL (45)

...checking Abel class AIL (310)

...checking Abel class AIR (36)

...checking Abel class AIL (301)

...checking Abel class AIL (1000)

...checking Abel class AIL (42)

...checking Abel class AIL (185)

...checking Abel class AIA (by Halphen)

...checking Abel class AIL (205)

...checking Abel class AIA (147)

...checking Abel class AIL (581)

...checking Abel class AIL (200)

...checking Abel class AIL (257)

...checking Abel class AIL (400)

...checking Abel class AIA (515)

...checking Abel class AIR (1001)

...checking Abel class AIA (201)

...checking Abel class AIA (815)

Looking for potential symmetries

... changing x -> 1/x, trying again

Looking for potential symmetries

The third absolute invariant s5*s7/s3^4 is: 243/16*(10240*x^12+133120*x^11+697600*x^10+1710080*x^9+3358592*x^8-1701568*x^7+6692592*x^6-18182448*x^5+2088072*x^4-7938000*x^3+2525985*x^2+1786050*x+2679075)/(2*x+1)^4*(128*x^8+1152*x^7+3696*x^6+1744*x^5+8148*x^4-31500*x^3+6615*x^2-5670*x+8505)/(8*x^4+40*x^3+45*x^2-270*x+135)^4

 ->         ======================================

 ->             ...checking Abel class D (by Appell)

 -> Step 1: checking for a disqualifying factor on F after evaluating x at a number

Trying x = 2

*** No disqualifying factor on F was found ***

 -> Step 2: calculating resultants to eliminate F and get candidates for C

*** Candidates for C are {4/27} ***

 -> Step 3: looking for a solution F depending on x

*** No solution F of x was found ***

 ->         ======================================

 ->             ...checking Abel class B (by Liouville)

 -> Step 1: checking for a disqualifying factor on F after evaluating x at a number

Trying x = 2

*** No disqualifying factor on F was found ***

 -> Step 2: calculating resultants to eliminate F and get candidates for C

*** Candidates for C are {1, 4, 1/4} ***

 -> Step 3: looking for a solution F depending on x

*** No solution F of x was found ***

 ->         ======================================

 ->             ...checking Abel class A (by Abel)

 -> Step 1: checking for a disqualifying factor on F after evaluating x at a number

Trying x = 2

*** No disqualifying factor on F was found ***

 -> Step 2: calculating resultants to eliminate F and get candidates for C

*** Candidates for C are {0, -1/4} ***

 -> Step 3: looking for a solution F depending on x

*** No solution F of x was found ***

 ->         ======================================

 ->             ...checking Abel class C (by Abel)

 -> Step 1: checking for a disqualifying factor on F after evaluating x at a number

Trying x = 2

*** No disqualifying factor on F was found ***

 -> Step 2: calculating resultants to eliminate F and get candidates for C

*** Candidates for C are {2, -11676447873119/75975070592769, 9/5, 15632211369872/75439744512117, 46273613050865/52325357771027, 75312059745574/25138886548531} ***

 -> Step 3: looking for a solution F depending on x

_____________________________

C = 9/5 leads to a useless solution (F does not depend on x)

*** No solution F of x was found ***

 ->         ======================================

 ->             ...checking Abel class AIL 1.6

 -> Step 1: checking for a disqualifying factor on F after evaluating x at a number

Trying x = 2

*** No disqualifying factor on F was found ***

 -> Step 2: calculating resultants to eliminate F and get candidates for C

*** Candidates for C are {-4, 16} ***

 -> Step 3: looking for a solution F depending on x

*** No solution F of x was found ***

 ->         ======================================

 ->             ...checking Abel class AIL 1.8

 -> Step 1: checking for a disqualifying factor on F after evaluating x at a number

Trying x = 2

*** No disqualifying factor on F was found ***

 -> Step 2: calculating resultants to eliminate F and get candidates for C

*** Candidates for C are {0, -116457391291688/45108305127449, -96869842492381/35485755507516, -36964550865207/94238117721032, -32286830321303/11596568583712, 32286830321303/11596568583712, 36964550865207/94238117721032, 96869842492381/35485755507516, 116457391291688/45108305127449} ***

 -> Step 3: looking for a solution F depending on x

*** No solution F of x was found ***

 ->         ======================================

 ->             ...checking Abel class AIL 1.9

 -> Step 1: checking for a disqualifying factor on F after evaluating x at a number

Trying x = 2

*** No disqualifying factor on F was found ***

 -> Step 2: calculating resultants to eliminate F and get candidates for C

*** Candidates for C are {-2/9, -1/9} ***

 -> Step 3: looking for a solution F depending on x

*** No solution F of x was found ***

 ->         ======================================

 ->             ...checking Abel class AIA 1.51

 -> Step 1: checking for a disqualifying factor on F after evaluating x at a number

Trying x = 2

*** No disqualifying factor on F was found ***

 -> Step 2: calculating resultants to eliminate F and get candidates for C

*** Candidates for C are {0, -94917840318055/84247876515289, -85939756880989/51399391393709, -82210125508529/36853933366676, -74381886667083/82545981233858, -41168492684238/33804146399567, -15658703496425/19275443365317, -9175348901453/101481647952193, 3/4, 15/4, 5568553686203/113599855351490, 12774469621703/63437040534358, 17836021821409/102823494563886, 39657708622139/74009717243016, 82495450887526/27663991325651, 86656182727564/45157560524183, 90074893410229/54954593917906, 100200889070747/32282555481919, 113612565327585/103754255779069} ***

 -> Step 3: looking for a solution F depending on x

_____________________________

C = 15/4 leads to a useless solution (F does not depend on x)

*** No solution F of x was found ***

 ->         ======================================

 ->             ...checking Abel class AIA 1.5

 -> Step 1: checking for a disqualifying factor on F after evaluating x at a number

Trying x = 2

*** No disqualifying factor on F was found ***

 -> Step 2: calculating resultants to eliminate F and get candidates for C

*** Candidates for C are {-1, 1, -113553630998996/78694251194667, -112790344818825/35834119404842, -104905620984375/18860524785743, -95409943222181/78810323073434, -77648002983645/31218435062578, -67259194033608/9576982470445, -46892223838816/86694928762723, -45901561561111/29768419326991, -34674701564566/6522678435631, 26154715634141/21099761863911, 42841215778132/81925179545457, 52638927823233/15127919203723, 54069389554571/5444364811188, 54445812264368/10328928623117, 56815569067370/40738034746481, 75614540760757/62881656939350, 76459718737483/64786816765621, 85896394925571/88677987470966, 90623073438172/24246571690325, 103628692054633/17857341616628, 117754725919014/60191028908095} ***

 -> Step 3: looking for a solution F depending on x

_____________________________

C = -1 leads to a useless solution (F does not depend on x)

_____________________________

C = -113553630998996/78694251194667 leads to a useless solution (F does not depend on x)

_____________________________

C = -112790344818825/35834119404842 leads to a useless solution (F does not depend on x)

_____________________________

C = -104905620984375/18860524785743 leads to a useless solution (F does not depend on x)

_____________________________

C = -95409943222181/78810323073434 leads to a useless solution (F does not depend on x)

_____________________________

C = -77648002983645/31218435062578 leads to a useless solution (F does not depend on x)

_____________________________

C = -67259194033608/9576982470445 leads to a useless solution (F does not depend on x)

_____________________________

C = -46892223838816/86694928762723 leads to a useless solution (F does not depend on x)

_____________________________

C = -45901561561111/29768419326991 leads to a useless solution (F does not depend on x)

_____________________________

C = -34674701564566/6522678435631 leads to a useless solution (F does not depend on x)

_____________________________

C = 26154715634141/21099761863911 leads to a useless solution (F does not depend on x)

_____________________________

C = 42841215778132/81925179545457 leads to a useless solution (F does not depend on x)

_____________________________

C = 52638927823233/15127919203723 leads to a useless solution (F does not depend on x)

_____________________________

C = 54069389554571/5444364811188 leads to a useless solution (F does not depend on x)

_____________________________

C = 54445812264368/10328928623117 leads to a useless solution (F does not depend on x)

_____________________________

C = 56815569067370/40738034746481 leads to a useless solution (F does not depend on x)

_____________________________

C = 75614540760757/62881656939350 leads to a useless solution (F does not depend on x)

_____________________________

C = 76459718737483/64786816765621 leads to a useless solution (F does not depend on x)

_____________________________

C = 85896394925571/88677987470966 leads to a useless solution (F does not depend on x)

_____________________________

C = 90623073438172/24246571690325 leads to a useless solution (F does not depend on x)

_____________________________

C = 103628692054633/17857341616628 leads to a useless solution (F does not depend on x)

_____________________________

C = 117754725919014/60191028908095 leads to a useless solution (F does not depend on x)

*** No solution F of x was found ***

 ->         ======================================

 ->             ...checking Abel class AIA 1.52

 -> Step 1: checking for a disqualifying factor on F after evaluating x at a number

Trying x = 2

*** No disqualifying factor on F was found ***

 -> Step 2: calculating resultants to eliminate F and get candidates for C

*** Candidates for C are {-5, -4, -3, 0, 1, 2, -3/2} ***

 -> Step 3: looking for a solution F depending on x

*** No solution F of x was found ***

 ->         ======================================

 ->             ...checking Abel class AIA 1.53

 -> Step 1: checking for a disqualifying factor on F after evaluating x at a number

Trying x = 2

*** No disqualifying factor on F was found ***

 -> Step 2: calculating resultants to eliminate F and get candidates for C

*** Candidates for C are {-3, -1, 1, 2, -3/2, -2/3, -1/2} ***

 -> Step 3: looking for a solution F depending on x

_____________________________

C = -3 leads to a useless solution (F does not depend on x)

_____________________________

C = -3/2 leads to a useless solution (F does not depend on x)

*** No solution F of x was found ***

trying to map the Abel into a solvable 2nd order ODE

...checking Abel class AIA 2-parameter, reducible to Riccati

Error, (in dsolve) invalid subscript selector

restart;

ode := diff(y(x),x)/y(x)-(3*(4*x^2+y(x)^2+1))/(2*x*(4*x^2+y(x)^2-2-2*x))=0:

dsolve(ode,y(x));

Error, (in dsolve) invalid subscript selector

tracelast;

Error, (in dsolve) invalid subscript selector

 

 

Download dsolve_invalid_subscript_dec_27_2024.mw

I am working on visualizing the results of an SIR model in Maple. I’ve created multiple plots for different parameter values using dsolve and odeplot, and I’d like to arrange them in a grid (e.g., 2 rows x 3 columns) for easier comparison. Here’s what I’ve tried:

restart; with(plots); n := 10^6; s__0 := n-1; i__0 := 1; r__0 := 0; simulate_SIR := proc (beta, gamma) local lambda, sys, ic, sols, single_plot; lambda := beta*i(t)/n; sys := diff(s(t), t) = -lambda*s(t), diff(i(t), t) = lambda*s(t)-gamma*i(t), diff(r(t), t) = gamma*i(t); ic := s(0) = s__0, i(0) = i__0, r(0) = r__0; sols := dsolve({sys, ic}, numeric, output = listprocedure); single_plot := display([odeplot(sols, [t, s(t)], 0 .. 60, color = red), odeplot(sols, [t, i(t)], 0 .. 60, color = blue), odeplot(sols, [t, r(t)], 0 .. 60, color = green)], labels = ["Time [day]", "Population"], labeldirections = [horizontal, vertical], legend = ["Susceptible", "Infected", "Recovered"], legendstyle = [location = right]); return single_plot end proc; plot1 := simulate_SIR(.1, .1); plot2 := simulate_SIR(.2, .1); plot3 := simulate_SIR(.7, .1); plot4 := simulate_SIR(1.5, .1); plot5 := simulate_SIR(1, 0.25e-1); plot6 := simulate_SIR(1, .2); plot7 := simulate_SIR(1, .5); plot8 := simulate_SIR(1, 1); combined_plot := display([plot1, plot2, plot3, plot4, plot5, plot6, plot7, plot8], insequence = true, view = [0 .. 60, 0 .. n], grid = [2, 4]); combined_plot

 
 

NULL

Download grid.mw

Unfortunately, the insequence=true and gird=[2, 4] options didn’t work as I expected. Instead of arranging the plots in a grid, they appear like an animation

How can I correctly arrange multiple plots into a grid layout in Maple? Are there specific options or steps I’m missing? I would appreciate any guidance or examples.

I am doing some work in Maple.  Specifically, I run the following commands in Maple worksheet mode:

with(Statistics);
L := abs(RandomVariable(UniformDistribution(0, 1)) - RandomVariable(UniformDistribution(0, 1)));
Export("LineDensity.jpg", DensityPlot(L));
PDF(L, x);

Everything works fine.  When I export these commands into an MPL script, I get the following:

with(Statistics);
L := abs(RandomVariable(UniformDistribution(0, 1)) - RandomVariable(UniformDistribution(0, 1)));
Export("LineDensity.jpg", DensityPlot(L));
PDF(L, x);
NULL;

When I execute this script, I get the following error message:

Warning: persistent store makes readlib obsolete
Error: (in Export) exported file LineDensity.jpg could not be created

I need to do the work in MPL script form so that I can have larger problems processed.  Does anyone know why I would be having this problem with the Export function?  

I did a lot  of time but this time i don't know why not run any one have idea?

restart

with(PDEtools)

with(LinearAlgebra)

with(Physics)

with(SolveTools)

undeclare(prime)

`There is no more prime differentiation variable; all derivatives will be displayed as indexed functions`

(1)

declare(u(x, t)); declare(U(xi)); declare(G(xi))

u(x, t)*`will now be displayed as`*u

 

U(xi)*`will now be displayed as`*U

 

G(xi)*`will now be displayed as`*G

(2)

T := xi = -V*t+x; T1 := u(x, t) = U(-V*t+x)*exp(I*(-k*x+t*w+theta))

xi = -V*t+x

 

u(x, t) = U(-V*t+x)*exp(I*(-k*x+t*w+theta))

(3)

P3 := diff(u(x, t), x, t)

``

(4)

P33 := diff(u(x, t), x)

diff(u(x, t), x)

(5)

P333 := diff(P33, t)

NULL

Download why.mw

3 4 5 6 7 8 9 Last Page 5 of 2175