Maple Questions and Posts

These are Posts and Questions associated with the product, Maple

Hi all
I have a simple problem with the following matrix entries. I probably have a problem with the indices. Because the matrix is ​​not calculated correctly. Anyone have suggestion?

Drear freinds,

I want to simplify f (a long experssion) in the form of f2. How to determine M1^2 and M0^2?

f1.mw

I've been evaluating Threads (since I can use Mutex in it, which is not supported in Grid).

I noticed that when measuring time to evaluate same integral inside thread it takes about 3 times as long as outside thread.

I am using time[real] to measure the time. (is this not the correct way to do this with Threads?)

Still, using threads was faster overall to integrate 10 different integrals than doing these sequentially one by one. 

When integrating 10 _different_ integrals using Threads, the total time was about 19 seconds.  While when done sequentially the overall time was about 50 seconds.  I used different integrals, to make sure Maple does not use result in its cache.

So using Threads was almost 3 times as fast, even when each int() call takes 3 times as long. (Because all the int() calls were done in parallel). 

But It seems there is some overhead to calling library function from inside Thread? (but time is compensated for since everthing is done in parallel now). Is this documented somewhere? It could be, I did not read every help page on Threads. Just started learning in early today.

But my main question is: Why int() takes 3 times as long inside Thread than outside?  I was expecting it to take similar time. Or may be I am not measuring time correctly inside Thread?

Attached test worksheet.

interface(version);

`Standard Worksheet Interface, Maple 2024.1, Windows 10, June 25 2024 Build ID 1835466`

Physics:-Version();

`The "Physics Updates" version in the MapleCloud is 1815. The version installed in this computer is 1813 created 2024, September 28, 18:14 hours Pacific Time, found in the directory C:\Users\Owner\maple\toolbox\2024\Physics Updates\lib\`

libname;

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

restart;

 

doall := proc(mutex_to_use,my_id,T::list)
  local s::string;
  local current_time;
  
  print("mutex is ",mutex_to_use," my id is ",my_id);
  current_time:=time[real]();
  int(T[my_id],x,method=_RETURNVERBOSE);
  print("thread ",my_id," time to integrate is ",time[real]()-current_time);  
 
end proc:

#file_id:=fopen(cat(currentdir(),"/log.txt"),WRITE);

mutex_to_use := Threads[Mutex][Create]();
T:=[sin(2*x)/(a^2+b^2*cos(x)^2),
    sin(3*x)/(a^2+b^2*cos(x)^2),
    sin(4*x)/(a^2+b^2*cos(x)^2),
    sin(5*x)/(a^2+b^2*cos(x)^2),
    sin(6*x)/(a^2+b^2*cos(x)^2),
    sin(7*x)/(a^2+b^2*cos(x)^2),
    sin(8*x)/(a^2+b^2*cos(x)^2),
    sin(9*x)/(a^2+b^2*cos(x)^2),
    sin(10*x)/(a^2+b^2*cos(x)^2),
    sin(11*x)/(a^2+b^2*cos(x)^2)];
print("time=",Calendar:-Format( Calendar:-Today(), "EEEE, MMMM dd, yyyy GG 'at' hh:mm:ss a" ));  
Threads[Wait]( seq( Threads[Create]( doall(mutex_to_use,i,T)), i=1..10)):
print("time=",Calendar:-Format( Calendar:-Today(), "EEEE, MMMM dd, yyyy GG 'at' hh:mm:ss a" ));  
#fclose(file_id);
Threads[Mutex][Destroy]( mutex_to_use );

2

[sin(2*x)/(a^2+b^2*cos(x)^2), sin(3*x)/(a^2+b^2*cos(x)^2), sin(4*x)/(a^2+b^2*cos(x)^2), sin(5*x)/(a^2+b^2*cos(x)^2), sin(6*x)/(a^2+b^2*cos(x)^2), sin(7*x)/(a^2+b^2*cos(x)^2), sin(8*x)/(a^2+b^2*cos(x)^2), sin(9*x)/(a^2+b^2*cos(x)^2), sin(10*x)/(a^2+b^2*cos(x)^2), sin(11*x)/(a^2+b^2*cos(x)^2)]

"time=", "Wednesday, October 02, 2024 AD at 11:08:15 PM"

"mutex is ", 2, " my id is ", 1

"mutex is ", 2, " my id is ", 2

"mutex is ", 2, " my id is ", 3

"mutex is ", 2, " my id is ", 4

"mutex is ", 2, " my id is ", 5

"mutex is ", 2, " my id is ", 6

"mutex is ", 2, " my id is ", 10

"mutex is ", 2, " my id is ", 8

"mutex is ", 2, " my id is ", 7

"mutex is ", 2, " my id is ", 9

"thread ", 7, " time to integrate is ", 15.192

"thread ", 1, " time to integrate is ", 16.540

"thread ", 3, " time to integrate is ", 18.185

"thread ", 5, " time to integrate is ", 18.354

"thread ", 10, " time to integrate is ", 18.367

"thread ", 2, " time to integrate is ", 18.416

"thread ", 9, " time to integrate is ", 18.544

"thread ", 6, " time to integrate is ", 18.581

"thread ", 8, " time to integrate is ", 18.604

"thread ", 4, " time to integrate is ", 18.603

"time=", "Wednesday, October 02, 2024 AD at 11:08:34 PM"

restart;

T:=[sin(2*x)/(a^2+b^2*cos(x)^2),
    sin(3*x)/(a^2+b^2*cos(x)^2),
    sin(4*x)/(a^2+b^2*cos(x)^2),
    sin(5*x)/(a^2+b^2*cos(x)^2),
    sin(6*x)/(a^2+b^2*cos(x)^2),
    sin(7*x)/(a^2+b^2*cos(x)^2),
    sin(8*x)/(a^2+b^2*cos(x)^2),
    sin(9*x)/(a^2+b^2*cos(x)^2),
    sin(10*x)/(a^2+b^2*cos(x)^2),
    sin(11*x)/(a^2+b^2*cos(x)^2)]:

print("time=",Calendar:-Format( Calendar:-Today(), "EEEE, MMMM dd, yyyy GG 'at' hh:mm:ss a" ));  
for item in T do
  current_time:=time[real]():
  int(item,x,method=_RETURNVERBOSE):
  print(" time to integrate is ",time[real]()-current_time);
od:
print("time=",Calendar:-Format( Calendar:-Today(), "EEEE, MMMM dd, yyyy GG 'at' hh:mm:ss a" ));  

"time=", "Wednesday, October 02, 2024 AD at 11:09:03 PM"

" time to integrate is ", 4.869

" time to integrate is ", 4.897

" time to integrate is ", 4.744

" time to integrate is ", 5.049

" time to integrate is ", 4.622

" time to integrate is ", 5.186

" time to integrate is ", 4.694

" time to integrate is ", 5.184

" time to integrate is ", 4.790

" time to integrate is ", 5.138

"time=", "Wednesday, October 02, 2024 AD at 11:09:52 PM"

 


 

Download why_int_timing_different_in_thread.mw

 

How to make Maple not use result of int() on same function it solved before? (this is for testing something else I am doing, and I will not use this in my main code).

I am trying to make some tests to compare things, and I'd like Maple to not remember last result.

But calling forget(int), it still seems to have remembered result it found before.

I also tried

         forget(int,forgetpermanent=true, subfunctions=true, reinitialize=true);

I do not ofcourse want to call restart in middle of loop.

Is there a way to make Maple forget result it obtained, in this example, from int()?

interface(version);

`Standard Worksheet Interface, Maple 2024.1, Windows 10, June 25 2024 Build ID 1835466`

restart;

int_1:=sin(3*x)/(a^2+b^2*cos(x)^2);
int_2:=sin(4*x)/(a^2+b^2*cos(x)^2);

sin(3*x)/(a^2+b^2*cos(x)^2)

sin(4*x)/(a^2+b^2*cos(x)^2)

#first time it is slow
T:=time[real]():
int(int_1,x,method=_RETURNVERBOSE):
print("time used is ",time[real]()-T);

"time used is ", 9.477

T:=time[real](): #now it remembered last result
int(int_1,x,method=_RETURNVERBOSE):
print("time used is ",time[real]()-T);

"time used is ", 0.1e-2

forget(int); #this has no effect. It still complete much faster than first time

 

T:=time[real]():
int(int_1,x,method=_RETURNVERBOSE):
print("time used is ",time[real]()-T);

"time used is ", 0.95e-1

forget(int,forgetpermanent=true, subfunctions=true, reinitialize=true); #also this had no effect

T:=time[real]():
int(int_1,x,method=_RETURNVERBOSE):
print("time used is ",time[real]()-T);

"time used is ", 0.47e-1

#lets try different integral, now it is slow since new integral
T:=time[real]():
int(int_2,x,method=_RETURNVERBOSE):
print("time used is ",time[real]()-T);

"time used is ", 4.810

 


 

Download how_to_forget_without_restart.mw

 

I want a plot of the function & the approx. calculus of integral:

E0 := evalf(int(T2, x = x0 .. x0 + 1.542976947*10^(-13))); it doesn't compute in in normal time...Audion.mw

in the program:

restart;
a := -1.44670357887361*10^(-7);
b := -1.049267156*10^(-9);
c := 1.890440485*10^(-12);
d := -6.233924848*10^(-16);
Ea := 0.00762014687*t + a*t^2 + b*t^3 + c*t^4 + d*t^5;
E1 := diff(Ea, t);
E2 := subs(t = 435, Ea);
E3 := subs(t = 528, Ea);
E4 := subs(t = 2860, Ea);
 

It seems that Maple needs more help than necessary:

restart:

kernelopts(version)

`Maple 2015.2, APPLE UNIVERSAL OSX, Dec 20 2015, Build ID 1097895`

(1)

expr:= A+B*limit(f(x), x=+infinity);
eval(expr, limit(f(x), x=+infinity)=1)

A+B*(limit(f(x), x = infinity))

 

A+B

(2)

expr:= A+B*limit(2*f(x), x=+infinity);

eval(expr, limit(f(x), x=+infinity)=1);     # Shouldn't this return A+2*B
eval(expr, limit(2*f(x), x=+infinity)=2);   # Can I avoid doing this?

A+B*(limit(2*f(x), x = infinity))

 

A+B*(limit(2*f(x), x = infinity))

 

A+2*B

(3)

expr:= A+B*limit(f(x)^2, x=+infinity);

eval(expr, limit(f(x), x=+infinity)=1);     # Shouldn't this return A+B
eval(expr, limit(f(x)^2, x=+infinity)=1);   # Can I avoid doing this?

A+B*(limit(f(x)^2, x = infinity))

 

A+B*(limit(f(x)^2, x = infinity))

 

A+B

(4)

expr:= A+B*limit(2*f(x)^2, x=+infinity);

eval(expr, limit(f(x)^2, x=+infinity)=1);    # Shouldn't this return A+2*B
eval(expr, limit(2*f(x)^2, x=+infinity)=2);  # Can I avoid doing this?

A+B*(limit(2*f(x)^2, x = infinity))

 

A+B*(limit(2*f(x)^2, x = infinity))

 

A+2*B

(5)
 

 

Download limits.mw

Why don't the commands labelled "Shouldn't this return.." do the job?

TIA

It is probably not possible to use mutex with Grid. But I see no other option. 

I need to create a number of nodes in Grid to do parallel processing. But need to also make critical section around few places during execution  in the code (for example, writing to common file, or update SQLite db).

Grid package does not seem to have a command to do this. I found that the Threads package have mutex which is exactly what I wanted in order to make critical section.

But all my attempts to use mutex in the Grid fail. When I make mutex and pass it to Grid:-Launch call to be used by each node, I keep getting errors when it is used inside the node.

I do not know if I am just not passing it correctly, or simply Mutex is not supported in Grid. I tried many things, and none have worked.

If it is not supported, what other mechanism are there to allow one to synchronize access to some shared resource, so only one node is using at a time?

Grid has Wait and Barrier and WaitForFirst, but I do not see how these can be used for this.

Without the ability to be able to create critical section, then Grid package will not work for me.

Below is worksheet I have been using. I hope I am just making silly mistake in using the mutex with Grid.

ps. I prefer to use Grid and not Threads package to do parallel processing.

pps. I can see why mutex would not work in Grid, since mutex is process specific entity, and Grid uses completely separate processes for each node. So it will not work to use for synchronization between separate processes. But what else to use in Maple for this?

interface(version);

`Standard Worksheet Interface, Maple 2024.1, Windows 10, June 25 2024 Build ID 1835466`

restart;

currentdir("C:/tmp"); #change as needed

"G:\public_html\my_notes\solving_ODE\current_version\tests\DB_with_GRID"

doall := proc(userData::list,mutex_to_use)
  local s::string, me:=Grid:-MyNode();
  local PROBLEM_ID::posint;
  local file_id;
  
  PROBLEM_ID:=userData[me+1];
  print("mutex is ",mutex_to_use);
  s:=cat("I'm node ",String(me)," of ",String(Grid:-NumNodes())," I will be processing problem ", String(PROBLEM_ID));
  print(s);

  
  file_id:=fopen(cat(currentdir(),"/log.txt"),APPEND);

  #I need to make sure only ONE node writes to this file
  #so not to lose buffer data
  
  Threads[Mutex][Lock]( mutex_to_use );
  fprintf(file_id,"%s\n",s);
  Threads[Mutex][Unlock]( mutex_to_use );
  
  
  fclose(file_id);
  Grid:-Barrier(); #wait here for all nodes to complete
end proc:

file_id:=fopen(cat(currentdir(),"/log.txt"),WRITE);

0

mutex_to_use := Threads[Mutex][Create]();
print("mutex created is ",mutex_to_use);
userData:=[$1..10];
Grid:-Launch(doall,codeargs=[userData,mutex_to_use],numnodes=5);
fclose(file_id);
Threads[Mutex][Destroy]( mutex_to_use );

2

"mutex created is ", 2

[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

"mutex is ", 2

"I'm node 4 of 5 I will be processing problem 5"

"mutex is ", 2

"I'm node 1 of 5 I will be processing problem 2"

Error, (in Threads:-Mutex:-Lock) invalid identifier given, no mutex with id %1

Error, (in Threads:-Mutex:-Lock) invalid identifier given, no mutex with id %1

"mutex is ", 2

"I'm node 2 of 5 I will be processing problem 3"

Error, (in Threads:-Mutex:-Lock) invalid identifier given, no mutex with id %1

"mutex is ", 2

"mutex is ", 2

"I'm node 3 of 5 I will be processing problem 4"

Error, (in Threads:-Mutex:-Lock) invalid identifier given, no mutex with id %1

"I'm node 0 of 5 I will be processing problem 1"

Error, (in Threads:-Mutex:-Lock) invalid identifier given, no mutex with id %1

 

 


 

Download using_mutex_in_grid.mw

 

Hi everyone...

How can the coefficients of below nonlinear equation be obtained?

c1*diff(f(x), x$4) + c2*diff(f(x), x$3)/x +c3*diff(f(x), x$2)/x^2 + c4*diff(f(x), x)/x^3 +c5 *f(x)=0

I want to calculate separately, c1,c2,c3,c4,c5 

tnx...

I never used the Maple Grid package. I've been learning it in the last few hrs and it looks nice and could be something I can use to speed my very slow script.

I am trying to see if I can use it to do parallel processing instead of using Batch script and calling cmaple.exe manually to solve one problem at a time sequentially.

I got basic flow working in the example below. Basically it goes like this.

Call Grid:-Lauach to run 10 separate Maple processes in parallel. From help, Grid will run 10 separate server.exe's.

Passing the function to run the list of problems to processes.

At the of the function, when it is done solving the 10 problems, there is Barrier. So when all 10 nodes are completed, this run is done.

Then I repeate this, passing the next 10 problems to solve and so on.

The only thing I am not clear on from help if I should worry about node 0 or just treat it as any other node in terms of using it to solve a problem or not. It seems node 0 is special. So do I need to check if node 0 is the one being run and not use it?

Could someome who knows Grid package better please check and review this code and see if they find any issues with it? As I will be basing all my tests on this frame work if I find it speed things. 

From this basic test, it seems to work ok for all nodes, including node 0. 

doall := proc()
  local i, me:=Grid:-MyNode();
  local PROBLEM_ID::posint;
  global userData;

  PROBLEM_ID:=userData[me+1];
  print("I'm node ",me," of ",Grid:-NumNodes()," I will be processing problem ", PROBLEM_ID);     
  Grid:-Barrier(); #wait here untill all nodes are done
end proc:
 

userData:=[$1..10];
Grid:-Launch(doall,numnodes=10,imports=['userData']);

[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

"I'm node ", 1, " of ", 10, " I will be processing problem ", 2

"I'm node ", 2, " of ", 10, " I will be processing problem ", 3

"I'm node ", 0, " of ", 10, " I will be processing problem ", 1

"I'm node ", 3, " of ", 10, " I will be processing problem ", 4

"I'm node ", 6, " of ", 10, " I will be processing problem ", 7

"I'm node ", 9, " of ", 10, " I will be processing problem ", 10

"I'm node ", 8, " of ", 10, " I will be processing problem ", 9

"I'm node ", 4, " of ", 10, " I will be processing problem ", 5

"I'm node ", 7, " of ", 10, " I will be processing problem ", 8

"I'm node ", 5, " of ", 10, " I will be processing problem ", 6

userData:=[$11..20];
Grid:-Launch(doall,numnodes=10,imports=['userData']);

[11, 12, 13, 14, 15, 16, 17, 18, 19, 20]

"I'm node ", 2, " of ", 10, " I will be processing problem ", 13

"I'm node ", 4, " of ", 10, " I will be processing problem ", 15

"I'm node ", 1, " of ", 10, " I will be processing problem ", 12

"I'm node ", 3, " of ", 10, " I will be processing problem ", 14

"I'm node ", 5, " of ", 10, " I will be processing problem ", 16

"I'm node ", 0, " of ", 10, " I will be processing problem ", 11

"I'm node ", 6, " of ", 10, " I will be processing problem ", 17

"I'm node ", 7, " of ", 10, " I will be processing problem ", 18

"I'm node ", 9, " of ", 10, " I will be processing problem ", 20

"I'm node ", 8, " of ", 10, " I will be processing problem ", 19

userData:=[$21..30];
Grid:-Launch(doall,numnodes=10,imports=['userData']);

[21, 22, 23, 24, 25, 26, 27, 28, 29, 30]

"I'm node ", 3, " of ", 10, " I will be processing problem ", 24

"I'm node ", 8, " of ", 10, " I will be processing problem ", 29

"I'm node ", 4, " of ", 10, " I will be processing problem ", 25

"I'm node ", 0, " of ", 10, " I will be processing problem ", 21

"I'm node ", 1, " of ", 10, " I will be processing problem ", 22

"I'm node ", 5, " of ", 10, " I will be processing problem ", 26

"I'm node ", 9, " of ", 10, " I will be processing problem ", 30

"I'm node ", 2, " of ", 10, " I will be processing problem ", 23

"I'm node ", 7, " of ", 10, " I will be processing problem ", 28

"I'm node ", 6, " of ", 10, " I will be processing problem ", 27

userData:=[$31..40];
Grid:-Launch(doall,numnodes=10,imports=['userData']);

[31, 32, 33, 34, 35, 36, 37, 38, 39, 40]

"I'm node ", 5, " of ", 10, " I will be processing problem ", 36

"I'm node ", 6, " of ", 10, " I will be processing problem ", 37

"I'm node ", 1, " of ", 10, " I will be processing problem ", 32

"I'm node ", 7, " of ", 10, " I will be processing problem ", 38

"I'm node ", 3, " of ", 10, " I will be processing problem ", 34

"I'm node ", 4, " of ", 10, " I will be processing problem ", 35

"I'm node ", 2, " of ", 10, " I will be processing problem ", 33

"I'm node ", 8, " of ", 10, " I will be processing problem ", 39

"I'm node ", 9, " of ", 10, " I will be processing problem ", 40

"I'm node ", 0, " of ", 10, " I will be processing problem ", 31

 

 

Download using_GRID.mw

Currently I run my Maple script in a LOOP which calls cmaple.exe to solve one problem at a time.

So each iteration starts one cmaple.exe and waits for it to finish. Then next iteration repeates this for the next problem. i.e. starts new cmaple.exe process.

So it is sequential process and it can take 5-6 days or more to finish all the problems I have. Running 24 hrs per day.

I am thinking if I can run more than one cmaple.exe at same time, I could change this to have each script process say 10 problems at a time in one cmaple.exe, and have 100 such scripts running at same time. This will speed things a lot.

But this means I need to be able to run 100 cmaple.exe at same time.

I googled to see if there is a limit or any license issues/limitations in running that many cmaple.exe's at same time on same PC, but could not find anything.

Is there a limit in Maple itself to how many cmaple.exe can be running on same PC at same time?

There is no shared files or resources between these scripts, so each solving of a problem is independent. Only shared resource is Maple itself.

Maple 2024.1 

How can I substitute equation (5) into equation (4) to obtain the final form [see image in BE.mw]?

Additionally, how can I use subscript notation for derivatives, such as expressing diff(f(tau,sigma), tau)  as  f[tau]​?

By using the 'declare' command in Maple, one can utilize subscript notation. However, in this case, the function must be written in terms of τ and σ on each step.

In the final plot in this worksheet, the electric field is displayed using blue headless vectors.

Instead, how can the gradient of the dipole's potential field be displayed in field lines?

Dipole_fields.mw

Hello,

Below I am attaching a Maple worksheet on rolling a circle on a flat curve and generating a cycloidal curve.

Regards!

Cycloidal_curve.mw



 

Hi, I've been trying to get help from the Maple website, but for months now, the display hasn't worked properly. The examples section shows "comma" and "colon" texts in a way that makes it impossible to use the site effectively. Has anyone else reported this issue? It's quite frustrating.

What is the correct idiom in Maple to check that one number is greater than another or not?

For example if n=sqrt(3) and m=3 ?

Maple does not like to compare sqrt(3) with other number. It says 

   Error, cannot determine if this expression is true or false: 3 <= 3^(1/2)

I am doing this in code, so solution has to be such that it works for all cases of n and m, without the ability to look at screen and decide.

I found that using is works without the need to convert to float.  Should one then use is(n>=m) instead of evalb(n>=m) always?  

I can also always apply evalf() on each side before. But this seems like an overkill to me.

restart;

n:=sqrt(3);
m:=3;

3^(1/2)

3

if evalb(n>=m) then
   "yes";
else
   "no";
fi;

Error, cannot determine if this expression is true or false: 3 <= 3^(1/2)

if n>=m then
   "yes";
else
   "no";
fi;

Error, cannot determine if this expression is true or false: 3 <= 3^(1/2)

if evalb(evalf(n)>=m) then
   "yes";
else
   "no";
fi;

"no"

if is(n>=m) then
   "yes";
else
   "no";
fi;

"no"

 

 

Download checking_one_number_larger_than_another.mw

For reference, another software does compare these two numbers as is without the need to convert them to floating point;

But it looks the design of Maple in this aspect is different. Since the principal root of sqrt(3) is always the positive one, I did not think it will cause a problem.

1 2 3 4 5 6 7 Last Page 2 of 2152