Maple 2021 Questions and Posts

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

I noticed Maple changes 1/(4*(x-2)) to 1/(4*x-8)  when copying the output and pasting it back to the worksheet.  

But in the variable it does remain 1/(4*(x-2))  which is what I wanted, as I am going to look for this form later on and I do not want it expanded.

But I am curious why Maple does this. It is a little annoying when copying something from one worksheet to another and have it change.  Here is a small movie and the code to see it. 

Is there a way to prevent this automatic expansion?  Maple 2021.2 on windows 10

 

code

r:=(x^4-8*x^3+24*x^2-24*x+12)/((4*x^2*(x-2)^2)):
rf:=convert(r,fullparfrac,x);

I use worksheet interface and have my display settings as the following

As a Maple user for 10+ years, I've had plenty of stack limit errors, pretty much all of them my fault. But I am currently experiencing a very unusual one after updating my Mac from Maple 2019 to Maple 2021.2.

I am running a long script to fetch json data from a url, parse it, and do a bunch of analysis. In most cases it works fine, but some cases give either an "Execution stopped: Stack limit reached." error, or the error "Error, (in type/polynom) result from type `algfun` must be true or false". Both are being caused by calling the gfun:-ratpolytocoeff command.

I kind of think some internal memory of Maple is being accidentally overwritten because I can cause the error to occur or not occur by adding / commenting out random lines of code that have nothing to do with the part of the code causing the problem. I've managed to find a fairly small script that causes the problem to occur:

with(PolynomialIdeals):
url := "https://api.combopal.ru.is/garpur_run/61e5f7acf2e929ff811caad3":

root_func := F[0, x]:

latex:-Settings(useimaginaryunit=i):

data := URL[Get](url):
json := JSON[ParseString](data):
json := JSON[ParseString](data):

debug_solved := (x^5-3*x^4+5*x^3-7*x^2+4*x-1)/(x^5-5*x^4+10*x^3-10*x^2+5*x-1):

debug_gfun := gfun[ratpolytocoeff](debug_solved, x, n);

If I remove ANY of these lines of code, there is no longer any problem, which is very strange because, for example, I'm not using the PolynomialIdeals package anywhere in the script. This particular script works fine on a Linux machine running 2021.0, but yet I am having similar problems on that machine with other cases.

Here's a slightly simpler example in which gfun[ratpolytocoeff] induces a "division by zero" error ("Error, (in convert/fullparfrac/normal_only) numeric exception: division by zero"):

with(PolynomialIdeals):
url := "https://api.combopal.ru.is/garpur_run/61e5f7acf2e929ff811caad3":

latex:-Settings(useimaginaryunit=i):

data := URL[Get](url):
json := JSON[ParseString](data):
json := JSON[ParseString](data):

debug_gfun := gfun[ratpolytocoeff](1/(1-x), x, n);

After the division by zero error, if I press Ctrl+D to close the Maple command line, it prints
"GC Thread signalAbort 0x7000019a5000 Execution stopped: Stack limit reached.".

Is this an internal Maple bug? Is there any workaround? I am pulling my hair out and would be very grateful for any help.

psi := psi(t)

psi := psi(t);
Error, recursive assignment
How can this assignment be accomplished?

There seems to be a bug in Maple 2021, latest release. Not sure if this was in previous versions.

When checking off the "Show Column Header" in Datatables, the cells are becoming invisible, while the column header still remains.

Show Row Header on the other side works fine.

A user wondered how to have Maple produce a desired form of a solution

eq1 := `σ__2` = P__2/(Pi*r^2)NULL

NULL

r := (1/2)*d

NULL

soln := `assuming`([solve(eq1, {d}, useassumptions)], [`σ__2`::real, d > 0, P__2 > 0])

{d = 2*(Pi*sigma__2*P__2)^(1/2)/(Pi*sigma__2)}

(1)

NULL

Parse:-ConvertTo1D, "first argument to _Inert_ASSIGN must be assignable"

Download question-better-spacing.mw

We suggested the closest they might be able to get is using simplify like so:

 

restart; eq1 := `σ__2` = P__2/(Pi*r^2)
``

``

r := (1/2)*d

``

soln := `assuming`([solve(eq1, {d}, useassumptions)], [`σ__2`::real, d > 0, P__2 > 0])

{d = 2*(Pi*sigma__2*P__2)^(1/2)/(Pi*sigma__2)}

(1)

``

`assuming`([simplify(soln)], [sigma__2::real, P__2 > 0])

{d = 2*P__2^(1/2)/(Pi^(1/2)*sigma__2^(1/2))}

(2)

NULL


Download suggestion.mw

Many times when using the debugger, and hitting the NEXT button I get the message

   Warning, cannot determine statement number; procedure may have changed in-place

The problem is that after this, hitting NEXT will not go to next statement any more. It will bypass and return from the current procedure. but hitting STEP will make it go to next statement, But STEP will also go into next block which I might not want to do.

Only way to fix this is to terminate the debugging session and start all over again.

it is random and comes up in different places. The code in in .mla file and I step through it.

I am sure anyone who have used the buildin debugger have seen this message before. It shows for me many times. 

What causes it and what can one do to not make it show up or clear it up so one does not have to restart the debugging each time it shows up?

Here is a screen shot.  I am also wondering if this happens using the emacs interface to the Maple debugger? I have not used the emacs interface to the debugger before.

Maple 2021.2 on windows 10

 

I can't understand why this error Error, adding lists of different length show up only when removing a print statement!

Why would a print has anything to do with an error message showing up or not?

some context. I wanted to call map on expression, but wanted to collect the result of operating on each indent in a list as map goes through the expression on term after the other. The expression will be type `+`.

I did not know how to do it inside map. So I create separate proc which map call.

Inside this proc, I use list to append to (this will small list, few terms at most).  To be able to do this, I made the list I want to collect thing into a global variable outside the proc.  Everything was working OK, until I remove a print statement  I had inside the proc for debugging.

I am sure there is a better way to do this all (i.e. collect map output into a list) and I am trying to find better way. But my question is: Why would this error shows up only when I remove a print statement from the last line in the proc?

I also notice when removing the line variable declaration global L now both version work with no error, but get warning Warning, (in f) `L` is implicitly declared local which is why I added declaration global L in first place.

Maple 2021.2 on windows 10

interface(version);

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

restart;

r:=2/(x^2+1)+1/(x^2+1)^2;
L:=[];
f:=proc(Z)
   global L;  
   #do some processing on Z, then collect it into list L
   L:=[ op(L), Z^2];
   #print("op(L) = ",op(L)," Z=",Z);   
end proc:
map(Z->f(Z),r);
L;

2/(x^2+1)+1/(x^2+1)^2

[]

Error, adding lists of different length

[4/(x^2+1)^2, 1/(x^2+1)^4]

restart;

r:=2/(x^2+1)+1/(x^2+1)^2;
L:=[];
f:=proc(Z)
   global L;  
   #do some processing on Z, then collect it into list L
   L:=[ op(L), Z^2];
   print("op(L) = ",op(L)," Z=",Z);   
end proc:
map(Z->f(Z),r);
L;

2/(x^2+1)+1/(x^2+1)^2

[]

"op(L) = ", 4/(x^2+1)^2, " Z=", 2/(x^2+1)

"op(L) = ", 4/(x^2+1)^2, 1/(x^2+1)^4, " Z=", 1/(x^2+1)^2

[4/(x^2+1)^2, 1/(x^2+1)^4]

 

Download why_error.mw

 

Thanks to everyone for the answers and information I did not know that map does process return value from a proc it calls. Good to know.

 

I'm asking this because I'm sure I'm just missing something.

If I solve a DE with numerics, i.e., dsolve(...,numeric), I get a procedure, say h. I want to answer: if I have a point a that I know, what are the root(s) of h(x) - h(a) = 1? In other words, solve for x.

I thought this would just involve something like fsolve or solve/evalf, or perhaps a root finding package, but I can't figure it out. What I want to avoid is having to write a procedure to hone in on the root myself, since my code is already quite slow.

Any help would be greatly appreciated.

EDIT 1: Here is my MWE (or, what should work in my mind but doesn't). The ODE isn't important, it's just an easy example.

restart;

ode := diff(f(x),x) = f(x);

initial_condition := f(0)=1;

a := 1;

h := dsolve({ode,initial_condition},numeric);

solution := fsolve(h(x) - rhs(h(a)[2]) = 1);

University of Costa Rica     

Course: SP-1493

Student: Lic. Marcus Vinicio Mora Salas

Instructor: Dr. Erick Castellón Elizondo

 

Assigment 7

Description

   

e2.301

 

Express sin(theta) in terms of

i)   cos(theta), and

ii)  tan(theta), and

iii)  cot(theta);

the latter part is more difficult than the preceding two parts.  Each square root that appears is assumed to include both positive and negative roots; for arbitrary angle theta, the sign of the root is given by the quadrant of the angle.  Test your results with a numerical value of theta. In an analogous manner, each circular trigonometric function is expressible in terms of any other circular trigonometric function, but possible ambiguity of signs of square roots exists.   

eq := [sin(theta)^2 + cos(theta)^2 - 1,

Error, invalid input: convert expects its 2nd argument, form, to be of type name, but received -sin(theta)

sin(theta)

 

Download tareaclase8.mw

In this question I have to do what I said in the title. Really I don't understand the question very well, or at least I don't understand the objetive, because if I use solve I get an error and if I use isolate I only can get sin in terms of cos and even wen I could get all answer, I needed a starting point, it's say an identity to solve the exercise. Therefore, my question is, Maple have some comand to express trigonometric functions in terms of another without introducing identities?

I looked at combinat package but it is too large and could not find what I want.

I'll explain with example to make it easy. Given n=2 I want to generate all possible arrangements of sets of length n where each element can be either +1 or -1. So it will be 2^n=4 possible arrangements

And for n=3 then want to generate all possible sets of length 3 where each element can be either +1 or -1 so it will be  2^n=2^3=8 possible sets

And for n=4 it will be 2^n=16 possible arrangements

And so on. I picked [+1,-1] in the above as an example.   

Is there a command to do this in Maple?  I can ofcourse program it using using loops and if's and so on. But thought there might be a command in Maple package which will generate all these possibles sets. Either as list of lists or Matrix or any other format. 

 

Our user wondered about using PolynomialIdeals:

1.  If we have n+1 polynomials,  f, g1,...,gn,  how to determine if  f  is in the ideal generated by  g1,...,gn?

2.  If so, how to write  f  as a polynomial combination of   g1,...,gn? 

We suggested that;

The nicest interface to answer the first question is given by the ?PolynomialIdeals,Operators page: you can write

with(PolynomialIdeals):
with(Operators):
J := <g1, g2, ..., gn>;
f in J; # true or false

To answer the second question, you need to use the lower level  package (which underlies the  package). This will also answer the first question for you. In particular the  command. You can write:

(Edit Feb 1, 2022 - use  instead of 

with(Groebner):
G := [g1, g2, ..., gn];
ord := tdeg(x,y,z); # replace x, y, z with the appropriate variables; you can also use other variable orders -- see ?Groebner,MonomialOrders

b := Basis(G, ord);
n := NormalForm(f, b, ord, 'Q');
# if n = 0 then f is in the ideal; Q is the list of coefficients:
f - add(Q[i] * b[i], i = 1 .. numelems(b)); # this will be equal to n.

Hello,

     Can you enter debug in a worksheet vs a proc?   

    I have a for loop that is crashing in the middle with a bad calculated number to provide to a thermoprops function.   Is there a way to single step through a for loop (1500 iterations) to see which line is getting tripped up?  I can not post the worksheet as it's private development.   The question is generic to any "for loop".

   I have also tried "porting" into a code edit region, but still can not enter the debugger mode.   Is proper debugger only available if I turn the "for loop" into a proc?   If yes, what is the availability of packages called right after restart for the worksheet for a proc, or do all the pre-calcs developed in the worksheet and the packages to be variables fed into the proc or packages re-declared insde a new proc ???

  Sorry if this is a trival question.

Thanks in advance,
Bill

I am a new user to Maple, but have used PTC's Mathcad and Prime.

I have several matrices that I need to combine both vertically and horizontally.  The command augment will combine the matrices horizontally.  I was unable to find a command to combine the matrices vertically.  I tried the stack command (Prime command).  The Maple stack command appears to have a different functionality.  Could you suggest which command would do the job?  The matrices are large and I would like to limit the number of rows and columns shown in the document.

The next step will be sorting the data. I am researching this at this time.

Thank you for the support,

David Tietje

A user would like to know if it is possible to specify a data set say, x:=[1,2,3,4,5,6] and then extract a random sample from that data set, i.e. xsample:=[3,2,4] for a bootstrapping-type calculation.

We suggested they use something like the following:

restart; with(Statistics); my_data := [1, 2, 4, 5.5, 5.5, 6]; X := RandomVariable(EmpiricalDistribution(my_data)); s := Sample(X, 10); Bootstrap(Mean, X, samplesize = 4, replications = 10000)

HFloat(3.9984625)

(1)

NULL

Download array-random-sample.mw

Hello people in Mapleprimes,
I haven't written in this site for a long time.

I have a question in the below program, which is to write ribbons.
For the implementation of this program, 
I wrote this.
ribbonplot5([cos, sin, cos + sin], -Pi .. Pi,numpoints=20);

In the part of pattern matching, as -Pi .. Pi above is a range, so it is OK.
But, when I changed this part to x=-Pi..Pi, an error message appears.

ribbonplot5([cos, sin, cos + sin],x=-Pi .. Pi,numpoints=20);

brings error messages:
"Warning, unable to evaluate the function to numeric values in the region; see the plotting command's help page to ensure the calling sequence is correct"

In the code of ribbonplot5,  x=-Pi..Pi which is the type of name=range shoud satisfy the pattern matching, as I wrote in the first part of the program as 
ribbonplot5 := proc(Flist, r1::{range,name=range})

I cannot know why the part of the program:
 
" else
       newFlist := map(unapply, Flist, lhs(r1));
     opts := ['labels'=[lhs(r1), " "," "],
                 args[3 .. nargs]];
    ribbonplot5(newFlist,rhs(r1),op(opts)):
"

wouldn't work well.

I wish I could get an answer to this. 

Thanks in advance.

This is a program in maple9 Advanced Programming Gude p. 253

graphic_ribbonplot.mw

restart;
extend := proc(f)
     local x, y;
     unapply(f(x), x, y);
end proc:
p:=x->cos(2*x):
q:=extend(p);


ribbonplot5 := proc(Flist, r1::{range,name=range})
     local i, m, p, n, opts,newFlist;
     opts := [args[3 .. nargs]];
     if type(r1, range) then
         if not hasoption(opts, 'numpoints', 'n', 'opts')
         then n := 25
         end if; 
         m := nops(Flist);
         p := seq(plot3d(extend(Flist[i]), r1, (i-1) .. i,
                                  grid=[n, 2], op(opts)),
                       i = 1 .. m):
         plots[display](p):
     else
       newFlist := map(unapply, Flist, lhs(r1));
     opts := ['labels'=[lhs(r1), " "," "],
                 args[3 .. nargs]];
    ribbonplot5(newFlist,rhs(r1),op(opts)):
   end if:
end proc:
ribbonplot5([cos, sin, cos + sin], -Pi .. Pi,numpoints=20);
First 19 20 21 22 23 24 25 Last Page 21 of 40