nm

9271 Reputation

19 Badges

12 years, 10 days

MaplePrimes Activity


These are questions asked by nm

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?)

Using worksheet mode. It is a strugle to add a new paragraph on its own group so I can document some code.

I open new worksheet, and type a Maple command. say

x:=10; and hit return.

Now the screen looks like

------
|>x:=10;
|                        x:=10
----
|>     curser is here now    (1)

Now I want to make new paragraph, on its own group, before I type new command. (I need it on its own group, to fix another Maple latex export issue) i..e I want it to look like

------
|>x:=10;
|                        x:=10
----
|   this is pargraph I wanted to create
-----
|>     curser is here now    (2)

However, this is not possible using one command.  when in (1) above, if I tell Maple to insert paragraph->Before cursor, it does this:

------
|>x:=10;
|                        x:=10
----
|  it created a paragraph- here, but this is still in the same group as (1) below
|>     curser is here now    (1)

Only way I found to do it is this: create an execution group before the cursor. Then go back to that execution group. Then do insert paragraph->Before cursor, then delete the execution group just created, leaving the paragraph on its own group:

Step 1

------
|>x:=10;
|                        x:=10
----
|> create this as execution group
----
|>

Step 2

------
|>x:=10;
|                        x:=10
----
|   create paragraph here
|>
----
|>

step 3, delete the execution group, leaving the paragraph

------
|>x:=10;
|                        x:=10
----
|   leaving paragraph on its own here
----
|>

there got to be a simpler way? I am using Maple 18 on windows 7. (64 bit)

 

Maple 18, windows 7.

When I export this to Latex

x:=1/y;

The latex comes out as x:=y^-1 instead of using 1/y as it displays. I prefer 1/y and not  y^-1

i.e. instead of generating {y}^{-1} it should use \frac{1}{y}, just as it appears on the screen. Is there a configurration option one can use for this?

I also like to know if one can insert latex markup directly in Maple text paragraphs?

For example, if I add a text paragraph, (Menu->Insert->Paragraph) and would like to type some math in there, I can't just write $\sin(x)$ as this will not render as math when exported to Latex, as it is in a Maple normal group in the Latex file. 

Is there another way to typeset math in text area of a document? I only use worksheet mode. Not interested in using document mode.

thank you

 

 

   

First 167 168 169 170 171 172 173 Page 169 of 175