Maple 2021 Questions and Posts

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

I would like to open a specially formatted document from start/new document. I set  up one with a fixed width table to make it easy to print to A4. I find the very useful for taking notes.

Currently I just save it as  a usual document. The attached shows the basic setup I use. Contents arn't too relivant.

restart

``

 

 

 

"R(m2,m3,m4,...)≡((2 m2+3 m3+4 m4+...)!)/((1+m2+2 m3+3 m4+...)!m2!m3!m4!...)"

 

 

  

Xterm := factorial(2*m+3*n+4*p+5*q)*c[2]^m*c[3]^n*c[4]^p*c[5]^q/(factorial(1+m+2*n+3*p+4*q)*factorial(m)*factorial(n)*factorial(p)*factorial(q))

factorial(2*m+3*n+4*p+5*q)*c[2]^m*c[3]^n*c[4]^p*c[5]^q/(factorial(1+m+2*n+3*p+4*q)*factorial(m)*factorial(n)*factorial(p)*factorial(q))

(1)

k := 5

5

(2)

x := add(add(add(add(Xterm, q = 0 .. 4*k), p = 0 .. 3*k), n = 0 .. 2*k), m = 0 .. k)

nops(x)

22176

(3)

NULL

nops(TestPoly)

1

(4)

ldegree(TestPoly)

1

(5)

NULL

NULL

NULL
NULL

mtaylor(TestPoly, [c[2], c[3], c[4], c[5]], k+2)

TestPoly

(6)

C1 := 1; C2 := -2; C3 := 3; C4 := -4; C5 := 5

5

(7)

Poly1 := expand((y+C1)*(y+C2)*(y+C3)*(y+C4)*(y+C5))

y^5+3*y^4-23*y^3-51*y^2+94*y+120

(8)

NULL

Poly1 := Poly1/coeff(Poly1, y, 0)

(1/120)*y^5+(1/40)*y^4-(23/120)*y^3-(17/40)*y^2+(47/60)*y+1

(9)

NULL

Poly1 := expand((y+C1)*(y+C2)*(y+C3)*(y+C4)*(y+C5))

y^5+3*y^4-23*y^3-51*y^2+94*y+120

(10)

NULL

Poly1 := Poly1/coeff(Poly1, y, 0)

(1/120)*y^5+(1/40)*y^4-(23/120)*y^3-(17/40)*y^2+(47/60)*y+1

(11)

fsolve(Poly1, y)

-5., -3., -1., 2., 4.

(12)

coeff(Poly1, y, 1)

47/60

(13)

Poly2 := algsubs(y = -z/coeff(Poly1, y, 1), Poly1)

-(6480000/229345007)*z^5+(324000/4879681)*z^4+(41400/103823)*z^3-(1530/2209)*z^2-z+1

(14)

"(->)"

-0.28254e-1*z^5+0.66398e-1*z^4+.39876*z^3-.69262*z^2-1.*z+1.

(15)

"(->)"

 

solve(Poly2, z)

-47/30, -47/15, 47/12, 47/20, 47/60

(16)

-%/coeff(Poly1, y, 1)

2, 4, -5, -3, -1

(17)

NULL

 

 

``

``

NULL

Download A4_format.mw

I can't move files in the navigator window anymore in Maple 2021.2.

Anyone else with the same problems?

sometimes complicated equation is generated and attempt to solve it fail, which is OK. But there is a case, where Maple generates an internal error from solve(). The problem is that it is not possible to even capture this error using try...catch... end try so the whole program crashes.

Is there a way to trap such errors, so at least it can bypass it without solving it but without terminating the whole program? 

According to help it says

The try statement provides a mechanism for executing statements in a controlled environment, where errors will not just cause the execution to halt with no warning.

Well. The above is not really true.

interface(version);

`Standard Worksheet Interface, Maple 2021.2, Windows 10, November 23 2021 Build ID 1576349`

Physics:-Version()

`The "Physics Updates" version in the MapleCloud is 1115 and is the same as the version installed in this computer, created 2021, December 15, 10:0 hours Pacific Time.`

restart;

eq:=-t^m*y+1/12*(-6*(-(108+12*(6144*(t^m)^3*y^3+81)^(1/2))^(2/3)+96*t^m*y)/(108+12*(6144*(t^m)^3*y^3+81)^(1/2))^(1/3))^(1/2)+1/12*6^(1/2)*((-(-6*(-(108+12*(6144*(t^m)^3*y^3+81)^(1/2))^(2/3)+96*t^m*y)/(108+12*(6144*(t^m)^3*y^3+81)^(1/2))^(1/3))^(1/2)*(108+12*(6144*(t^m)^3*y^3+81)^(1/2))^(2/3)+96*t^m*y*(-6*(-(108+12*(6144*(t^m)^3*y^3+81)^(1/2))^(2/3)+96*t^m*y)/(108+12*(6144*(t^m)^3*y^3+81)^(1/2))^(1/3))^(1/2)+72*(108+12*(6144*(t^m)^3*y^3+81)^(1/2))^(1/3))/(108+12*(6144*(t^m)^3*y^3+81)^(1/2))^(1/3)/(-6*(-(108+12*(6144*(t^m)^3*y^3+81)^(1/2))^(2/3)+96*t^m*y)/(108+12*(6144*(t^m)^3*y^3+81)^(1/2))^(1/3))^(1/2))^(1/2) = t^(m-1)*(-y+1/12*(-6*(-(108+12*(6144*y^3+81)^(1/2))^(2/3)+96*y)/(108+12*(6144*y^3+81)^(1/2))^(1/3))^(1/2)+1/12*6^(1/2)*((-(-6*(-(108+12*(6144*y^3+81)^(1/2))^(2/3)+96*y)/(108+12*(6144*y^3+81)^(1/2))^(1/3))^(1/2)*(108+12*(6144*y^3+81)^(1/2))^(2/3)+96*y*(-6*(-(108+12*(6144*y^3+81)^(1/2))^(2/3)+96*y)/(108+12*(6144*y^3+81)^(1/2))^(1/3))^(1/2)+72*(108+12*(6144*y^3+81)^(1/2))^(1/3))/(108+12*(6144*y^3+81)^(1/2))^(1/3)/(-6*(-(108+12*(6144*y^3+81)^(1/2))^(2/3)+96*y)/(108+12*(6144*y^3+81)^(1/2))^(1/3))^(1/2))^(1/2)):

sol:=solve(eq,m)  assuming t>0;

Error, (in PolynomialSystemSolvers:-PseudoResultant) too many levels of recursion

try
    sol:=solve(eq,m)  assuming t>0;
catch:
    print("Cought error");
end try;

Error, (in PolynomialSystemSolvers:-PseudoResultant) too many levels of recursion

 

Download dec_16_2021.mw

Other than saving few bytes of memory, why would one use ::static for methods of Object?

I found that if I use ::static, then I have to add prefix _self:- each time an object data member is referenced anywhere, making the code very hard to read.

Imagine having to write  _self:-x + 3* _self:-x^2 + 2* _self:-y^3 and so on all the time, instead of just x+3*x^2+2*y^3. (where it is assumed here that x,y happened to be object private data members and not local variables for a proc inside the module).

But then I found if I remove  ::static now _self:- no longer needed and can still get the benefit of using the object and the code works as before, but the code is now much more readable. 

I know that by not using static, then a copy of each method is made for each new object.

I am OK with that. As I do not use that many objects any way (few at a time before GC cleans the ones I used).

But the benefit of much more readable code far outweights the little extra memory needed, and memory is cheap these days anyway. I got lots of RAM. An extra few MB's is not a big deal.

What Am I missing here? Why does all the Maple help and documenation say that one should use static for object methods then? But do not mention that by not using static:: then the code will become more readable since _self:- is not needed to be appeneded to each variable or method name.

Here is an example below to compare. 

First example uses ::static methods, and the second does not.

One can see the difference The code is more clear in the second.   Is there something else I am overlooking by not using ::static . I am still learning OOP in Maple, and could be overlooking something else. I definitly do not want to code using _self:-variable_name all the time if I have to use OOP in Maple as it makes the code hard to read. 

Notice that in both examples, and for the exported methods, I used _self as first argument. This is OK. This is meant to allow client of the object to call it using object:-method() syntax which is what I prefer instead of method(object,....). syntax.

I am talking about the execssive use of _self internal to the module/object code when having to use ::static. methods.

restart;

person_class_STATIC:=module()
   option object;
   local age:=5;   

   export set_age::static:=proc(_self,age,$)      
     _self:-age:=age:
   end proc:      

   export update_age::static:=proc(_self,age,$)      
      do_the_update(_self)
   end proc:      

   local do_the_update::static:=proc(_self,$)
      _self:-age:=_self:-age+1;
      _self:-age:=sqrt(_self:-age^2+3);
   end proc;

   export get_age::static:=proc(_self,$)      
     return _self:-age;
   end proc:      

end module:

o:=Object(person_class_STATIC);
o:-set_age(100);
o:-get_age();
o:-update_age();

o2:=Object(person_class_STATIC);
o2:-get_age();

_m1982588380672

100

100

2*2551^(1/2)

_m1982698669216

5

person_class_NO_STATIC:=module()
   option object;
   local age:=5;   

   export set_age:=proc(_self,_age,$)      
     age:=_age:
   end proc:      

   export update_age:=proc(_self,$)      
      do_the_update()
   end proc:      

   local do_the_update:=proc()
      age:=age+1;
      age:=sqrt(age^2+3);
   end proc;

   export get_age:=proc(_self,$)      
     return age;
   end proc:      

end module:

o:=Object(person_class_NO_STATIC);
o:-set_age(100);
o:-get_age();
o:-update_age();

o2:=Object(person_class_NO_STATIC);
o2:-get_age();

_m1982698652256

100

100

2*2551^(1/2)

_m1982698629312

5

 

Download OOP.mw

Without trying it or looking down more, should these two code fragments give same output or not

# CASE 1

restart;
A   :=   2;
B   :=   x+2*y;
t^2 * ( A * B );


#CASE 2
restart;
t^2*( 2 * (x+2*y)  );

One would expect both to give same output, right? CASE 1 just uses variables and CASE 2 just uses the values of these variables. I mean the semantics of CASE 1 and 2 are the same, given that Maple replaces each variable with its value when evaluating.

But Maple does not give same result.

One way to force same result when using variables is to use t^2*(eval(A*B));

My question is why CASE 1 gives different result from CASE 2?  I would have expected same output.

Maple 2021.2 on windows 10. Worksheet.

interface(version);

`Standard Worksheet Interface, Maple 2021.2, Windows 10, November 23 2021 Build ID 1576349`

restart;

A:=2;
B:=x+2*y;
t^2*(A*B);

2

x+2*y

2*t^2*(x+2*y)

restart;

t^2*(2*(x+2*y));

t^2*(2*x+4*y)

restart;

A:=2;
B:=x+2*y;
t^2*(eval(A*B));

2

x+2*y

t^2*(2*x+4*y)

 

Download why_different.mw

How do i code when i have to locate all maximum and minimum values, intervals of increase and decrease, and inflection points.

Thanks 

Why would simplify(t^2*x^2+t^2*y^2)  give  (x^2 + y^2)*t^2 but with seemingly same input except changing `+` to `-` fails now to simplify it?  simplify(t^2*x^2-t^2*y^2) gives t^2*x^2-t^2*y^2

Just trying to understand the logic behind this behavior.

In Mathematica both do simplify as can be seen below, which is what one would expect.

Should Maple hangs when one quits a debugger in the middle of debugging session, and there is a call to the same function with a DEBUG break point in it next?

For example

restart;
foo:=proc()
  local x;
  DEBUG();
  x:=x+1
end proc;

And now in the next same execution group, I had

> foo(); #quitting debugger here makes Maple hangs/freeze

  foo();

 

When evaluating the above, the debugger comes up as expected when first call to foo() is made.

When quitting the debugger either by hitting Quit or by hitting the close red X at top right corner, Maple now hangs. I was expecting the debugger to come up again for the second call to foo().  

It seems closing the debugger window like this for some reason is not handled correctly. Even if the user is not supposed to do this, Maple should not just freeze like this.

Nothing I do causes it to unfreeze. Clicking on the ! button does nothing. Only way is to either kill Maple from task manager or close all of Maple if possible and sometimes this does not even work, ending possibly losing work done on other open worksheets.

Maple should be more robust that this. Does this happen on other platforms?

This problem does not happen if the calls were each in a separate execution group in the worksheet. Like this

> foo();

> foo();

Using Maple 2021.2 on windows 10.

 

VertexConnectivity returns the vertex connectivity of a graph, that is the minimum number of vertices whose removal disconnects the graph.  When I was filtering some graphs with a certain  vertex connectivity, maple was much slower than mathematica. I'm going to store all graphs in file  named op21new.g6.  When mathematica selects all graphs with a connectivity of 6, it only takes 15 seconds to complete.

mma codes are the following 

L = Import[
  "C:/Users/asus/Desktop/op21new.g6"]; # Change this line
t = AbsoluteTiming[L1 = Select[L, VertexConnectivity[#] == 6 &];]

{15.6484, Null}

But my maple has been running for half an hour and it is not over yet.

with(GraphTheory):
L:=ImportGraph("C:/Users/asus/Desktop/op21new.g6", graph6, output=list): # Change this line
L2:=CodeTools:-Usage(select(g->VertexConnectivity(g)=6,L)):

Because Mapleprimes does not support graph6 format file uploading, I changed it to TXT format. If you want to use it, you only need to change the suffix name.

op21new.txt

I am trying to anime a pump but itn't working. I need help. Thank you. restart; with(plots); with(plottools); unprotect(D); alpha := arctan(-58/62.5); solve({k*Pi/100 = alpha}, {k}); beta := arctan(19/84); solve({k*Pi/100 = beta}, {k}); ang1 := arctan(-68/84); evalf(solve({k = ang1}, {k})); ang2 := arctan(55/84); evalf(solve({k = ang2}, {k})); #angular head travel Head := proc(k) local r, poly, k1, tC, tD, tE, DikC, DikD, DikE; global C, D, E; r := 84; C := [-55, 17]; D := [0, 0]; E := [84, 0]; poly := [[-60, 24], [63, -17], [60, -55.5], seq([r*cos(1/100*k*Pi), r*sin(1/100*k*Pi)], k1 = -24 .. 7), [82, 18], [78, 20], [64, -3], [-46.5, 35]]; tC := textplot([C[], "C"], align = {above, right}, font = [Times, bold, 18]); tD := textplot([D[], "D"], align = {above, left}, font = [Times, bold, 18]); tE := textplot([E[], "E"], align = {above, left}, font = [Times, bold, 18]); DikC := disk(C, 1, color = black); DikD := disk(D, 1, color = black); DikE := disk(E, 1, color = black); if 0

I am looking for a robust way to factor an expression (if applicable) to become    x^n*(rest)  as we do it by hand.

edit The input will only be of type `+` and I am looking for a way extract a common factor to convert the input to term^n*(rest) where term is the common factor to pull out.

For example, given  x^2*Y+x and the symbol is given as x  the result will be x*(x*Y+1) and if the input is Y^2*x^3-x^3 then the output is x^3*(Y^2-1) and if there is no common factor x to pull out from all the terms, the output will be the same as the input.

I tried many commands and options, but can't find one method that works all the time for all cases.

For example for   x^2*Y+x  the command factor(x^2*Y+x) gives (Y - 1)*(Y + 1)*x^3 which is not what I want. There is no option to factor to give the name to factor on. And I did not know how to use the last argument of function to do that.

But here simplify(x^2*Y+x) happened to work on this and gives (Y^2 - 1)*x^3 but simplify does not work on first example. simplify(x^2*Y+x) returns the same expression back. So simplify is not reliable to use.

I tried collect, with options factor and simplify. Again, they work on one examples but not others. 

collect(x^2*Y+x,x); does not do it. But collect(Y^2*x^3-x^3,x); works and returns (Y^2 - 1)*x^3 which is what I want.

The problem is that I do not know what the expression looks like. I just know the name and want to find if there is a common to any power that can be pulled out to rewite the expression as x^n*(rest) where is an integer or rational number depending.

This seems like a simple problem. But can't find a Maple command for.   I could ofcourse program it by brute force. Go over each term in the expression, check if each term has a free to any power in it multiplied by something else, then collect all these x^n term in a list. At end find the which is raised to lowest power, and then divide the whole expression by it. 

Here is another way I can also try:  Use factor and also collect and also simplify. One at a time. Each time I check if the result is of type `*` but not a division! (check that denom is 1). If so, Then check if result has two operands only. If so, check if op(1,result) is for form x^anything. If so, then one of these cases worked.  Need to try this now to see if it will work on all cases I have. 

Is there a better way to do this in Maple? It has to work on all expresions f(x) without knowing what the expression looks like.

update

I've updated the test cases and included all algorithms given to compare. It is hard in Maple to make a nice table to present results and keep math formatting below.

restart;
makegrid := proc(M::Matrix)#https://www.mapleprimes.com/questions/202902-How-To-Create-Table-Like-Output-For
  uses DocumentTools:-Layout;
  local i,j,m,n,wks;
  m,n := op(1,M);
  wks := Worksheet(Table(alignment=center,width=20,
                         seq(Column(),j=1..n),
                         seq(Row(seq(Cell(Textfield(sprintf("%a",M[i,j]))),
                                     j=1..n)),i=1..m)));
  DocumentTools:-InsertContent(wks);
end proc:

acer_V1_common_factor := proc(x::algebraic, ee::algebraic)
  local p, d := gcd(ee, x^frontend(degree,[ee,x]),'p');
  d * p;
end proc:

acer_V2_common_factor := proc(x, ee) local d, t;
  if ee::`+` then
    t := max(map(proc(u) local r:=frontend(degree,[u,x]);
                         `if`(r::numeric,r,0); end proc,[op(ee)]));
    d := gcd(numer(ee),x^t);
    d*map(u->u/d,ee);
  else ee; end if;
end proc:

dharr_common_factor:=proc(x,z)
  local xn:=x^ldegree(collect(z,x),x);
  if rem(z,xn,x)=0 then xn*quo(z,xn,x) else z end if;
end proc:

me_common_factor:=proc(term,expr)
local tmp;
local T1;

local update_T1:=proc()
T1:= hastype(op(1,tmp),identical(term)^anything) or hastype(op(1,tmp),identical(term));
if not T1 then
   T1:= hastype(op(2,tmp),identical(term)^anything) or hastype(op(2,tmp),identical(term));
fi;
end proc;

if type(expr,`*`) or not has(expr,term) then 
   return expr;
fi;

tmp := collect(expr,term);       
if type(tmp,`*`) and evalb(denom(tmp)=1) and evalb(nops(tmp)=2) then
   update_T1();
   if T1 then
       return tmp;
   fi;
fi;

tmp :=factor(expr);
if type(tmp,`*`) and evalb(denom(tmp)=1) and evalb(nops(tmp)=2) then
    update_T1();
    if T1 then
      return tmp;
    fi;
fi;

tmp := simplify(expr);
if type(tmp,`*`) and evalb(denom(tmp)=1) and evalb(nops(tmp)=2) then
    update_T1();
    if T1 then              
      return tmp;
    fi;
fi;

return expr;
end proc:
############################

test_data:=[[x,x^2*Y+x],
[x,Y^2*x^3-x^3],
[x,x],
[x,x+2*x^2],
[x,x^4*diff(y(x),x)+x^7],
[x,x^4*diff(y(x),x)+x^7-sin(x)],
[y(x),y(x)^4*diff(y(x),x$2)^2*diff(y(x),x)+y(x)^2*diff(y(x),x)+y(x)],
[y(x),y(x)^4*diff(y(x),x$2)^2+y(x)^2*diff(y(x),x)+y(x)^9],
[x,x^4*y^2+x^2*y^2],
[y(x),y(x)^4*diff(y(x),x)^2+y(x)^2*diff(y(x),x)^2],
[diff(y(x),x),y(x)^4*diff(y(x),x)^2+y(x)^2*diff(y(x),x)^2],
[diff(y(x),x),y(x)*diff(y(x),x$2)^2*diff(y(x),x)*sin(x)+diff(y(x),x)^3],
[y(x),diff(y(x),x)-(1+x^(1/2))/(1+y(x)^(1/2))],
[y(x),diff(y(x),x) -(x-1)*y(x)^5/x^2/(-y(x)+2*y(x)^3)],
[y(x),3*y(x)+diff(y(x),x) - 2*x/exp(3*x)],
[x,3*x^2*y^3+7*x/y],
[y,A-(1+x)/(1+y^(1/2))]
]:
RESULT:=Matrix(nops(test_data),6);
for N,item in test_data do
    term:=item[1];
    expr:=item[2];
    RESULT[N,1]:=term; RESULT[N,2]:=expr;
    try
        result:=acer_V1_common_factor(term,expr);
        if type(result,`*`) and denom(result)<>1 then
           RESULT[N,3]:=expr;#bypass, not correct output
        else
           RESULT[N,3]:=result;#accept
        fi;  
    catch:
        RESULT[N,3]:=expr;#reject
    end try;      

    try
        result:=acer_V2_common_factor(term,expr);
        if type(result,`*`) and denom(result)<>1 then
           RESULT[N,4]:=expr;#bypass, not correct output
        else
           RESULT[N,4]:=result;#accept
        fi;  
    catch:
        RESULT[N,4]:=expr;#reject
    end try;      

    try
        result:=dharr_common_factor(term,expr);
        if type(result,`*`) and denom(result)<>1 then
           RESULT[N,5]:=expr;#bypass, not correct output
        else
           RESULT[N,5]:=result;#accept
        fi;  
    catch:
        RESULT[N,5]:=expr;#reject
    end try;      


    try
        result:=me_common_factor(term,expr);
        if type(result,`*`) and denom(result)<>1 then
           RESULT[N,6]:=expr;#bypass, not correct output
        else
           RESULT[N,6]:=result;#accept
        fi;  
    catch:
        RESULT[N,6]:=expr;#reject
    end try;      

od:

RESULT

how_to_do_special_factor.mw

Mapleprime will not let let insert content for some reason. Here is the output as screen shot but it is hard to read. But it is in the above worksheet.

Hello everyone,

I purchased Maple 2021 student version. I am using a Linux Ubuntu 20.04 machine. The machine is my personal computer, so there is no user access privilege restriction. I installed Maple using the GUI, and at the activation step, I get an error that says "Missing host ID for license server". I remember an option for servers or personal PC during download. I am confident that I chose the personal PC option.

Kind regards, and I look forward to hearing from you.

Hey guys,

How can I create a bar chart or a column chart, with specific x values under the bars.

Would be great If someone could help me.

Thank you;) 

help under object it says  (in Maple 2021)

The above has not been true for almost a year. Since in Maple 2021 one can do o:-m() 

person_class :=module()
  option object;
  export m:=proc(_self,$)
      print("you called me");
  end proc;
end module;

o:=Object(person_class);
o:-m()

            person_class := Object<<1758956556512>>
                  o := Object<<1758955674784>>
                        "you called me"

I hope this gets updated in Version 2022,  with examples also. The notation o:-method() is hidden in help and could not even find it, but it is meantioned in some pdf file which I lost track of at this moment. 

On another help page titled Overview of Object Methods it briefly mentions alternative call but the link that is supposed to explain it does not work. (clicking on it, produces nothing. Stays on same page). I guess no one tried this link before shipping Maple. 

Is this link somewhere to access directly in the help page?

How can factorise a polynomial with complex roots, without showing their numerical values of the roots, but only their symbolical value.

For example I have:

factor(x^4 - x^2 + x - 1)

and it shows me the following factorisation: (x-1)(x^3+x^2+1) but I want to also factorise x^3+x^2+1 but the roots should be displayed symbolically without numerical values of these roots. Then how to implement this task?

In the book I am reading it's stated to use factor(x^4-x^2+x-1, I), but it doesn't seem to be working.

2 3 4 5 6 7 8 Last Page 4 of 20