nm

8552 Reputation

19 Badges

12 years, 355 days

MaplePrimes Activity


These are questions asked by nm

I am trying solve on the outout of odetest, in order to determine range of which x makes this output zero.

It works sometimes and  does not work another times. I mean, it gives correct domain something, and other times, it overlooks some domain. 

Here is an example

restart;
ode:=x*diff(y(x),x)*y(x) = (y(x)^2-9)^(1/2):
ic:=y(exp(4)) = 5:
sol:=dsolve([ode,ic],y(x)):
res:=odetest(sol,ode);
solve(simplify(res),x,allsolutions = true) assuming real;

It is true than when x=1, then is zero.  But so all values x>1 as well.

How to get solve to find those values as well and not just x=1?

I tried PDEtools:-Solve as well. It did not better

PDEtools:-Solve(simplify(res),x,allsolutions = true) assuming real;

Compare to Mathematica

Are there other commands in Maple which could obtain all the solutions like in the above?

Maple 2020.2 on windows 10

 

 

I can't figure exactly why adding export on module wide variable when using option package makes the variable not writable from a function inside the module

restart;

dsolver :=module()
option package;
export X::boolean := true;

export foo:=proc()
   dsolver:-X :=false;
end proc;
end module;

dsolver:-foo();

Error, (in foo) attempting to assign to `X` which is protected.  Try declaring `local X`; see ?protect for details.

But this works

dsolver :=module()
export X::boolean := true;

export foo:=proc()
   dsolver:X :=false;
end proc;
end module;

dsolver:-foo();

    false;

I wanted to make the variable export, so it can be set from anywhere (by other modules for example, directly). if I make it local, then other modules can no longer access it?

I know I can change the export to local as the error says. But why is this needed? Only thing I found so far, is this

"Not all modules are packages. Package semantics differ from module semantics in two ways. First, (module-based) package exports are automatically protected. Second, packages can be used as the first argument to"

So the above says function inside module, can't change module wide variable, if this variable is exprted, when using option package? Why?

In general, I am still not sure when to use option package or not. 

Are there any general rules as to when one needs to add option package vs. Not using this option? i.e. just use module() without this option? or the question is: When must one use option package?

I put everything (all modules) eventually in an .mla file and both cases work the same in this respect, so not sure when to use this option now. 

Maple 2020.2 on windows 10

Maple will give error when one tries to make a variable of the same name as a Maple command. Which is good ofcourse. So this gives an error

Vector:=5;

But Maple also uses hundreds of other names, as options, which are not protected like this. Even when adding this

adding interface(warnlevel=4);
kernelopts('assertlevel'=2):

There was no warning when a user makes a variable of same name as one of those Maple option names.

So if a user make a variable with such a name, it will cause serious problem. For example Vector constructor takes the name row as an option. But this name is not protected. So one can write  row:=5 and there is no warning generated by Maple.

Using Vector['row'] does not actually help. Here is an example, where Maple crashes due to this

restart;
interface(warnlevel=4);
kernelopts('assertlevel'=2):
A:=Matrix([[1,1],[2,3],[4,5]]);
row:=convert([a,b],Vector['row']);
res:=ArrayTools:-Concatenate(1,A,row); #this works, no problem

ArrayTools:-Concatenate(1,A,convert([a,b],Vector['row'])); #this will crash Maple

 

A workaround this, it to use double '' in the second call. Like this:

ArrayTools:-Concatenate(1,A,convert([a,b],Vector[''row''])); 

And if this to used again, to use

ArrayTools:-Concatenate(1,A,convert([a,b],Vector['''row'''])); 

And so on.  Ofcourse this is no way to do things.

So the user should not use row as variable name. May be use the_row instead, or a_row, and so on.

But this comes back to my question. The above is a made up example. How is the user supposed to remember there is some option used by Maple somewhere with such a name and avoid using it as a variable name? 

There are may be thousands of such names in Maple, with common names, like color and so on, and it is very easy to make a variable of this name by the user without noticing.

I also tried maplemint() and it gave no warning that a user variable have the same name as a Maple option name.

restart;
interface(warnlevel=4);
kernelopts('assertlevel'=2):

foo:=proc()
local A,row,res,a,b;
A:=Matrix([[1,1],[2,3],[4,5]]);
row:=convert([a,b],Vector['row']);
res:=ArrayTools:-Concatenate(1,A,row); #this works, no problem
ArrayTools:-Concatenate(1,A,convert([a,b],Vector['row'])); #this will crash Maple
end proc;

maplemint(foo);

foo()

 

Finally, I found that if I use Vector(:-row) instead of Vector('row'), then the crash goes away and now it works

restart;
interface(warnlevel=4);
kernelopts('assertlevel'=2):

foo:=proc()
local A,row,res,a,b;
A:=Matrix([[1,1],[2,3],[4,5]]);
row:=convert([a,b],Vector[:-row]);
res:=ArrayTools:-Concatenate(1,A,row); #this works, no problem
ArrayTools:-Concatenate(1,A,convert([a,b],Vector[:-row])); #this will now work
end proc;

foo();

But this worked because there was no global variable of the name row before calling foo. That is all. To make the above crash, all what I had to do is this
 

restart;
interface(warnlevel=4);
kernelopts('assertlevel'=2):

foo:=proc()
local A,row,res,a,b;
A:=Matrix([[1,1],[2,3],[4,5]]);
row:=convert([a,b],Vector[:-row]);
res:=ArrayTools:-Concatenate(1,A,row); #this works, no problem
ArrayTools:-Concatenate(1,A,convert([a,b],Vector[:-row])); #this will now work
end proc;

row:=5;
foo();

And now it crashes again.

This is all a big mess. Maple should warn users they are using variable of same name as Maple own option names, or make all Maple option names use some standard prefix. May be have them all start with or _ and have this special first letter be allowed only for Maple own use.

This will help prevent name clashes.

In Mathematica, this issue does not happen. Since all Mathematica names and symbols used, even as options, are protected or are strings. So no such possibility of name clash happen.

Is there a 100% robust way in Maple to prevent such name clash between user variable names and names used as options to Maple commands?

 

Fyi, there seems to be some problem here

Maple 2020.2 with Physics 897

restart;
interface(warnlevel=4):
kernelopts('assertlevel'=2):
eq:=exp(x)*sin(y(x))-3*x^2+(exp(x)*cos(y(x))+(1/3)/y(x)^(2/3))*(D(y))(x) = 0;
timelimit(30,solve(eq,y(x)));

 

Full screen shot:

 



Maple Worksheet - Error

Failed to load the worksheet /maplenet/convert/solve_error.mw .
 

Download solve_error.mw

When doing solve(res,x); maple returns back x

Does this means the equation is true for any x?

Also, doing PDEtools:-Solve(res,x) returns nothing.

I was trying to check if my solution is valid for an ode, and I obtained res above is what odetest() gives back, I wanted to find for what could res be zero.

Here is the code

restart;
ode:=diff(y(x),x)=2*sqrt(1+y(x))*cos(x);
my_sol:=y(x)=sin(x)^2+2*sin(x);
res:=odetest(my_sol,ode);
res:=simplify(res)=0;
solve(res,x);

And now 

PDEtools:-Solve(res,x)

gives nothing.

So I am a little confused what is going on. does solve result mean the equation is true for any (I think the solution I have is correct, so may be what this means,  but wanted to make sure, as I do not think I've seen this before)  And if so, why then PDEtools:-Solve did not return the same result.

Maple 2020.2, windows 10, Physics 897

First 62 63 64 65 66 67 68 Last Page 64 of 164