Maple Questions and Posts

These are Posts and Questions associated with the product, Maple

As I was trying things with Maple OOP, I noticed strange behavior which I do not understand. I'll explain the problem in words first then given an example.

I have Person class. Then made one instance of it. In this class, there is one method which is defined to take in an object of same type as the class itself.

I found when I pass the object itself to its own method, it gives an error that the method expects a second argument of type person which is missing. But it is not missing.

Then when creating a second object of same type, and passing the second object, it worked! 

Why?  Here is MWE. Attached worksheet.  I would have expected same behavior in both cases. EIther both work, or both do not work. As as long as the object being passed is the correct type (person).

It seems in the first case, Maple noticed the object being passed to the method happened to be same object where this method is, and it did not pass it. Hence the missing second argument.  Is this a documented behaviour somewhere? (I made sure to make all method static though, so same code is used by all instances of the class. This is strange error message).
 

interface(version)

`Standard Worksheet Interface, Maple 2022.1, Windows 10, May 26 2022 Build ID 1619613`

restart;

person:=module()
    option object;
    export name::string:="";  

    #--- constructor---
    export ModuleCopy::static:=proc(_self,proto, name::string, $)
      _self:-name := name;
    end proc;

    export process::static:=proc(_self, the_input::person ,$)
       print("in person::process. name = ", the_input:-name);
    end proc;

end module;

_m2370471750496

p:=Object(person,"me");

_m2370557462912

p:-process(p);  #why this fail

Error, invalid input: process uses a 2nd argument, the_input (of type person), which is missing

o:=Object(person,"new_name"); #make new object and try again

_m2370557450944

p:-process(o); #why this OK?

"in person::process. name = ", "new_name"

 


 

Download why_first_call_fail.mw

Update

Ok, I am all set. I found a good way to do this. i.e. pass the object to one of its method. One has to make a copy of the object first and pass the copy. Can't use the same object. This is how I do it now. 

restart;
person:=module() 
    option object;
    export name::string:="";  

     export ModuleCopy::static:= overload( 
     [ 
         proc(_self,proto, $)option overload;
            print("Enter 2 args constructor of person");  
            #do nothing    
         end proc,

         proc(_self,proto, name::string, $) option overload; 
             print("Enter 3 args constructor of person");      
             _self:-name := name;
        end proc
     ]);

    export process::static:=proc(_self, the_input::person,$)
       print("the_input:-name = ",the_input:-name);
    end proc;
    
end module; 


p:=Object(person,"me");
#p:-process(p);  #instead of this do the following
o:=Object(p);
p:-process(o)

Which works and gives

              "Enter 3 args constructor of person"
                  p := Object<<2370600065568>>
              "Enter 2 args constructor of person"
                  o := Object<<2370600048288>>
                   "the_input:-name = ", "me"

So I am now able to pass the object (or rather copy of it) as explicit argument to other methods and other modules.  I am not sure why it does not work when using the object itself and had to make a copy. 

How to integrate the below function from 0 to eta.

A := P(eta)+S(H-2*`cos&theta;`(eta+1)*F)+`cos&theta;`*(2*F(eta)-2*H*F) = S(eta+1)*`sin&theta;`*F(theta)-`sin&theta;`(F*H(theta)-H*F(theta)+F(theta, eta))

Thanks in advance

How does one undo an overload?                                                                        

:RLC circuit I want to solve.

restart

with(DynamicSystems); with(inttrans)

E := 1; J := 3; R := 3; L := 1; C := 1/2

(1/s-6/s^2)/(s+3+2/s)

(1/s-6/s^2)/(s+3+2/s)

(1)

i__RL := proc (t) options operator, arrow; invlaplace((1/s-6/s^2)/(s+3+2/s), s, t) end proc

proc (t) options operator, arrow; invlaplace((1/s-6/s^2)/(s+3+2/s), s, t) end proc

(2)

"(->)"

-4*exp(-2*t)-3+7*exp(-t)

(3)

e__C := proc (t) options operator, arrow; E-i__RL(t)*R-L*(diff(i__RL(t), t)) end proc

proc (t) options operator, arrow; E-i__RL(t)*R-L*(diff(i__RL(t), t)) end proc

(4)

"(->)"

10+4*exp(-2*t)-14*exp(-t)

(5)

plot([-4*exp(-2*t)-3+7*exp(-t), 10+4*exp(-2*t)-14*exp(-t)], t = 0 .. 10, color = [red, blue], thickness = 3, labels = ["t", "i(t)_red and vc(t)_blue"])

 

NULL

(1/s-6/s^2)/(s+3+2/s)

(1/s-6/s^2)/(s+3+2/s)

(6)

"(->)"

[diff(x1(t), t) = x2(t), diff(x2(t), t) = -(1/3)*x3(t), diff(x3(t), t) = 6*x2(t)-3*x3(t)-3*u1(t), y1(t) = -6*x1(t)+x2(t)]

(7)

How to solve this by Maple? The answer I want to solve is the plot shown above.

Download DynamicSystem-How_to_ODE.mw

Hi experts, I know built in command to solve definite integral by using simpson and trapezoidal rule but i need to show step which is given in the example to satisfy his students of grade 12. Please help me to solve this example


I have an animation in Maple that only works if I use the option frames=120, or anything >120. Anything less and it gives the error "Error, (in plots/animate) points cannot be converted to floating-point values". I don't understand why this restriction is happening, any advice is appreciated.

transparent_background_in_plots.mw

Is there a better way to impletment a transparent background when genereating plots?

Here I generate a plot with a yellow background.

plot(sin(x), x = 0 .. 4*Pi, background = yellow);


I want the background to be completely transparent instead of yellow.

plot(sin(x), x = 0 .. 4*Pi, background = none);

Error, (in plot) Unable to find image file, none

none is not an accepted color, so an error is returned. Is there such a color as "clear" that is fully transparent? Is there a better way to impletment a transparent background when genereating plots?

As we know, when every Gi is normal in G, then the series is called a normal series:

cs := CompositionSeries(DihedralGroup(8))

We can draw it:

DrawSubgroupLattice(DihedralGroup(8), labels = ids, highlight = cs)

And all Gi is normal in G:

IsNormal~(cs, DihedralGroup(8))

[true, true, true, true, true]

But why type(cs, 'NormalSeries') will get false.. It is a bug or do I have a misunderstanding?

I am still struggling understanding Maple Object  inheritance due to lack of good examples and sparse documenation.

This is what I am trying to do. I have base class Person, and then make Employee class which extends Person class and adds new field.   

The constructor to the Employee class then needs to call the constructor to the Person class (its base class) in order to initialize it. The base class constuctor takes care of initialization the fields in the base class.

I do not know how to do this. Actually it is not clear to me how the proto argument gets into play in all of this. I could not find one example that explains how to use proto with inheritance.

I am trying to implement this python example. I will show the code for the Python, and my Maple translation. The part I do not know how to do, it how to call the constructor for the base class from the sub class.  If I do not do this, then the fields of the base class will remain unitilized.

Python example is from https://www.geeksforgeeks.org/python-access-parent-class-attribute/

# parent class 
class Person( object ):     
    
        # __init__ is known as the constructor          
        def __init__(self, name, idnumber):    
                self.name = name 
                self.idnumber = idnumber 
                  
        def display(self): 
                print(self.name) 
                print(self.idnumber) 
    
# child class 
class Employee( Person ):            
        def __init__(self, name, idnumber, salary): 
                self.salary = salary 
    
                # invoking the constructor of the parent class  
                #----->>>>> HOW TO DO THIS IN MAPLE?
                Person.__init__(self, name, idnumber)  
          
        def show(self):
            print(self.salary)

# creation of an object
# variable or an instance 
a = Employee('Rahul', 886012, 30000000)     
    
# calling a function of the
# class Person using Employee's
# class instance 
a.display()
a.show() 

Here is the Maple code

restart;
person:=module() 
    option object; 
    #I made these exported instead of local for ease of printing from outside while
    #debugging , that is all.. These should otherwise be local

    export idnumber::integer:=0;  
    export name::string:="";  

    export ModuleCopy::static:= proc( _self, proto, name::string, idnumber::integer, $) 
        _self:-idnumber := idnumber;
        _self:-name := name;
    end proc;
 
end module; 
#---- extend the above class 

employee:=module() 
    option object(person); 
    export salary::integer:=0;  

    ModuleCopy::static:= proc( _self, proto, name::string, idnumber::integer, salary::integer , $) 
        _self:-salary := salary;
        # invoking the constructor of the parent class  
        # How to do that in Maple?

        #I could always manually do this. But I do not want to duplicate the code
        #done by the base class constructor.
        #_self:-name := name;
        #_self:-idnumber := idnumber;
        
    end proc;
 
end module; 

 

How does one do the Python example in Maple?

Someone should write a book on programming using OOP in Maple. I'll buy a copy in advance.

Maple 2022.1

Please, how do plot the contour plot of im(qq) vs Re(qq) from the list below: 

qq= [2.106333379+.6286420119*I, 2.106333379-.6286420119*I, 4.654463885, 7.843624703, 10.99193295, 14.13546782, 17.27782732, 20.41978346, 23.56157073, 26.70327712, 29.84494078, 32.98658013, 36.12820481, 39.26982019, 42.41142944, 45.55303453, 48.69463669, 51.83623675, 54.97783528, 58.11943264, 61.26102914]

How does one compute the location of the minimum algebraically (rather than numerically) of the following expression:
F:=((z^2+(z^2+2*z+2)^(1/2)*(z^2+1)^(1/2)+z+1)^(1/2)*(-z^2+(z^2-2*z+2)^(1/2)*(z^2+1)^(1/2)+z-1)^(1/2)-(z^2+(z^2-2*z+2)^(1/2)*(z^2+1)^(1/2)-z+1)^(1/2)*(-z^2+(z^2+2*z+2)^(1/2)*(z^2+1)^(1/2)-z-1)^(1/2)+2*z)/(2*z^2+2);

Write a Maple procedures called “biggest4” and “smallest4” to find
a) the biggest
b) the smallest
of the given numbers  a = -1/3, b = 0, c = 7/3, d = -2

i guess i need to use end proc for programing but i dont understand:

I have set of graphs say with names

Graph1,Graph2,..., Graph50.

1) I want to print all these using a single for.

2) I want to check the Isomorphic property of which two are all Isomorphic pairwise using a for loop say 

Or if any other methods kind help with suitable advice.

i need to use two different methods to solve the initial value problem. I tried but didnt find the answer 

y" + 4y' + 4y = sin(x), y(0) = 1 , y'(0) = 0

y" + 4*diff(y(x), x) + 4*y(x) = sin(x)

dsys1 := {diff(y(x), x, x) + diff(y(x), x) + 4*y(x) = sin(x), y(0) = 1, D(y)(0) = 0};
dsol1 := dsolve(dsys1, numeric, method = gear);
dsol1(0);

 y = ax^3 + bx^2 + cx + d this is curve and is passing through the points (−1,−4),(1,0),(2,0),(3,−4).
1) Find the values of 𝑎,𝑏,𝑐 and 𝑑.
2) Plot the curve and the points given on the same axis.

I tried solving with derivative of the curve but i didnt find the exact values.

4 5 6 7 8 9 10 Last Page 6 of 1923