nm

11353 Reputation

20 Badges

13 years, 18 days

MaplePrimes Activity


These are questions asked by nm

I want to check that all entries in a list are of some value. Say 0. (or in general, if all entries satisfy some condition).

So, If any entry is not zero, then it returns false. It returns true only if all elements meet this conditions.

What would be the right way to do this in Maple? I know I could write a loop. But I am asking if there is a build-in function in Maple. Here is an example

ode:=y(x)*diff(y(x),x)=x*(y(x)^2+2):
sol:= dsolve(ode,y(x)):
check:=map(z->odetest(z,ode1),[sol]);

                       check := [0, 0]

I want to check that all entries in check are zero. This tells me all my solution are correct.

I can't use member(check,0) since this only check if at least one entry is zero. I want to chek that all entries are zero.

In Mathematica, it has AllTrue function. Like this

check = {0, 0, 0};
AllTrue[check, # == 0 &]

     True

The "#==0&"  is the test to do. It uses this test on each element automatically. If all satisfy this test, then it returns true.

Again, I can easily write a small function in Maple to do this,

alltrue :=proc(arr,value)
    local z;
    for z in arr do
        if z<>value then
           return(false);
        fi;
    od;
    return(true);
end proc:

alltrue(check,0) return true.

But I am asking if there is a build-in such function similar to the above one in Mathematica, which accepts a more general test function to use.

why

expr:=1-3*y;
patmatch(expr, b::integer - a::integer*y,'la');

gives false but

expr:=1-3*y;
patmatch(expr, b::integer + a::integer*y,'la');

gives true?

Should one then use `+` for matching with `+` and `-`? This result was a little confusing to me. 

It is actually good that it behaves this way. Makes it easier to write the pattern (less cases to cover). But I would have expected both to return true, that is all.

I found I can start Maple itself 2 times on my windows PC. (I think my license allows max of 2, but I could be wrong).

I want to run a program which takes long time. But I want to use Maple at same time.

Which is the recommended approach:

1) Start 2 separate Maple applications. Use one to run the long program, and then I can use the second Maple for other things while the first is running)

2) Start one Maple, but set the "How should Maple handle the create of new Math engine" to "Ask me each time"

for me, choice 1 seems more safe. But thought to ask if there is something else I should consider when making which choice to pick.

Update

Found out that actually when clicking on Maple icon, I was not starting a new Maple at all. It was just starting a new worksheet using the currently running Maple ! This is confusing. With Mathematica, clicking on its icon actually starts a new complete separate Mathematica application. Not a new notebook using the currently running Mathematica.

So the question I have now is: Can one start 2 separate Maple applications on windows?  And if so, how?

is there a way  for a proc() in a parent module to call an exported proc in a child module, without having to use long form of the call    child:-child_proc() and just do child_proc()?  Here is an example

A:=module()
  option package;
  export foo;
  local B; #child module

  B:=module()     
     export boo;
     boo:=proc()
        print("in B:-boo()");
     end proc;
  end module;
  
  foo:=proc()
     B:-boo();  #how can one just type  boo() here?
  end proc;
end module;

B:-foo(); now works ok. But I'd like to just use  boo() and not B:-boo() since the name of the child module is too long. 

I can't figure how to do it. I can't use with(B) in the parent, Maple complains. 

 

When a child proc calls a parent local proc using parent_module:-parent_proc(), Maple gives an error. But when the child calls the parent local proc using just parent_proc() it works. Why is that?

parent_module:=module()
 
 local child_module;
 local parent_proc;

 export parent_entry;

 child_module:= module()
    export child_entry; 
    child_entry :=proc()
     #parent_module:-parent_proc(); #this fails
     parent_proc(); #this works
    end proc;
  end module;

 #local
 parent_proc :=proc()
   print("insider parent proc");
 end proc;

 #public
 parent_entry :=proc()
   child_module:-child_entry();
 end proc;
end module;

parent_module:-parent_entry();
              "insider parent proc"

but the other way, (the commented code above) gives

parent_module:-parent_entry();
Error, (in child_entry) module does not export `parent_proc`

 

First 156 157 158 159 160 161 162 Last Page 158 of 199