nm

11353 Reputation

20 Badges

13 years, 19 days

MaplePrimes Activity


These are questions asked by nm

From help it says

"For any variable used within a procedure without being explicitly
mentioned in a local localSequence; or global globalSequence; the
following rules are used to determine whether it is local or global:

The variable is searched for amongst the locals and globals (explicit or implicit)
in surrounding procedures
, starting with the innermost.  If the name is
encountered as a parameter, local variable, or global variable of such
a surrounding procedure, that is what it refers to."

--------------------------------------------

So it seems if I do not use explicit "global" on a variable, Maple can figure
if it is global or not using the above rules. But when I use explicit "global"
on a variable, Maple did not seem to do the same thing. Here is an example
 

restart;
foo:=proc()
  local a, inner_proc;

  inner_proc := proc()
     local b;
     b   := ithprime(10);
     a   := b; #this assiged the global (to this proc)
               #variable, which is "a" correctly
  end proc;

  inner_proc();

  return(a);
end proc;

calling foo() gives 29.

But since the variable "a" in foo() is a global with respect to the inner_proc() (based on what the above help page seems to say), then why this does not work

restart;
foo:=proc()
  local a, inner_proc;

  inner_proc := proc()
     local b;
     global a;
     b   := ithprime(10);
     a   := b;                
  end proc;

  inner_proc();

  return(a);
end proc;

Now foo() returns "a". So Maple did not assign 29 to the global "a", (global to the inner_proc).

This for me makes little sense. Is global in Maple means the outermost scope only, skipping everything in between?

I thought global means any variable outside the proc itself. So if the proc() was inside another proc(), then the variables in the outer proc are global to the inner proc, even if they are declared local to the outer proc.

Why did Maple not do the assignment when I explicitly declare "a" to be global in the inner proc?

 

Why does Maple dsolve give this strange error from dsolve? I do not see that the input is wrong

restart;
F := x * ( y(x) + x*sqrt(x*y(x)) + sqrt(x^3*y(x)) );
ode:= diff(y(x),x) = F;
dsolve(ode,y(x));

I do not see where the input is invalid. I stared at it for 5 minutes.

Mathematica can solve this as follows

ode = y'[x] == x ( y[x] + x Sqrt[x y[x]] + Sqrt[x^3 y[x]]  )
DSolve[ode, y[x], x]

Did I type something wrong in Maple?

Physics:-Version();
    2018, June 12, 1:40 hours, MapleCloud version: 60

 

 

I want z  to becomes abs(z) then later on, remove abs() and obtain z back in the same form it was.

I found that Maple changes z when I put it inside abs. Like this

expr:=(-y^2+1);
abs(expr);
op(1,%);

So instead of 1-y^2, I end up now with  y^2-1. I want to keep the same expression I started with.

Mathematica does not do this:

expr = 1 - y^2
Abs[expr]
%[[1]]

Is there a way or option to tell Maple not change the expression when I put it inside abs()?

This complicates what I am trying to do in Maple.

thank you

What is the correct idiom in Maple to do subexpression replacement?

Suppose I want to replace each occurance of ln(anything) by ln(abs(anything)) in an expression.

Currently I call indets and then loop over each entry and use patmatch to do the replacement.

Is there a better method than what I doing now? Here is an example

restart;
expr := 7*ln(arcsin(x))-(1/2)*ln(x-1)*sin(x)-(1/2)*ln(x+1)+f;
lis:=indets(expr):
for z in lis do
    a:='a';b:='b';c:='c';
    if patmatch(z,a::anything*ln(b::anything)*c::anything,'la') then
       map(z0->assign(z0),la);
       expr:=subs(z = a*ln(abs(b))*c, expr);
    fi;
od:
expr;

I do not know if this will fails on some other cases yet.

I found that when changing constant of integration from _C1 to C1, Maple now fails to verify solution.

Is one supposed to only use constant with _ in it for this? I prefer to use C1 instead of _C1. Why does Maple odetest fail in this case? Is there a way around this?

Here is an example

restart;
ode:=diff(y(x),x)=x*ln(y(x)):
implicit_sol := -Ei(1, -ln(y(x)))+C1=(1/2)*x^2;
explicit_sol := solve(implicit_sol,y(x)):
odetest(y(x)=explicit_sol,ode);

Now changing C1 to _C1 and nothing else, odetest verifies the solution

implicit_sol:= subs(C1=_C1,implicit_sol);
explicit_sol := solve(implicit_sol,y(x)):
odetest(y(x)=explicit_sol,ode);

I understand the using symbol with _ is a convention in Maple for global symbols. But I want to use C1 and not _C1 as it is easier to read.

 

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