nm

5961 Reputation

17 Badges

9 years, 140 days

MaplePrimes Activity


These are questions asked by nm

When doing

item:=x;
res:=remove(has,item,x);

Maple returns, as expected

But when item is not a single symbol, say sin(x) or diff(y(x),x), then it no longer returns ()

item:=diff(y(x),x);
res:=remove(has,item,diff(y(x),x));

It does not return () but it now returns the input itself, as if it was not removed.

Why is that, and how to make it return () also on composite expression?  I tried flatten and inplace option. Otherwise, I will have to do a special test before. 

The strange thing is that it works on 

item:=2*diff(y(x),x);
res:=remove(has,item,diff(y(x),x));

Now it returns as expected. So now it did remove diff(y(x),x). But it does not remove it when it is on its own. I assume this is by design. But it is not intuitive to the user. One would expect it to work same way on removing `x` or `sin(x)` or `diff(y(x),x)`

Can Maple solve an ode by asymptotic expansions methods? series methods (power series or Frobenius series) work only on ordinary expansion point or removable singularity point. For non removable singularity (essential), Maple's dsolve with series method can't solve these. Also, if the RHS of the ode is not analytic at the expansion point, series method do not work. 

The asympt command only applies to algebraic expressions.

Does Maple have something similar to Mathematica's AsymptoticDSolveValue  ?

Here is an example. This is an ode with RHS not analytic (has no Taylor series) at x=0

ode:=diff(y(x),x)+y(x)=1/x;
dsolve(ode,y(x),'series',x=0)

No solution.  While in Mathematica

ode = y'[x] + y[x] == 1/x
AsymptoticDSolveValue[ode, y[x], {x, 0, 6}]

 

Here is another example of ode where the coefficient of y(x) is not analytic at x=0

ode:=diff(y(x),x)+sqrt(x)*y(x)=0;
dsolve(ode,y(x),'series',x=0)

No solution. In Mathematica

ode = y'[x] + Sqrt[x] y[x] == 0
AsymptoticDSolveValue[ode, y[x], {x, 0, 6}]

Does there exist a package in Maple that can do this? Will this functionality be added in Maple in the future if currently there is no support? ( I searched and could not find anything so far).

One possible workaround I found is to solve the ODE using normal methods (non-series), then apply the asympt command on the solution. But one needs to remove the constant of integration first, Here is the above example done this way

ode:=diff(y(x),x)+sqrt(x)*y(x)=0;
sol:=dsolve(ode);
Order:=8;
sol:=eval(sol,_C1=1);
asympt(eval(rhs(sol),x=1/y),y);
eval(%,y=1/x)

Mutliplying the above back by the constant _C1 gives same answer as Mathematica's.

Is the above how one is supposed to do it in Maple? It worked on the above simple example, but need to see if it will work for other examples. it will be better if this was more directly supported. i.e. if asympt will work directly on ode's (or a new command or a new option to dsolve similar to 'series' but call 'asympt').

Maple Object model is somewhat limited.  One of the main reasons to use OOP is to be able to extend base class, and override methods in base class by new methods if needed.

This is described in  https://en.wikipedia.org/wiki/Method_overriding

Method overriding, in object-oriented programming, is a language feature that allows a subclass or child class to provide a specific implementation of a method that is already provided by one of its superclasses or parent classes. It allows for a specific type of polymorphism (subtyping). The implementation in the subclass overrides (replaces) the implementation in the superclass by providing a method that has same name, same parameters or signature, and same return type as the method in the parent class.[1] The version of a method that is executed will be determined by the object that is used to invoke it. If an object of a parent class is used to invoke the method, then the version in the parent class will be executed, but if an object of the subclass is used to invoke the method, then the version in the child class will be executed.[2] Some languages allow a programmer to prevent a method from being overridden.

Maple does not allow the extending class to override variables or methods in the base class. Even if the type of the variable or the sigature of the proc is different as long as the name is the same.

This makes it hard to override base class implementation and to do type extension.

Here is a toy example

restart;

 animal:=module()
   option object;
   export data1;

   export move::static:=proc(_self,$)
      print("In Animal class. moving ....");
   end proc;  
end module;
 
#create class/module which extends the above
dog:=module()
   option object(animal);
   export move::static:=proc(_self,$)
      print("In dog class. moving ....");
   end proc;  
end module;

Error, (in dog) export `move` is declared more than onc

All computer languages that supports OOP that I know about supports overriding, The above web page lists some. 

Ada,  C#C++, DelphiEiffel, Java, Kotlin, Python, Ruby

A workaround, is if such name conflict occurs, is to come up with new name. So the above example becomes


dog:=module()
   option object(animal);
   export move_the_dog::static:=proc(_self,$)
      print("In dog class. moving ....");
   end proc;  
end module;

And now Maple does not complain. But the whole point of type extension is to override the base class implementation, and not add a new implementation while keeping the base class one there.

Is there a way to do this in Maple? if not in current version, are there plans to add this to future Maple versions?

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

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