MaplePrimes Questions

In traditional OOP, one can have a base class with its own constructor. Then extends this class, where the sub class has also its own consturctor. The first thing one does in the extending class constructor is to initialize the base class by calling base class constructor directly, before finishing the initializing of the extending class.

This is done in different ways. in Java the call super(...) is used for example. in C++ it is done by explicit call to base class constructor. Here is an example.  from the net.

But in Maple, I am not able to duplicate this. Because once ModuleCopy is defined (which is the name for the module constructor) in the base class, I can't have another ModuleCopy in the extending/child class. Maple complains because the name already exists.

In the following example, the base class represents a generic ode.

Then the extending/child class is meant to represent a first order ode which extends the base class and adds some specific functions that only meant to apply for first order ode type.

Later on I want to make a second order ode class and so on. All extend the base ode class. 

My question is: How to extend a class in Maple and have the extending/child class constructor call the base class constructor if one can't have more than one constructor when extending?

This Maple help shows one example of inhertance using Objects but this example does not use a constructor in the base of the child. I am assuming one needs to use ModuleCopy as the name for the constuctor since it specifies how an object is copied by Object so can't make my own function and pretend it is the constructor.

restart;

interface(version)

`Standard Worksheet Interface, Maple 2023.0, Windows 10, March 6 2023 Build ID 1689885`

ode_class:=module()
   option object;
   local ode::`=`;
   local x::symbol;
   local y::symbol;

   #constructor
   export ModuleCopy::static := proc( _self::ode_class, proto::ode_class, ode, func, $ )
    _self:-ode:= ode;
    _self:-y:=op(0,func);
    _self:-x:=op(1,func);
   end proc;

   export get_ode::static:=proc(_self,$)
     return _self:-ode;
   end proc;

   export get_x::static:=proc(_self,$)
     return _self:-x;
   end proc;

   export get_y::static:=proc(_self,$)
     return _self:-y;
   end proc;


end module;

_m2586207352192

first_order_ode_class:=module()
   option object(ode_class);
   local is_linear_ode::truefalse;

   #constructor
   export ModuleCopy::static := proc( _self::first_order_ode_class, proto::first_order_ode_class, ode, func, $ )
    #How to call base class above constructor here?

    _self:-is_linear_ode:= false;
   end proc;

   export is_linear::static:=proc(_self,$)
          return _self:-is_linear_ode;
   end proc;
          
end module;

Error, (in first_order_ode_class) export `ModuleCopy` is declared more than once

ode:=Object(first_order_ode_class,diff(y(x),x)=sin(x),y(x));

_m2586207319808

ode:-get_ode();
ode:-is_linear()

false

 


Download base_class_constructor.mw

UPDATE

This is workaround which seems to work OK. do not use ModuleCopy to construct an object, but have custom named function for each base and each child and call these explicitly.

So child constructor will  now call its parent constuctor using the specific name of that function. May be using some convention as  module_name_constuctor(....)   passing it what the parents needs.

The drawback is that now copying an object does not work automatically since ModuleCopy is missing.  but so far, I never had the need to copy one object to another, so I can live without it for now.
 

1421372

restart;

1421372

ode_class:=module()
   option object;
   local ode::`=`;
   local x::symbol;
   local y::symbol;

   #constructor
   export ode_constructor::static := proc( _self,ode::`=`, func, $ )
     print("inside ode_class constrructor");
    _self:-ode:= ode;
    _self:-y:=op(0,func);
    _self:-x:=op(1,func);
    NULL;
   end proc;

   export get_ode::static:=proc(_self,$)
     return _self:-ode;
   end proc;

   export get_x::static:=proc(_self,$)
     return _self:-x;
   end proc;

   export get_y::static:=proc(_self,$)
     return _self:-y;
   end proc;

end module;

_m2325067887904

first_order_ode_class:=module()
   option object(ode_class);
   local is_linear_ode::truefalse;

   #constructor
   export first_order_ode_constructor::static := proc( _self,ode::`=`, func, $ )
      print("inside first_order_ode_class constrructor");
      #call base class constructor
      _self:-ode_constructor(ode,func);
      #finish rest of constructor  
     _self:-is_linear_ode:= false;
     NULL;
   end proc;

   export is_linear::static:=proc(_self,$)
          return _self:-is_linear_ode;
   end proc:
          
end module;

_m2325067872672

o:=Object(first_order_ode_class);
o:-first_order_ode_constructor(diff(y(x),x)=1,y(x));

_m2325067860896

"inside first_order_ode_class constrructor"

"inside ode_class constrructor"

o:-get_ode()

diff(y(x), x) = 1

o:-is_linear()

false

 


I think Maple OOP is not fully OOP,  but it is better than nothing.

Download base_class_no_constructor.mw

 

I have a function (Hamilton-Jacobi-Bellman, HJB)

H:=(y,u,t)->y^(2)(t)+u^(2)(t)+1/(2)(x(t))^(4) +(∂)/(∂ x)(V(t))*u(t)

When I try to do

diff(H(y, u,t), u(t))

I get an invalid derivative error. Even if I remove the partial derivative, I still get the error. Does anyone know of to fix this?

Thanks

Hello,
I wonder why in the collect function:  collect(exp, abs (x-x0)) work and collect(exp, x-x0) doesn't? 
I would like to use both, any tip how to change the x-x0 to be seen like abs (x-x0), Or maybe another solution better than the collect function

Merci 

Best regards 

Please how do I compute the div n,  (n.curl n), (n.curl n)^2 and (n x curl n) and  (n x curl n)^2 given the information below: 

restart; restart; with(VectorCalculus); with(LinearAlgebra);

I.e.,

n = (cos(theta(x,y), sin(theta(x,y), 0).

I tried 

divn := Divergence(proc (x, y, z) options operator, arrow; `<,>`(n) end proc);

but received: Error, (in VectorCalculus:-Divergence) the procedure must evaluate to a Vector

  restart;

  local gamma:
  local GAMMA:

  odeSystem:= [ (1 + GAMMA)*diff(f(eta), eta$4) - S*(eta*diff(f(eta), eta$3) + 3*diff(f(eta), eta$2)
                +
                diff(f(eta), eta)*diff(f(eta), eta$2) - f(eta)*diff(f(eta), eta$3))
                -
                GAMMA*delta(2*diff(f(eta), eta$2)*diff(f(eta), eta$3)^2 + diff(f(eta), eta$2)^2*diff(f(eta), eta$4))
                -
                M^2*diff(f(eta), eta$2) = 0,

                (1 + (4*R)/3)*diff(theta(eta), eta$2) + Pr*S*(f(eta)*diff(theta(eta), eta)
                -
                eta*diff(theta(eta), eta) + Q*theta(eta)) = 0,

                diff(phi(eta), eta$2) + Sc*S*(f(eta)*diff(phi(eta), eta)
                -
                eta*diff(phi(eta), eta)) - Sc*gamma*phi(eta) = 0
              ];

  params:= [ S = 0.5, GAMMA = 0.1, delta = 0.1, gamma = 0.1, M = 1,
             Pr = 1, Ec = 0.2, Sc = 0.6, R = 1, Q = 1
           ];
  bcs :=[ f(0) = 0, (D@@2)(f)(0) = 0, f(1) = 1, D(f)(1) = 0, D(theta)(0) = 0,
          theta(1) = 1, phi(1) = 1, D(phi)(0) = 0
        ];

how to solve the equations by finite element method

Please check: Finding_Chi_Version1.mw

My end goal is to find the following three expressions:

chi_1 := collect(X_A,[nnu[1],nnu[2]]);

chi_2 := collect(X_B,[nnu[1],nnu[2]]);

chi_3 := collect(X_C,[nnu[1],nnu[2]]);

I expect these three expressions to be linear combinations of random variables nu[1] (nnu[1]) and nu[2] (nnu[2]).

While calling solve(), I encounter this error:

Error, (in assuming) when calling 'SolveTools:-Engine:-Dispatch'. Received: 'badly formed input to solve: not fully algebraic'

What is exactly the issue here? If it can help you answer my doubt, that argmin expression I defined is composed by conditional means and variances which I computed as in here: conditional_distributions_Version1.mw

The two formulas I am trying to implement in Maple are conditional distribution of a multivariate normal distributionAm I already doing any mistake in conditional_distributions_Version1.mw? An alternative interpretation of mine for these two formulas is: conditional_distributions_Version2.mw. Please check the light-blue-highlighted differences in the conditional variance calculation. This alternative interpretation leads to Finding_Chi_Version2.mw, which I also can't solve() (solver stuck in "evaluating") but at least I don't get the error mentioned above...

I am a bit lost to be honest: Is Finding_Chi_Version1 or Finding_Chi_Version2 the correct interpretation? 

Thanks!

Hi

Can anyone help me with this problem, i need maple to solve 8 non linear equations with 8 unknowns. Ive searched the entire internet, and this is what ive scripted so far. However there seems to be a problem with the solve command.

Ive copied the code beneath and posted the maple file aswell

Script:

restart;
g := 9.82;
p := 999.7;
u := 1.307*10^(-3);

F1 := 18 = x__1^2/(2*g) + x__2;

F2 := x__2 = x__3*13/0.1*x__4^2/(2*g) + x__5*35/0.05*x__1^2/(2*g) + x__6*x__4^2/(2*g) + x__7*x__1^2/(2*g);

F3 := 0.1*p*x__4/u = 0.1*p*x__4/u;

F4 := 0.05*p*x__1/u = 0.05*p*x__1/u;

F5 := 1/sqrt(x__3) = -2*log*2.51/(F3*sqrt(x__3));

F6 := 1/sqrt(x__5) = -2*log*2.51/(F4*sqrt(x__5));

F7 := x__4 = 0.05/0.1*x__1;

F8 := x__8 = x__1*Pi*0.05^2/2;
 

solve({F1, F2, F3, F4, F5, F6, F7, F8}, [x__1, x__2, x__3, x__4, x__5, x__6, x__7, x__8]);
Error, invalid input: solve expects its 1st argument, eqs, to be of type {`and`, `not`, `or`, algebraic, relation(algebraic), ({list, set})({`and`, `not`, `or`, algebraic, relation(algebraic)})}, but received {18 = 0.5091649695e-1*x__1^2+x__2, x__2 = 6.619144604*x__3*x__4^2+35.64154786*x__5*x__1^2+0.5091649695e-1*x__6*x__4^2+0.5091649695e-1*x__7*x__1^2, x__4 = .5000000000*x__1, x__8 = 0.3926990818e-2*x__1, 1/x__3^(1/2) = (-0.6563108934e-4*log/(x__3^(1/2)*x__4) = -0.6563108934e-4*log/(x__3^(1/2)*x__4)), 1/x__5^(1/2) = (-0.1312621786e-3*log/(x__5^(1/2)*x__1) = -0.1312621786e-3*log/(x__5^(1/2)*x__1)), 38244.07039*x__1 = 38244.07039*x__1, 76488.14078*x__4 = 76488.14078*x__4}
 

Give a list of Graphs say G now how to write a function to MakeUnique the list that is improve Isomophic graphs duplicate only.

And to get a list which tells which tell which graphs where Isomophic to which one's for my by the index position of the graph in the list G of graphs.

Writing For loops , checking each are which are Isomorphic and finding them is ok.

Looking for a simple code.

If a polynomial is irreducible, you can use GroupTheory:-GaloisGroup or galois to compute its polynomial, for example:

G := GroupTheory:-GaloisGroup(x^5 - x + 1, x)

But what if polynomials are reducible? Such as x^5-x+15. How to compute its Galois group by maple? There are some examples to check at the end of this article

Dear all

How can I determine a positive constant M such that the following inequality hold for any positive values of a, b,c. 

More precisley, I determine M such that  f(a,b,c) greater or equal M a^2 

The constant M is a positive constant depend only on alpha 

find_positive_constant_M.mw

thank you for your help 

Hi all,

I'm trying to plot the regions of a cube [0,1]x[0,1]x[0,1] that are defined by two inequalities 

0<=x<=y<=z<=1

I tried the following but the result is not satisfying :

with(plots):
G1 := implicitplot3d(x = y, x = 0 .. 1, y = 0 .. 1, z = 0 .. 1, style = surface)

G2 := implicitplot3d(z = y, x = 0 .. 1, y = 0 .. 1, z = 0 .. 1, style = surface)

display({G1, G2})

Thank you for your help.

Dear all

I would like to compute Hardy−Littlewood maximal function : we use polar coordinate for a radial function  and then evalaute integral with respect the radius r 

Hardy_maximal_function.mw

Thank you for your help 


u := c1*BesselK(0, alpha1*r) + c2*BesselI(0, alpha1*r) + c3*BesselK(0, alpha2*r) + c4*BesselI(0, alpha2*r) - A1*k^2*(k^2 - (-alpha^2*j*s + 4*c*s)/c)*BesselK(0, k*r)/((-alpha1^2 + k^2)*(-alpha2^2 + k^2)) - B1*k^2*(k^2 - (-alpha^2*j*s + 4*c*s)/c)*BesselI(0, k*r)/((-alpha1^2 + k^2)*(-alpha2^2 + k^2)) + ur*(-alpha^2*j*s + 4*c*s)/(c*(1 + c));

w := (-1 - c)/(2*s*(4.*c - alpha^2*j))*collect(diff(diff(r*diff(u, r), r)/r, r) + (alpha^2 - 4*c*s)*diff(u, r)/(1 + c) - A1*k^3*BesselK(1, k*r) + B1*k^3*BesselI(1, k*r), [c1, c2, c3, c4], factor);

om := (-1)/2*diff(u, r)/r;

fn1 := collect(simplify(subs(subs(r = 1, u))), [c1, c2, c3, c4], factor);
fn2 := collect(simplify(subs(subs(r = sigma, u))), [c1, c2, c3, c4], factor);
fn3 := collect(simplify(subs(r = 1, w)), [c1, c2, c3, c4], factor);
fn4 := collect(simplify(subs(r = sigma, w)), [c1, c2, c3, c4], factor);
soln := simplify(solve({fn1 = 0, fn2 = 0, fn3 = 0, fn4 = 0}, {c1, c2, c3, c4}));

I was translating some code from Mathematica to Maple. Why MmaTranslator does not know about Mathematica's CubeRoot function? This was added in 2012 (more than 11 years ago).

Is this known? How could one teach Maple's MmaTranslator to convert CubeRoot[x] to surd(x,3)? Is it possible to manually add missing translations to this package? Otherwise I would have to manually edit lots of code and do this myself each time.

 

restart; 
with(MmaTranslator);
FromMma(`CubeRoot[9]`);

Gives CubeRoot(9) it should be surd(9, 3)

Version 2023 on windows 10

First 206 207 208 209 210 211 212 Last Page 208 of 2427