nm

5976 Reputation

17 Badges

9 years, 146 days

MaplePrimes Activity


These are questions asked by nm

This is another one of those problems that shows up only when I put all my modules in a lib and run the program, and unable to make a MWE in the worksheet.

Here is description of the problem. There is a module which is an object, which has no method. Just variables. 

export SUM_type:=module()
   option object;
      
   export starting_index::integer;
   export body;
   export power_on_x;
   export actual_sum;   
end module;

some where inside the program, a list is created of such objects. This problem only shows up when there is ONE object in the list. Where there is 2 or more objects in the list, no problem. The problem shows up here

for tmp in op(THE_SUMS) do    #BUG IN MAPLE  
        new_ode := new_ode + tmp:-actual_sum;
 od; 

The above code is from inside a proc in a module. The variable THE_SUMS is the list and tmp is just a local variable.

In the debugger, once I step in the loop, it generates an exception

The strange thing, this only happens when there is ONE object in the list and not more. Here are screen shot from the debugger window

To avoid this, I changed the loop to the following, and not it works with one or more entries in the list

   for N from 1 to nops(THE_SUMS) do
       tmp := THE_SUMS[N];
       new_ode := new_ode + tmp:-actual_sum;
   od;

And this work. I spend a lot of time trying to make a MWE, but it works ok in worksheet. It looks like a scoping issue. I do not use ModuleIterator, and do not need it. When I added one to the object above just to see what happens, I saw the ModuleItrator being called. I have no idea why Maple wants to call it when there is one object in the list.

Here is one attempt on a MWE. but this gives no error. 

SUM_type:=module()
   option object;
   
   export starting_index::integer;
end module;
o:=Object(SUM_type):
o:-starting_index:=1;
L:=[o]:
for item in L do  #OK here since in global name space?
    print(item);
od;

I am just repoting this in case someone have seen it before. I have a workaround it as I showed, which is to avoid using `for temp in list` when the list has objects in it.

Maple 2021.1 on windows 10

I just spend 2 hrs trying to make this work in headless worksheet, but it does not work. I have A worksheet, which calls B worksheet. The call all go through OK and I set it all correctly. Set up the section in worksheet B and document property, etc.. as described in help.

So the call works OK and arguments are passed correctly from A to B.

The problem is that in worksheet B, I wanted to generate a plot in order to save it to postscript file.  This did not work. Nothing gets exported, even  though the plot is actually generated correctly in B.  How do I know this? Becaue B returns the plot back to A, and I can see the plot was correctly generated.  The file .ps never gets created. I look at the folder these worksheets are in, and there is no .ps file created.

But it was not saved to .ps file.  The same code works ok in standard worksheet and plot is saved correctly to .ps file using same code.

I also could not export the plot to JPEG file from worksheet B.  Only thing that worked is exporting some text to .TXT file from B.  

Any one knows of limitation to calling one worksheet from another?  It seems somethings work in headless worksheet and some things do not. Which does not make it useful.

You might ask, why Am I doing this? Because I wanted to call that B worksheet later on (if it worked) from a script to do the plot exporting, as the quality is better when in a "worksheet" vs. command line).

But since this does not even work when calling the worksheet from another worksheet, then there is no point of trying it from the command line.

Attached A and B. To try it, please save both worksheets in same folder and simply open A.mw and run it. It will call B.mw  

This is the first time I used documentTools package. I did not even know one can call one worksheet from another before.

I suspect it had to do with print(); call becoming inactive in headless worksheet, which causes nothing to be send to the postscript file. But I am not sure. Without print(); one can't export the plot.

I do not understand why is it so hard in Maple to export a plot to a PDF. Why is there not a simple export command to export a plot to PDF like with all the other software out there in the world?  This is the year 2021, not 1980. How many decades does Maplesoft needs to implement export to PDF?

This is on windows 10. Maple 2021.1

This is A.mw
 

restart;

currentdir("C:\\tmp\\TEST_MAPLE");
p:=DocumentTools[RunWorksheet]( "B.mw" , [the_function=sin(x),the_variable=x]  ):
print("Back from calling worksheet B. Here is the result");
p;

"C:\tmp\TEST_MAPLE"

"Back from calling worksheet B. Here is the result"

 


 

This is B.mw
 


 

Inputs

 

the_function:=0;

the_variable:=0;


p:=plot(the_function,the_variable=-2*Pi..2*Pi):
full_file_name:=cat("C:\\tmp\\TEST_MAPLE\\tmp.ps");
plotsetup(ps,plotoutput=full_file_name):
print(p);
plotsetup(default):

return p;


 

Download B.mw

Download A.mw

in my program, I need to generate plot of solution. I only know where the initial condition x value is. So I give to plot the x range as some value around that initial condition location. But this is not perfect, since the command line script will fail if Y value happend to be too large somewhere in this range due to singularity. (This fails only in the command line print driver, not in the worksheet GUI).

I can ofcource limit the y range also, using view=[....] but I do not know how to pick best Y range  automatically in the program to show what is interesting in the plot without doing lots of analysis on the expression.

There is something called smartview which is supposed to be active by default. But it does not seem to be working too well.

Here is an example. This function blows up at value near x=Pi  due to singularity. and I want the plot to automatically limit the Y range without having to specify manually the y view.

restart;
sol:=exp(-3^(1/2)*(cos(x)-1)/sin(x)):
plot(sol,x=0..2*Pi);

So clearly "smartview" did not do it or I am not using it correctly. But it is supposed to be "active"? 

Compare the same thing with Mathematica Plot where this  is handled automatically by Plot

sol = Exp[-3^(1/2)*(Cos[x] - 1)/Sin[x]];
Plot[sol, {x, 0, 2*Pi}]

Again, I know I can do the following in Maple

plot(sol,x=0..2*Pi,view=[default,-1..20]);

The problem is that I am doing this in a program, which only gets an expression as function of x to plot, around some x location. So hard to decide what the right Y range is. It will best if Plot can determine the best view automatically.

How to use smartview to handle this? Or are there other alternative plot options for such cases?

The command line print driver is still broken in Maple.  Same code works OK in the worksheet, but gives error in command line.

restart;
p:=plot(sin(x),x=0..3,axesfont=[12,12]);
full_file_name:=cat("C:\\TMP\\tmp.ps");
plotsetup(ps,plotoutput=full_file_name);
print(p);   
plotsetup(default):

No problem in the worksheet.  When putting the above code in file t.mpl and running it from DOS command line, it gives this error

>"C:\Program Files\Maple 2021\bin.X86_64_WINDOWS\cmaple.exe"  t.mpl

    |\^/|     Maple 2021 (X86 64 WINDOWS)
._|\|   |/|_. Copyright (c) Maplesoft, a division of Waterloo Maple Inc. 2021
 \  MAPLE  /  All rights reserved. Maple is a trademark of
 <____ ____>  Waterloo Maple Inc.
      |       Type ? for help.
> p:=plot(sin(x),x=0..3,axesfont=[12,12]):
> full_file_name:=cat("C:\\TMP\\tmp.ps");
> plotsetup(ps,plotoutput=full_file_name);
> print(p);

Error, invalid FONT specification

> plotsetup(default):
> quit

The fix is to remove axesfont=[12,12] from the plot command.

Is this known bug in Maple 2021.1 on windows 10?

I do not know why int() on this integrand fails always first time, and works second time it is called. seems like something is not loaded correctly first time?

integrand:=(((-3*x^2-18*x-27)*exp(2)^2+(30*x^3+330*x^2+1170*x+1350)*exp(2)-75*x^4-1200*x^3-7050*x^2-18000*x-16875)*ln(x)+(12*x^2+54*x+81)*exp(2)^2+(-120*x^3-1106*x^2-3510*x-4050)*exp(2)+225*x^4+3560*x^3+20990*x^2+54000*x+50625)/((3*x^4+18*x^3+27*x^2)*exp(2)^2+(-30*x^5-330*x^4-1170*x^3-1350*x^2)*exp(2)+75*x^6+1200*x^5+7050*x^4+18000*x^3+16875*x^2):

print("First time");
int(integrand,x);

print("second time");
int(integrand,x);

Worksheet attached.

Update

Here is a movie. it is few minutes long. This happens by random and not each time. This movie shows the command starting from "restart" are repated 4 times. First two times, no error. Then the error shows up.  So it is random. Maybe it depends if Maple is busy with other things or not. I have each worksheet set to use its own server though. So I have no idea why this happens sometimes and not other times.

 

 

 

issue_int_nov_11_2021.mw

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