Maple 2024 Questions and Posts

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

I have  4 worksheets with derived equations. So I export the equations and  possibly some procedures (but they can be handled seperately if needed)  from each worksheet as a .mpl file. 

I want to combine the .mpl files  together without using copy/paste. Then I can open that single file in the VS code editor.
There may be other ways to achieve this so I am open to suggestions.

I chased down a problem to factoring a square that has sqrt in the coefficients. All numbers are real,
The code is inside a procedure in a package. Iso I could do with something robust.

expand((sqrt(A+B)*x+sqrt(7-K)*y)^2)
     2      2            (1/2)          (1/2)        2      2
  A x  + B x  + 2 (A + B)      x (7 - K)      y - K y  + 7 y 

factor(%) 

 

Hello, everyone,

I am new to Maple and I am trying to get use of it.

I tried to plot the following linear systems in different ways. I realized that the Student Linear Algebra is not as flexible as Linear Algebra. My question is the following. Is there any other way to create a plot without defining the implicit plots?

with(Student[LinearAlgebra])

A := Matrix([[1, 1], [12, 16]]); b := Vector([10, 136]); sol := LinearSolve(A, b)

Matrix(2, 2, {(1, 1) = 1, (1, 2) = 1, (2, 1) = 12, (2, 2) = 16})

 

Vector(2, {(1) = 10, (2) = 136})

 

Vector[column](%id = 36893488153382714652)

(1)

LinearSystemPlot({x+y = 10, 12*x+16*y = 136}, axes = normal)

 

restart

 

 

with(Student[LinearAlgebra])

A := Matrix([[2, -1, 1], [0, 1, 3], [0, 0, 1]]); b := Vector([-5, 7, 2]); sol := LinearSolve(A, b)

Matrix(3, 3, {(1, 1) = 2, (1, 2) = -1, (1, 3) = 1, (2, 1) = 0, (2, 2) = 1, (2, 3) = 3, (3, 1) = 0, (3, 2) = 0, (3, 3) = 1})

 

Vector(3, {(1) = -5, (2) = 7, (3) = 2})

 

LinearSolve(Matrix(%id = 36893488151878044716), Vector[column](%id = 36893488151878030628))

(2)

LinearSystemPlot({w = 2, y+3*w = 7, 2*x-y+w = -5}, axes = normal)

 

restart

with(plots); with(LinearAlgebra); A := Matrix([[1, 1], [12, 16]]); b := Vector([10, 136]); sol := LinearSolve(A, b); eq1 := x+y = 10; eq2 := 12*x+16*y = 136; plot1 := implicitplot(eq1, x = -5 .. 10, y = -50 .. 50, color = "red", thickness = 2, labels = ["x", "y"]); plot2 := implicitplot(eq2, x = -5 .. 10, y = -50 .. 50, color = "blue", thickness = 2); display(plot1, plot2, title = "Plot of Linear System", legend = [x+y = 10, 12*x+16*y = 136])

Matrix(2, 2, {(1, 1) = 1, (1, 2) = 1, (2, 1) = 12, (2, 2) = 16})

 

Vector(2, {(1) = 10, (2) = 136})

 

Vector[column](%id = 36893488153330030820)

 

x+y = 10

 

12*x+16*y = 136

 

 

A := Matrix([[2, -1, 1], [0, 1, 3], [0, 0, 1]]); b := Vector([-5, 7, 2]); solution := LinearSolve(A, b); eq1 := 2*x-y+z = -5; eq2 := y+3*z = 7; eq3 := z = 2; plot1 := implicitplot3d(eq1, x = -10 .. 10, y = -10 .. 10, z = -10 .. 10, color = "red", style = surface); plot2 := implicitplot3d(eq2, x = -10 .. 10, y = -10 .. 10, z = -10 .. 10, color = "blue", style = surface); plot3 := implicitplot3d(eq3, x = -10 .. 10, y = -10 .. 10, z = -10 .. 10, color = "green", style = surface); display(plot1, plot2, plot3, title = "3D Plot of Linear System", axes = boxed)

Matrix(3, 3, {(1, 1) = 2, (1, 2) = -1, (1, 3) = 1, (2, 1) = 0, (2, 2) = 1, (2, 3) = 3, (3, 1) = 0, (3, 2) = 0, (3, 3) = 1})

 

Vector(3, {(1) = -5, (2) = 7, (3) = 2})

 

Vector[column](%id = 36893488152610632156)

 

 

NULL


 

Download linear_systems.mw

 

OEIS A034828 and OEIS A000292 (which give the Wiener index for the cycle graph and the path graph respectively) mention that 

the Wiener index of the cycle of length 19 is 855 and 
the Wiener index of the path with 19 edges is 1330

However, 

GraphTheory:-WienerIndex(GraphTheory:-CycleGraph(19));
 = 
                               38

GraphTheory:-WienerIndex(GraphTheory:-PathGraph(20));
 = 
                               38

So what happened here? 

I was attempting to remove part of string using StringTools:-Remove()

But it causes server.exe crash each time.

Any idea why this happens?

Worksheet below

interface(version);

`Standard Worksheet Interface, Maple 2024.0, Windows 10, March 01 2024 Build ID 1794891`

Physics:-Version();

`The "Physics Updates" version in the MapleCloud is 1735. The version installed in this computer is 1732 created 2024, April 17, 19:33 hours Pacific Time, found in the directory C:\Users\Owner\maple\toolbox\2024\Physics Updates\lib\`

restart;

3048

ode:=x*y(x)*diff(y(x), x) = (x + 1)*(y(x) + 1):
ode:=diff(y(x), x$2) = (y(x) + 1):
the_output:=Student:-ODEs:-ODESteps(ode,y(x)):
 

s:=latex(the_output,'output'=string):

StringTools:-Remove(s,"\\begin{array}{ccc}");


Download crash_during_string_tools_remove_maple_2024.mw

ps. reported to Maplesoft also.

Maple dsolve fails to find many singular solutions using the option 'singsol'=all.

Any idea why that is? Here is one example

ode:=diff(y(x),x)=(y(x)-3)^2;
dsolve(ode,y(x),'singsol'=all)

It returns 

But we see that y=3 is singular solution which can't be obtained from the above solution for any value of c1

Mathematica finds this singular solution

ode=y'[x]==(y[x]-3)^2
DSolve[ode,y[x],x,IncludeSingularSolutions->True]

Here is second example.

restart;
ode:=diff(y(x),x)=2*x*sqrt(1-y(x)^2);
dsolve(ode,y(x),'singsol'=all)

Gives

But it misses the y=1,y=-1 singular solutions. 

Is there something I am doing wrong? Why does Maple sometimes fail to find singular solutions?

ps. reported to Mapesoft also.

Update

I remembered now a case similar to this. one has to use `Lie` solver and now Maple gives the singular solution

ode:=diff(y(x),x)=(y(x)-3)^2;
dsolve(ode,Lie,'singsol'=all)

There is no mention of this in help and it is still not clear to me if one has to always use Lie solver to obtain singsol or if this is just a coincidence for this one case.  

Same for the other case:

restart;
ode:=diff(y(x),x)=2*x*sqrt(1-y(x)^2);
dsolve(ode,'Lie','singsol'=all)

gives

I think singsol should work all the time and not only when using specific solver. If Lie solver is needed for singsol to work, then help should be clear and say this.

Consider the following exact algebraic number expr
 

restart;

kernelopts('version'):

Physics:-Version():

expr := Physics:-`*`(2-(1/2)/(1-(RootOf(16*_Z*(_Z*(2*_Z*(_Z*(8*_Z*(_Z*(_Z*(_Z*(32*_Z*(8*_Z-33)+1513)-812)-13)+267)-1469)-330)+811)+279)+345, index = 2)-1/2)^2), sqrt(1-(1-(1/2)/(1-(RootOf(16*_Z*(_Z*(2*_Z*(_Z*(8*_Z*(_Z*(_Z*(_Z*(32*_Z*(8*_Z-33)+1513)-812)-13)+267)-1469)-330)+811)+279)+345, index = 2)-1/2)^2))^2))+Physics:-`*`(Physics:-`*`(3+Physics:-`*`(4, 1-(1/2)/(1-(RootOf(16*_Z*(_Z*(2*_Z*(_Z*(8*_Z*(_Z*(_Z*(_Z*(32*_Z*(8*_Z-33)+1513)-812)-13)+267)-1469)-330)+811)+279)+345, index = 2)-1/2)^2)), 1/12), sqrt(3-Physics:-`*`(4, (1-(1/2)/(1-(RootOf(16*_Z*(_Z*(2*_Z*(_Z*(8*_Z*(_Z*(_Z*(_Z*(32*_Z*(8*_Z-33)+1513)-812)-13)+267)-1469)-330)+811)+279)+345, index = 2)-1/2)^2))^2)))+Physics:-`*`(Physics:-`*`(2, Physics:-`*`(2-(1/2)/(1-(RootOf(16*_Z*(_Z*(2*_Z*(_Z*(8*_Z*(_Z*(_Z*(_Z*(32*_Z*(8*_Z-33)+1513)-812)-13)+267)-1469)-330)+811)+279)+345, index = 2)-1/2)^2), 1/3)), sqrt(Physics:-`*`(Physics:-`*`(2, 2-(1/2)/(1-(RootOf(16*_Z*(_Z*(2*_Z*(_Z*(8*_Z*(_Z*(_Z*(_Z*(32*_Z*(8*_Z-33)+1513)-812)-13)+267)-1469)-330)+811)+279)+345, index = 2)-1/2)^2)), 1-Physics:-`*`(2, 1-(1/2)/(1-(RootOf(16*_Z*(_Z*(2*_Z*(_Z*(8*_Z*(_Z*(_Z*(_Z*(32*_Z*(8*_Z-33)+1513)-812)-13)+267)-1469)-330)+811)+279)+345, index = 2)-1/2)^2)))))+Physics:-`*`(Physics:-`*`(1+Physics:-`*`(2, 1-(1/2)/(1-(RootOf(16*_Z*(_Z*(2*_Z*(_Z*(8*_Z*(_Z*(_Z*(_Z*(32*_Z*(8*_Z-33)+1513)-812)-13)+267)-1469)-330)+811)+279)+345, index = 2)-1/2)^2)), 1/6), sqrt(Physics:-`*`(2, (1/4)/(1-(RootOf(16*_Z*(_Z*(2*_Z*(_Z*(8*_Z*(_Z*(_Z*(_Z*(32*_Z*(8*_Z-33)+1513)-812)-13)+267)-1469)-330)+811)+279)+345, index = 2)-1/2)^2)^2-Physics:-`*`(3, (1-(1/2)/(1-(RootOf(16*_Z*(_Z*(2*_Z*(_Z*(8*_Z*(_Z*(_Z*(_Z*(32*_Z*(8*_Z-33)+1513)-812)-13)+267)-1469)-330)+811)+279)+345, index = 2)-1/2)^2))^2)))):

CodeTools:-Usage(PolynomialTools:-MinimalPolynomial(expr));

memory used=0.97MiB, alloc change=12.00KiB, cpu time=31.00ms, real time=27.00ms, gc time=0ns

 

27*_X^2+70*_X-433

(1)

evalf[30](eval(27*_X^2+70*_X-433, _X = expr));

0.262508598220109180966e-6

(2)

"evalf((mp:=CodeTools:-Usage(evala(':-Minpoly'(expr,_X)))));"

memory used=70.25GiB, alloc change=48.00MiB, cpu time=23.63m, real time=21.81m, gc time=3.18m

 

-422.3889573*_X+2208.949800*_X^4-225.8139518*_X^3-230.2173498*_X^2+59.33811620+_X^10-19.92850932*_X^9+166.6440365*_X^8-755.9985571*_X^7+1997.484781*_X^6-3014.379082*_X^5

(3)

type(mp, polynom(rational, _X))

false

(4)


 

Download wrong_minpoly.mw 
I would like to find its minimal polynomial (without a priori knowledge). 

According to the documentation, 

if is an exact algebraic number, and and are not given, then PolynomialTools:-MinimalPolynomial(expr) will call  to compute an exact minimal polynomial of . If a name is not specified for the variable , then  will be used.

Regretfully, it is easy to see that the minimal polynomial of expr cannot be the returned 27*_X^2 + 70*_X - 433. And when I invoke  directly, the result is still not correct (and this evaluation takes a rather long time). 
Another help page mentions that 

the call mp := evala(Minpoly(expr, _X)) computes the monic minimal polynomial of  in the variable  over the field of rational numbers (or multivariate rational functions); the resulting polynomial will not contain any algebraic numbers or functions.

However, as type(mp, polynom(rational, _X)) gives , we know that cannot be the desired minimal polynomial of expr either. 
So, what is the proper way to compute the minimal polynomial of expr in Maple? 

Code: 

use alpha=1-(1/2)/(1-(RootOf(16*_Z*(_Z*(2*_Z*(_Z*(8*_Z*(_Z*(_Z*(_Z*(32*_Z*(8*_Z-33)+1513)-812)-13)+267)-1469)-330)+811)+279)+345,index=2)-1/2)**2) in 
	expr:=(1+alpha)*sqrt(1-alpha**2)+(3+4*alpha)/12*sqrt(3-4*alpha**2)+2*(1+alpha)/3*sqrt(2*(1+alpha)*(1-2*alpha))+(1+2*alpha)/6*sqrt(2*((1-alpha)**2-3*alpha**2)) 
end:
CodeTools:-Usage(PolynomialTools:-MinimalPolynomial(expr));

Of note, the minimal polynomial of an algebraic number zeta is the unique irreducible monic polynomial of smallest degree p(x) with rational coefficients such that p(zeta)=0 and whose leading coefficient is 1

As the following worksheet shows, 
 

restart

kernelopts('version');

Physics:-Version();

`Maple 2024.0, X86 64 WINDOWS, Mar 01 2024, Build ID 1794891`

`The "Physics Updates" version in the MapleCloud is 1732 and is the same as the version installed in this computer, created 2024, April 12, 17:58 hours Pacific Time.`

with(RealDomain):

eval(MTM:-det(<
   a, b/2, d/2 |
   b/2, c, e/2 |
   d/2, e/2, f
  >), PDETools:-Solve(MTM:-det(<
     x**2 + y**2, x1**2 + y1**2, x2**2 + y2**2, x3**2 + y3**2 |
     x, x1, x2, x3 |
     y, y1, y2, y3 |
     1, 1, 1, 1
    >) = inner([a, b, c, d, e, f], [x**2, x*y, y**2, x, y, 1]),
   {f, e, d, c, b, a}, 'independentof' = {y, x}))/MTM:-det(<
  x1, x2, x3 |
  y1, y2, y3 |
  1, 1, 1
 >): simplify(`%`);

-(1/4)*(x1^2-2*x1*x2+x2^2+(y1-y2)^2)*(x2^2-2*x2*x3+x3^2+(y2-y3)^2)*(x1^2-2*x1*x3+x3^2+(y1-y3)^2)

eval(MTM:-det(<
   a, b/2, d/2 |
   b/2, c, e/2 |
   d/2, e/2, f
  >), PDETools:-Solve(MTM:-det(<
     x**2 - y**2, x1**2 - y1**2, x2**2 - y2**2, x3**2 - y3**2, x4**2 - y4**2 |
     x*y, x1*y1, x2*y2, x3*y3, x4*y4 |
     x, x1, x2, x3, x4 |
     y, y1, y2, y3, y4 |
     1, 1, 1, 1, 1
    >) = inner([a, b, c, d, e, f], [x**2, x*y, y**2, x, y, 1]),
   {f, e, d, c, b, a}, 'independentof' = {y, x}))/(MTM:-det(<
   x2, x3, x4 | 
   y2, y3, y4 | 
   1, 1, 1
  >)*MTM:-det(<
   x3, x4, x1 | 
   y3, y4, y1 | 
   1, 1, 1
  >)*MTM:-det(<
   x4, x1, x2 | 
   y4, y1, y2 | 
   1, 1, 1
  >)*MTM:-det(<
   x1, x2, x3 | 
   y1, y2, y3 | 
   1, 1, 1
  >)): simplify(`%`);

(1/4)*((x2-x3)*x1-x2*x4+x3*x4+(y2-y3)*(y1-y4))*((x3-x4)*x1+(x4-x3)*x2+(y3-y4)*(y1-y2))*((x2-x4)*x1-x2*x3+x3*x4+(y2-y4)*(y1-y3))


 

Download Why_not_consider_subexpressions?.mw

the underlined part is evidently not the simplest. (For instance, shouldn't RealDomain:-simplify(x2^2 - 2*x2*x3 + x3^2 + (y2 - y3)^2, 'size') and RealDomain:-simplify((x2-x3)*x1-x2*x4+x3*x4+(y2-y3)*(y1-y4), 'size') be converted into RealDomain:-simplify((x2 - x3)^2 + (y2 - y3)^2, 'size') and RealDomain:-simplify((x2 - x3)*(x1 - x4) + (y2 - y3)*(y1 - y4), 'size')?) 
If I understand correctly, , by default, should try combining every part of an expression with every other to apply a vast range of potential transformations to look at many different forms of it and make progress in picking out the simplest possible one. So, why is simplify unable to touch certain sub-expressions when they are encountered at intermediate stages in a computation? 

Could someone be able to spot why I get different solution when solving for the constant of integration from this Maple dsolve solution manually than when asking Maple to do it directly?

This is the ode 

ode:=x*y(x)*diff(y(x), x) = (x + 1)*(y(x) + 1);
ic:=y(1) = 1;

If I ask Maple to solve it with the IC all at once, it gives solution which odetest verifies OK.

If I ask Maple to solve it with no IC, then solve the constant myself and plug the constant back into the solution I get solution which does not verify any more.

I am not able to find why. Could someone spot the error in this? Please see worksheet below. I suspect the problem is when plugging back the constant of integration into the general solution, but have no idea now what it is. Clearly Maple did something much smarter than what I did by just plugging the constant back into the solution. May be need to specify what branch to use when plugging the constant back? but how do I know which one?
 

interface(version);

`Standard Worksheet Interface, Maple 2024.0, Windows 10, March 01 2024 Build ID 1794891`

Physics:-Version()

`The "Physics Updates" version in the MapleCloud is 1730 and is the same as the version installed in this computer, created 2024, April 17, 19:33 hours Pacific Time.`

ode:=x*y(x)*diff(y(x), x) = (x + 1)*(y(x) + 1);
ic:=y(1) = 1;
sol_no_IC:=dsolve(ode);
 

x*y(x)*(diff(y(x), x)) = (x+1)*(y(x)+1)

y(1) = 1

y(x) = -LambertW(-exp(-x-1)/(x*c__1))-1

sol_with_IC_direct:=dsolve([ode,ic]);
odetest(sol_with_IC_direct,[ode,ic]);

y(x) = -LambertW(-1, -2*exp(-x-1)/x)-1

[0, 0]

#this verifies Maple found correct constant also:

solve(rhs(sol_with_IC_direct)=rhs(sol_no_IC),c__1)

1/2

#now solve for constant of integration manually. This gives invalid solution. Why?

eq:= 1=limit(rhs(sol_no_IC),x=1);

1 = -LambertW(-exp(-2)/c__1)-1

PDEtools:-Solve(eq,c__1);

c__1 = 1/2

sol_with_ic:=eval(sol_no_IC,%)

y(x) = -LambertW(-2*exp(-x-1)/x)-1

odetest(sol_with_ic,[ode,ic]);

[0, 2+LambertW(-2*exp(-2))]

 

 

Download why_wrong_solution.mw

In my view, <x || (1 .. 2); y || (1 .. 2); 1 $ 2> should return a Matrix without any error messages; however, 

<x || (1 .. 2); y || (1 .. 2); 1 $ 2>; # Arguments are shielded??? 
Error, (in Matrix) this entry is too wide or too narrow: 1

If I understand right, each argument of a function is evaluated in turn (unless the modifier is used). 
So why is it not equivalent to <x1, x2; y1, y2; 1, 1>

 

I am trying to find the minimum values of a table, but not of all of its indices, just some that comply to a certain pattern.

The minimum of the values of a table are found by using min(entries(atable)).

If the indices of atable are "a1", "a2", "b1", "b2", I would like to just have the ones starting with "a".

Can be done by a loop, but is there a easier way?

I any trying to seperate the real and imaginary components but they are mixed up inside and outside a square root.

Their seems to be a problem displaying the worksheet.

restart



expand((a+I*b)*(a-I*b))
(a+I*b)+(a-I*b)
# z = x *Iy    I need to seperate out solution to [x,y] & [x,-y]
#https://math.stackexchange.com/questions/44391/foci-of-a-general-conic-equation
eq := T*z^2 - (R + S*I)*z +G-K + H*I
sol:=solve(eq,z)
expand(sol[1]*sol[2])=a^2+b^2
simplify(sol[1]+sol[2]=2*a)
simplify(sol[1]-sol[2]=2*b)

Maple Worksheet - Error

Failed to load the worksheet /maplenet/convert/2024-04-20_Q_Seperate_Real_&_Imaginary.mw .

Download 2024-04-20_Q_Seperate_Real_&_Imaginary.mw

Is it wrong to call limit like this

limit(expr,[y = y0,x=x0]);

vs

limit(expr,y = y0);
limit(%,x=x0);

The first one gives internal Maple error.  Worksheet attached. I would have expected both to work the same.

interface(version);

`Standard Worksheet Interface, Maple 2024.0, Windows 10, March 01 2024 Build ID 1794891`

Physics:-Version();

`The "Physics Updates" version in the MapleCloud is 1727 and is the same as the version installed in this computer, created 2024, April 17, 19:33 hours Pacific Time.`

kernelopts('assertlevel'=2):

expr:=3/2*(y-1)^(2/3)-3/2*x^2-c__1 = 0;
y0:=-7;
x0:=3;
limit(expr,[y = y0,x=x0]);
 

(3/2)*(y-1)^(2/3)-(3/2)*x^2-c__1 = 0

-7

3

Error, (in limit/multi/ldegree1) assertion failed

expr:=3/2*(y-1)^(2/3)-3/2*x^2-c__1 = 0;
y0:=-7;
x0:=3;
limit(expr,y = y0);
limit(%,x=x0);

(3/2)*(y-1)^(2/3)-(3/2)*x^2-c__1 = 0

-7

3

-3+(3*I)*3^(1/2)-(3/2)*x^2-c__1 = 0

-33/2+(3*I)*3^(1/2)-c__1 = 0

 

 

Download limit_internal_error_maple_2024.mw

I still see these Maple internal errors in Maple 2024.

Now calling odetest.

The problem is that it is not possible to catch them.

Any suggestion what to do and what causes it?

11196

interface(version);

`Standard Worksheet Interface, Maple 2024.0, Windows 10, March 01 2024 Build ID 1794891`

Physics:-Version();

`The "Physics Updates" version in the MapleCloud is 1727 and is the same as the version installed in this computer, created 2024, April 17, 19:33 hours Pacific Time.`

sol:=y(x) = (exp(RootOf(-sin(x)*tanh(1/2*_Z+1/2*c__1)^2+sin(x)+exp(_Z)))+sin(x))/sin(x);
ode:=diff(y(x),x)-cot(x)*(y(x)^(1/2)-y(x)) = 0;

y(x) = (exp(RootOf(-sin(x)*tanh((1/2)*_Z+(1/2)*c__1)^2+sin(x)+exp(_Z)))+sin(x))/sin(x)

diff(y(x), x)-cot(x)*(y(x)^(1/2)-y(x)) = 0

try
   odetest(sol,ode,y(x));
catch:
   print("cought error ");
end try;

Error, (in anonymous procedure called from depends) too many levels of recursion

 

 

Download too_many_levels_of_recursion_calling_odetest_maple_2024.mw

Hopefully, this is a question relating to Mathematica, which I find virtually unreadable, and the Statistics package, which I am minimally familiar with, that someone can answer quickly.

Hence, could someone translate the following Mathematica code into Maple code? (The MmaTranslator failed at the 2nd line.)

func[x_] := 1/(1 + Sinh[2*x]*(Log[x])^2);

Distrib[x_, average_, var_] :=   PDF[NormalDistribution[average, var], 1.1*x - 0.1];
n = 10;
RV = RandomVariate[TruncatedDistribution[{0.8, 3}, NormalDistribution[1, 0.399]], n];
Int = 1/n Total[func[RV]/Distrib[RV, 1, 0.399]]*Integrate[Distrib[x, 1, 0.399], {x, 0.8, 3}]
3 4 5 6 7 8 9 Page 5 of 9