Maple 2020 Questions and Posts

These are Posts and Questions associated with the product, Maple 2020

Having read-only, public proprty of class is very useful. But I am not able to see if Maple supports this.

The idea is to have an object with public variable that can only be read from outside. But to change it, one must call a setter() method.  The advantage of this over having a getter() method to read the variable back is that it simplifies the code and makes it easier to read.  

There is good discussion here on this subject https://www.python-course.eu/python3_properties.php  

and https://en.wikipedia.org/wiki/Property_(programming)  :


"A property, in some object-oriented programming languages, is a special sort of class member, intermediate in functionality between a field (or data member) and a method. The syntax for reading and writing of properties is like for fields, but property reads and writes are (usually) translated to 'getter' and 'setter' method calls. The field-like syntax is easier to read and write than many method calls"

 

In Maple, if I make the variable inside the object an export then now one can not only read it, but also change it from outside. I want to allow only reading from outside. Here is an example

restart;
module my_class()
  option object;

  export name::string; #made it export to allow direct reading
 
  export set_name::static:=proc(o::my_class,name::string)
      o:-name := name;
  end proc;

end module;

And now one can do

o:=Object(my_class);
o:-set_name(o,"me");
o:-name;  #read it

But one can also change it from outside by doing o:-name:="new name";  and this ofcurse breaks the whole idea of encapsulation.

I think allowing reading only of object variables is OK and many OO language allow this. They are called properties.

If the variable above is made local, then one can not read it directly, and a getter() method is needed for each object properties, in addition to setter() method.

Is it possible in Maple to make local object variables read only from outside? If not and if Maplesoft wants to improve its OO, this will be something useful to add for next version.

Hi

When I try to substitute a value for j, it doesn't evaluate.

add.mw

Does anyone know why pdetest is not giving [0, 0, 0] for the solution of pdsolve?
 

restart

eq := diff(u(x, t), t)-k*(diff(u(x, t), x, x)) = 0

diff(u(x, t), t)-k*(diff(diff(u(x, t), x), x)) = 0

(1)

ic := u(x, 0) = g(x)

u(x, 0) = g(x)

(2)

bc := (D[1](u))(0, t) = 0, eval(diff(u(x, t), x)+u(x, t), x = 1) = 0

(D[1](u))(0, t) = 0, eval(diff(u(x, t), x), {x = 1})+u(1, t) = 0

(3)

sol := `assuming`([simplify(pdsolve([eq, ic, bc]))], [k > 0, 0 < x and x < 1, t > 0])

u(x, t) = `casesplit/ans`(Sum(4*exp(-k*lambda[n]^2*t)*lambda[n]*cos(lambda[n]*x)*(Int(g(x)*cos(lambda[n]*x), x = 0 .. 1))/(2*lambda[n]+sin(2*lambda[n])), n = 0 .. infinity), {And((sin(lambda[n])*lambda[n]-cos(lambda[n]))/cos(lambda[n]) = 0, 0 < lambda[n])})

(4)

`assuming`([simplify(pdetest(sol, [eq, ic, bc]))], [k > 0, 0 < x and x < 1, t > 0])

[-(diff(diff(`casesplit/ans`(sum(4*exp(-k*lambda[n]^2*t)*lambda[n]*cos(lambda[n]*x)*(Int(g(x)*cos(lambda[n]*x), x = 0 .. 1))/(2*lambda[n]+sin(2*lambda[n])), n = 0 .. infinity), {And(-(1/2)*(I*lambda[n]*exp(I*lambda[n])-I*lambda[n]*exp(-I*lambda[n])+exp(I*lambda[n])+exp(-I*lambda[n]))/cos(lambda[n]) = 0, 0 < lambda[n])}), x), x))*k+diff(`casesplit/ans`(sum(4*exp(-k*lambda[n]^2*t)*lambda[n]*cos(lambda[n]*x)*(Int(g(x)*cos(lambda[n]*x), x = 0 .. 1))/(2*lambda[n]+sin(2*lambda[n])), n = 0 .. infinity), {And(-(1/2)*(I*lambda[n]*exp(I*lambda[n])-I*lambda[n]*exp(-I*lambda[n])+exp(I*lambda[n])+exp(-I*lambda[n]))/cos(lambda[n]) = 0, 0 < lambda[n])}), t), `casesplit/ans`(Sum(4*lambda[n]*cos(lambda[n]*x)*(Int(g(x)*cos(lambda[n]*x), x = 0 .. 1))/(2*lambda[n]+sin(2*lambda[n])), n = 0 .. infinity), {And(-(1/2)*(I*lambda[n]*exp(I*lambda[n])-I*lambda[n]*exp(-I*lambda[n])+exp(I*lambda[n])+exp(-I*lambda[n]))/cos(lambda[n]) = 0, 0 < lambda[n])})-g(x), eval(diff(`casesplit/ans`(Sum(4*exp(-k*lambda[n]^2*t)*lambda[n]*cos(lambda[n]*x)*(Int(g(x)*cos(lambda[n]*x), x = 0 .. 1))/(2*lambda[n]+sin(2*lambda[n])), n = 0 .. infinity), {And(-(1/2)*(I*lambda[n]*exp(I*lambda[n])-I*lambda[n]*exp(-I*lambda[n])+exp(I*lambda[n])+exp(-I*lambda[n]))/cos(lambda[n]) = 0, 0 < lambda[n])}), x), {x = 0}), eval(diff(`casesplit/ans`(Sum(4*exp(-k*lambda[n]^2*t)*lambda[n]*cos(lambda[n]*x)*(Int(g(x)*cos(lambda[n]*x), x = 0 .. 1))/(2*lambda[n]+sin(2*lambda[n])), n = 0 .. infinity), {And(-(1/2)*(I*lambda[n]*exp(I*lambda[n])-I*lambda[n]*exp(-I*lambda[n])+exp(I*lambda[n])+exp(-I*lambda[n]))/cos(lambda[n]) = 0, 0 < lambda[n])}), x), {x = 1})+`casesplit/ans`(Sum(4*exp(-k*lambda[n]^2*t)*lambda[n]*cos(lambda[n])*(Int(g(x)*cos(lambda[n]*x), x = 0 .. 1))/(2*lambda[n]+sin(2*lambda[n])), n = 0 .. infinity), {And(-(1/2)*(I*lambda[n]*exp(I*lambda[n])-I*lambda[n]*exp(-I*lambda[n])+exp(I*lambda[n])+exp(-I*lambda[n]))/cos(lambda[n]) = 0, 0 < lambda[n])})]

(5)

``


 

Download PDE.mw

inside my module, I create types to be used by only procs, and other sub modules inside the main one package I have.

but TypeTools:-AddType invoked inside my package, adds the type to system. So a user after loading the package can still see it and use this type.

Adding local before TypeTools:-AddType is not supported.

How to make the type only visible inside the package? Here is example

restart;
kernelopts('assertlevel'=2):
my_pkg:=module()
 option package;
 TypeTools:-AddType(age_type,t->evalb(t::nonnegint and t<150));
 export foo:=proc()
    local age::age_type:=20;
    print("age=",age);
 end proc;
end module;

with(my_pkg);

And now a user can do this

x::age_type:=30;

It worked, since age_type is now in the system. This can also cause a problem, since loading this package, could overwrite a type name allready set there by another package the user happened to load before.

If I can make it at least such that the user has to do 

x::my_pkg:-age_type:=200;

That would be better. But the best solution is to make the type name completely not visible from outside the package. i.e. private type to the package only.

I looked at Extension Mechanisms under typetools in help, but do not see how to use that for what I want.

 

Maple 2020.1

Any idea why Maple can simplify this expression only when multiplied by -1 but not otherwise?

expr:=sqrt(-2 + 2*I*sqrt(3));
simplify(expr)

But now

simplify(-1*expr)

Multiplying by -1 should not have mattered. Becuase -2 + 2*I*sqrt(3)=(1+I*sqrt(3))^2  Therefore sqrt(-2 + 2*I*sqrt(3)) is the same as 1+I*sqrt(3) and Maple knows this:

simplify((1 + sqrt(3)*I)-expr) gives zero.

But Maple only simplifies -expr  and not +expr.

Just wondering is someone can suggest why that is and if this is considered OK?

Maple 2020.1, Physics 724

Hello

I need to check if the solution (sols) of a (nonlinear) polynomial system of equations (the coefficients are not numeric) has only one solution for, let's say, y and (one solution for y and one solution for z).  I cannot use allvalues (not threadsafe according to CodeTools:-ThreadSafetyCheck) and then count the number of solutions. 

I have removed all solutions that fit the command 

ormap(x->x=true,map(has,rhs~(op~(sols)),_Z))

(RootOf works too).  (Please tell me if I am using ormap correctly).  

Even using the above command and then checking if nops(sols)=1, not all one solutions are caught.  

Many thanks

Ed

 

 

 

 

From another question I asked, I learned that parse("string") returns an unevaluated Maple expression. 

But in interactive mode (in worksheet), the result looks the same as normal evaluated expression. That is why I did not know this. For example

ode1:= :-parse("diff(y(x),x$2)=0");
ode2:= diff(y(x),x$2)=0;

it gives

There is no difference when looking at it.  That is why when I was in Maple debugger, I could not see why Maple was complaining about it. An eval  was needed.

I looked at the types to see if there is something like type(variable,`unevaluated`) or such, and could not find one.

If Maple can at least display unevaluated expression with different color, or different notations when in the worksheet interface,  I would have noticed that parse returns unevaluated expression.

In Mathematica, these things are done using wrappers, (called Hold or Inactive) but these are visible in the notebook and use different color shading or Hold is present and had to expliclity removed,  and so looking at them, one can see the differerence between the expressions. 

How can one in Maple distinguish between unevaluated expression such as ode1 above and evaluated one such as ode2 above?  This can be useful to use inside a proc for example.  Is there an option in the GUI itself to tell Maple may be to color each differently?

 

I can't figure why dsolve and odeadvisor fail to process ode when it is parsed from string and only inside a proc, but works ok in global space.

This works OK:

restart;
ode  :=  :-parse("diff(y(x),x$2)=0"):
func := :-parse("y(x)"):

dsolve(ode);
DEtools:-odeadvisor(ode,func);

But the same code, when inside a proc, fail

restart;
foo:=proc()
  local ode,func;  
  local x,y; #adding this did not  help

  ode  :=  :-parse("diff(y(x),x$2)=0");
  func :=  :-parse("y(x)");

  dsolve(ode);
  try
     DEtools:-odeadvisor(ode,func);
  catch:
     error lastexception;
  end try;

end proc;

foo()

It seems to have with name scoping, but I do not see what is the problem. :-parse works fine.

How to resolve this? Since I must use :-parse as I am reading the ode as string from database with Maple as string from inside a proc inside a module and the above is just a simple example that shows the problem.

Maple 2020.1 with Physics 724

Hello!

Could you help me plesase, I have a matrix like this:

And I want to get determinant of this matrix as function f(w1,w2) but when I use Determinant I always get something like this:

Hello!

I have a matrix and all elements has two indexes. For example 3x3 case:

1,1 1,2 1,3

2,1 2,2 2,3

3,1 3,2 3,3

So if I want to travers this matrix in zig-zag way and fill it with increasing numbers I will get this matrix:

1 2 6

3 5 7

4 8 9

From 1 to 2,3 and 4,5,6 ...

We have 9 elemets in this order:

1 - (1,1); 2 - (1,2); 3 - (2,1); 4 - (3,1); 5 - (2,2); 6 - (1,3); 7 - (2,3); 8 - (3,2); 9 - (3,3).

The question is - do we have a way to convert two indexes in one digit like (3,1) -> 4 or (2,3) -> 7

Thank you!

Could you help me please if there is a way to convert to

So, here again, I'm still having this problem with Maple 2020 on Machbook OS 10.13.6 (all updates have been performed): Maple 2020 does not start. I see an icon appearing in the dock but it then disappears soon without showing anything like splash something. I reinstalled and restarted the copmuter several times, reactivated the software several times (always successful), and still I'm having the problem. I installed java and then it worked for one time, but after that the same problem happens and I'm still having this issue.

I went through steps suggestged in the help and arrived at JAVA reisntallation. What else can I try? 

Please help me. Thanks.

Hiro

 

 

Suddently Maple 2020 (on Macbook) stops launching... I reinstalled it and restarted a couple of times. 

Can someone give me some clues about what is causing this problem.

I really need it right now... 

Thanks,

Hiro

 

Consider the family of functions "{`f__n`   : -infinity< n<infinity}," where the index n is
integer, and f__n; proc (R) options operator, arrow; R end proc.   It is known that diff(f__n(x), x) = `f__n-1`(x) for all n.

 

I want to convey that information to Maple.  For instance, given the input
diff(f[3](x),x), Maple should return f__2(x).  Similarly:
diff(f[3](x), x$2)                   should return   f__1(x)
f[4](x)*diff(f[3](x),x)^5   should return   f__4(x)*f__2(x)^5

What is a good way of doing that?

 

Hello!

Could you help me please to plot a fuction with domain and complex range (Maple 2020.1). For example:

f := (x, w) -> exp(w*x*I)

x,w are real numbers

 

Hello!

I've just want to use indexes in functions, like this (Maple 2020.1)

f[l,m]:=(x,y)->x^k + y^m

But I can't get the result of it:

f[1,1](2,2)

Maple show me not 4, but the same function.

First 41 42 43 44 45 46 47 Last Page 43 of 55