nm

9752 Reputation

19 Badges

12 years, 63 days

MaplePrimes Activity


These are questions asked by nm

restart;
g:=0.88641:
e:=2.53128:
eq:=tan(g)= e*sin(f)/(1+e*cos(f)):
fsolve(eq,f);

gives  1.19749

What command/option do I need to get both solutions like with Mathematica:

g = 0.886461;
e = 2.53128;
eq = Tan[g] == (e Sin[f])/(1 + e Cos[f]);
NSolve[eq, f]

  (*   {{f -> -2.56623}, {f -> 1.19756}} *)

thanks

I find this a little frustrating as I learn Maple, so I think there is a better way to handle this.

I find myself having to keep wrapping expressions with evalf() in order to compare them, since when I use a constant such as Pi in these expressions and then compare them,  Maple complains.

In a large program, one does not know if an expression contains Pi or not beforehand, so is one really supposed to convert every expression to float just in case they might need to compare 2 expressions? 

Let me explain with simple example:

x:=1.2;  #it does not matter if this was 12/10 or 1.2, same error will result.
y:=Pi/3;
if x<y then
   print("x<y");
else
   print("x>=y");
fi;

The above gives the error "Error, cannot determine if this expression is true or false: 1.2<(1/3)*Pi"

So I changed the y assignment above to y:=evalf(Pi/3); or evalf(Pi)/3; and now Maple is happy.

But this for me looks awkward. In Mathematica, I can simply write the same, using symbolic Pi, and it works as is:

x = 1.2;  #even if this is symbolic 12/10 it will also work
y = Pi/3;
If[x < y, Print["x<y"], Print["x>=y"]]

I did not have to write  y=N[Pi/3]  where N[] is the equivalent function to Maple's evalf() which converts its argument to real.

So, now in Maple, I find myself writing evalf() around so many things, since I have to anticipate I might need to compare them in some logic later on and I can't keep track which one has some symbolic constant such as Pi in them or not. While in Mathematica I never had to worry about this.

Is there a way to reduce the need to having to use evalf() so much?
It seems to me, Maple should be able to decide if  1<Pi without me having to write 1<evalf(Pi) ?

 

I need a small help again. I have a basic question. Not able to figure how to do this.
(I am a newbie in Maple)

Maple handles things little different inside a proc() vs. global. http://www.maplesoft.com/support/help/Maple/view.aspx?path=procedure

And I could not understand what this below means in plain English:

Within a procedure, during the execution of its statementSequence, local
variables have
single level evaluation. This means that using a variable
in an expression will yield the current value of that variable, rather than
first evaluating that value. This is in contrast to how variables are evaluated
outside of a procedure, but is similar to how variables work in other programming languages.

 

But here is my question. In global name space, A variable inside an expression will automaticaly
update to the current value of the the variable. So one can do this:

x:='x';z:='z';
expr:=3*z;
z:=solve(x-1=0,x);
expr;

and now expr will have value "3" and not "3 z" since "z" was assigned a new numerical value in between
as one can see. The same code inside a proc()  behave differently

f:=proc()
  local z,x,expr;
  expr:=3*z;
  z:=solve(x-1=0,x);
  expr;
  end proc:

f();

return "3 z" and not "3" as the case with global scope. I tried subs() insid the proc,
but still it did not work. What is the recommded way to handle this? I want "expr" to
use the most recent value of any variables inside it. I can't do sub(z=z,expr) ofcourse
since this makes no sense. I need the value of z inside expr to be updated.i.e. I need
to refresh "expr" somehow.

 thank you,

Ok, I am not able to find about this after 30 minutes search (my limit of giving up :).

One can ofcourse make a local variables in a proc. But sometimes I need to make a temporary variable within the proc, say inside an if...fi to use for some local temporary computation. There is no need for this temporary variable to be declared at the whole proc() scope, since it is used only inside some limited scope.  I am not able to find how to do this in Maple. Here is some silly example

f:=proc()
     local x;
     x:=9;
     if x<10 then
        local z;
        z:=20;
        x:=z;
        ....
     fi;
     x;
     end proc;

the above is illegal. I can do this:

f:=proc()
     local x;
     x:=9;
     if x<10 then
        proc()
        z:=20;
        x:=z;
          ....
        end proc;    
     fi;
     x;
     end proc;
which compiles , but does not do what is expected. The body of the `if` statement is not called. I added a print statments there and they are not being called. (I guess since it is non-named proc(), it is not called, I thought it will fall through....

I looked for some kind of BLOCK , or DECLARE construct or such in Maple but can't find it.

is it possible to introduce a temporary local scope within a proc()? What would be the syntax? That would be really useful. Ada has this feature.

   

I could not find a way to do this in Maple looking at http://www.maplesoft.com/support/help/Maple/view.aspx?path=parameter_classes

and I see that Maple is missing from http://rosettacode.org/wiki/Named_parameters

Is it possible to call a Maple proc using named parameters? Here is an example of what this looks like from a small Ada example from the above link:

procedure Foo (Arg_1 : Integer; Arg_2 : Float := 0.0);
Foo (Arg_2 => 0.0, Arg_1 => 1);

This is very useful for proc with many arguments, and it also makes the code much
more clear and less change in using the wrong value for the wrong parameter.

In Maple notation, this can be like

foo:=proc(arg1::integer,arg2::float) ..... end proc;
foo(arg2=>10,arg1=>200);

(This editor is so bad, can't someone fix it?)
First 175 176 177 178 179 180 181 Page 177 of 183