acer

18325 Reputation

29 Badges

14 years, 248 days

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are answers submitted by acer

Your can also use zip to produced the list of 2-element lists. I have a slight preference for this because I find it slightly easier to recognize what the code is doing just by glancing at it a few months later.

You should choose whichever you find easier to understand, if high efficiency is not a major concern. Annotating your code with comments is also good.

You can also accomplish the pointplot by merging the two lists into an appropriate Matrix.

restart;

ListF:= [seq(x, x = -10..10, 1)]:

ListH:= [seq(x^2, x = -10..10, 1)]:

plots:-pointplot( <ListF|ListH>, size=[400,200]);

plots:-pointplot( zip(`[]`,ListF,ListH), size=[400,200]);

zip(`[]`,ListF,ListH);

[[-10, 100], [-9, 81], [-8, 64], [-7, 49], [-6, 36], [-5, 25], [-4, 16], [-3, 9], [-2, 4], [-1, 1], [0, 0], [1, 1], [2, 4], [3, 9], [4, 16], [5, 25], [6, 36], [7, 49], [8, 64], [9, 81], [10, 100]]

`[]`~(ListF,ListH);

[[-10, 100], [-9, 81], [-8, 64], [-7, 49], [-6, 36], [-5, 25], [-4, 16], [-3, 9], [-2, 4], [-1, 1], [0, 0], [1, 1], [2, 4], [3, 9], [4, 16], [5, 25], [6, 36], [7, 49], [8, 64], [9, 81], [10, 100]]

[seq([ListF[i],ListH[i]], i=1..nops(ListF))];

[[-10, 100], [-9, 81], [-8, 64], [-7, 49], [-6, 36], [-5, 25], [-4, 16], [-3, 9], [-2, 4], [-1, 1], [0, 0], [1, 1], [2, 4], [3, 9], [4, 16], [5, 25], [6, 36], [7, 49], [8, 64], [9, 81], [10, 100]]

 

restart;

ListF:= [seq(x, x = -10..10, 1.0)]:

ListH:= [seq(sin(x), x = -10..10, 1.0)]:

FH := zip(`[]`,ListF,ListH);

[[-10, -sin(10)], [-9.0, -.4121184852], [-8.0, -.9893582466], [-7.0, -.6569865987], [-6.0, .2794154982], [-5.0, .9589242747], [-4.0, .7568024953], [-3.0, -.1411200081], [-2.0, -.9092974268], [-1.0, -.8414709848], [0., 0.], [1.0, .8414709848], [2.0, .9092974268], [3.0, .1411200081], [4.0, -.7568024953], [5.0, -.9589242747], [6.0, -.2794154982], [7.0, .6569865987], [8.0, .9893582466], [9.0, .4121184852], [10.0, -.5440211109]]

with(CurveFitting):
polyInterFH:= PolynomialInterpolation(FH,x):

plot(polyInterFH, x=min(ListF) .. max(ListF), size=[400,200]);

plots:-display(
  plots:-pointplot( zip(`[]`,ListF,ListH), size=[400,200]),
  plot(PolynomialInterpolation(ListF, ListH,x),
       x=min(ListF) .. max(ListF), size=[400,200])
);

 

Download list_zip.mw

This is an attempt at part ii) using your earlier methodology of Arrays and loops. You may be able to bend it to your task. You certainly don't have to do it this way. (It's not my preference.)

There are easier ways to get all the intersections with the unit circle, but it asked for fsolve specifically in part i). [edited] I've much added easiers ways, using solve or RootFinding:-Isolate.

By now, you should realize that usually there are several reasonable ways to do most things in Maple, and often no "best" way. Tweak, adjust, and rewite as you wish.

I deliberately do some of this in a way that I consider awkward (and somewhat inefficient). It is on purpose. I realize that you are still learning Maple. I'd rather show you a somewhat clunky approach that you can figure out and understand than a slick solution that is opaque to you.

restart;

#H := (x,y)->x^3-x*y-1;
#H := (x,y) -> x^3 - 2*y^2 + 3/2;
H := (x,y) -> x^2*y + x^3 + x*y^3 + y + 1;

proc (x, y) options operator, arrow; x^2*y+x^3+x*y^3+y+1 end proc

 

part ii)

 

ImpDH := implicitdiff(H(x,y), y, x);

-(y^3+3*x^2+2*x*y)/(3*x*y^2+x^2+1)

hlist := [-0.5, 0.0, 0.5]:
P := Array(1..nops(hlist), 1..7):

for i from 1 to nops(hlist) do
  P[i, 1] := hlist[i];
  P[i, 2] := H(1+hlist[i],y)=0;
  P[i, 3] := [fsolve(P[i, 2], y, maxsols=10)];
  P[i, 4] := [seq( [1+P[i, 1], P[i, 3][1]],
                   j=1..nops(P[i, 3]))];
  P[i, 5] := [seq( eval(ImpDH, [x=P[i, 4][j][1], y=P[i, 4][j][2]]),
                   j=1..nops(P[i, 3]))];
  P[i, 6] := [seq( P[i, 4][j][2] + P[i, 5][j]*(x-P[i, 4][j][1]),
                   j=1..nops(P[i, 3]))];
  P[i, 7] := [seq( plot(P[i, 6][j], x=0..2,
                        color=sprintf("Bright %a",i+2),
                        legend=typeset("tangent at",
                                       evalf[3](P[i, 4][j]))),
                   j=1..nops(P[i, 3]))];;
end do:

plots:-display(
  plots:-implicitplot(H, 0..2, -2..5,
                      legend=typeset(H(x,y)),
                      thickness=2, color=red),
  seq(seq( P[i, 7][j], j=1..nops(P[i, 3])), i=1..nops(hlist)),
  seq(plots:-pointplot(P[i, 4], symbol=solidcircle,
                       symbolsize=15, color=blue),
      i=1..nops(hlist)),
  size=[700, 400],
  legendstyle=[location=right]
);

 

For part i)

 

PH := plots:-implicitplot(H, -4..2, -4..5, rangeasview):

# This could be done more easily, but fsolve was requested.
T := table([]):
no_more := false: count:=0:
while no_more = false and count < 10 do
  temp := fsolve([H(x,y)=0, x^2+y^2=1], {x=-4..2, y=-4..5}
                 , avoid = {entries(T, nolist)}
                  );
  if type( eval(temp,1), set) then
    count := count+1;
    # sometimes fsolve with `avoid` has trouble finding all
    # the roots, so give it a little prod.
    # Alternatively we could pass the other three as initial
    # points in their own calls to fsolve.
    T[count] := {op(Equate([x,y],eval([x,y], temp)))},
                {op(Equate([x,y],eval([-x,y], temp)))},
                {op(Equate([x,y],eval([x,-y], temp)))},
                {op(Equate([x,y],eval([-x,-y], temp)))};
    # This check is pretty crude.
    T[count] := seq(`if`(abs(H(op(eval([x,y],r))))<=1e-9,r,NULL),
                    r = [T[count]]);
  else
    no_more := true;
  end if;
end do:
sols := map(r->eval([x,y],r), [op(simplify(fnormal({ entries(T, nolist)})))]);

[[-1.000000000, 0.], [-.6023240113, -.7982517055], [0., -1.000000000], [.6906238640, -.7232141305]]

#
# Surely it is easier to just use solve for these
# bivariate polynomials.
#
sols := map(r->eval([x,y],r),
            evalf([solve({H(x,y)=0, x^2+y^2=1, x>=-4, x<=2, y>=-4, y<=5})]));

[[0., -1.], [-.602324011, -.7982517055], [.690623864, -.7232141305], [-1., 0.]]

RootFinding:-Isolate([H(x,y), x^2+y^2-1], [x,y]);

[[x = 0., y = -1.], [x = -.6023240113, y = -.7982517055], [x = .6906238640, y = -.7232141305], [x = -1., y = 0.]]

plots:-display(PH, plottools:-circle([0,0], 1),
               plots:-pointplot(sols, color=blue, symbol=solidcircle));

 

Download ex_set_2_task_7_acc.mw

If you know that what is inside the csgn is positive, then you can evaluate under that assumption.

For example,  12_ac.mws

The expression sqrt(2*x+7) doesn't mean both the positive and negative square root.

solve( Or(sqrt(2*x+7)-x-2, -sqrt(2*x+7)-x-2), [x] );

[[x = -3], [x = 1]]

H := RootOf(_Z^2 - (2*x+7));

RootOf(_Z^2-2*x-7)

allvalues(H);

(2*x+7)^(1/2), -(2*x+7)^(1/2)

solve( H - x - 2, [x] );

[[x = 1], [x = -3]]

 

Download sqrt_RootOf.mw

I don't get an error if I used eval instead of subs to do the substitution.

simplification_error_ac.mw

I didn't bother to check which term gave a problematic (diff?) term.

Why did you choose subs to do a mathematical substitution?

The following will work not work in Maple 17 (released 2013), since DataFrames and Tabulate don't exist in that version. But it would work if you actually have Maple 2017, which is a different, later release.

You could augment the Matrix with an extra column and row, and then use the DocumentTools:-Tabulate command on that to display it nicely.

Or you could put the Matrix into a DataFrame, and call Tabulate directly on that. Here is an example of that. (It looks nicer in Maple's own GUI, and appears centered by default though that is optional.) 

restart;

S:=Matrix([[0,9,8,0,7],[3,5,6,5,1],
           [1,0,0,3,2]]);

Matrix(3, 5, {(1, 1) = 0, (1, 2) = 9, (1, 3) = 8, (1, 4) = 0, (1, 5) = 7, (2, 1) = 3, (2, 2) = 5, (2, 3) = 6, (2, 4) = 5, (2, 5) = 1, (3, 1) = 1, (3, 2) = 0, (3, 3) = 0, (3, 4) = 3, (3, 5) = 2})

DF:=DataFrame(S,
              rows=["small","medium","large"],
              columns=["Rose","Teal","Plum","Sand","Peach"]):

Tabulate(DF, widthmode=pixels, width=400):

 

 

Rose

Teal

Plum

Sand

Peach

small

0

9

8

0

7

medium

3

5

6

5

1

large

1

0

0

3

2

 

 

DF_example.mw

You already have the exact value. (The cube root of 2 is irrational, and a positive integer multiple of it is also irrational and cannot be expressed exactly as a rational -- if that's what you were expecting. That's mathematics, not just Maple.)

You can get a floating-point approximation using the evalf command.

C__temp1:=2^((105-25)/6);                                                         

                                 (1/3)
               C__temp1 := 8192 2

evalf(C__temp1);                                                                  

                    10321.27324

evalf[20](C__temp1);                                                              

                10321.273240738800966

When you load a package using the with command Maple rebinds the global name, such that a newly parsed expression will use whatever is the current binding of the name.

Several people throw around the term "overload" for this rebinding process, but that is a mistake. In Maple the term overload has quite a different technical meaning, and it's incorrect and wrong to mix up the two.

There is a procedure VectorCalculus:-`.` which is one of the package exports of the VectorCalculus package. When the VectorCalculus package is loaded, say by executing with(VectorCalculus) the name `.` is rebound to VectorCalculus:-`.` and that is what then gets called in your second example.

Your second example called with(VectorCalculus); but you omitted to show  the output displayed by that call. It contains a list of all the name that have been rebound to the package exports. One of those names printed is `.`, and by looking at that output and by reading the Help page for the with command you should be able to figure out that there is a VectorCalculus:-`.` export.

You can even utilize that export directly, without the whole package being loaded (as a prefix call rather that a infix call, however):

restart;
VC:=VectorCalculus:
f:=y*sin(x)+y^2:
VC:-`.`( VC:-Nabla, VC:-Nabla(f,[x,y]) );

                    2 - y sin(x)

The act of rebinding the name is done via the (undocumented) bind command, which the with command utilizes. Similarly the unwith command utilizes the (undocumented) unbind command. These work like a stack, such that calling unwith will restore the previous binding. I don't recommend anyone using bind and unbind directly; utilize with and unwith instead.

In this stack model, the last rebinding is what gets used. If you load the plots package then Maple rebinds the name arrow to plots:-arrow. If you subsequently load the plottools package then Maple futher rebinds the name arrow to plottools:-arrow, replacing the previous binding. If you then unload the plottools package then the binding of arrow reverts to the previous binding to plots:-arrow.

The name management functionality offered by with/unwith is there to assist people and make common operations easier. It cannot offer perfect management of the namespace because such a thing is impossible: there are cases where two different people want two different behaviors under otherwise identical circumstances.

So there will always be cases where qualifying commands names (using the colon-minus syntax to distinguish between different exports from different packages, and the global names) is necessary or highly preferable.

The mechanisms for "overloading" a name so that a procedure is able to dispatch according to the type of the arguments are different and distinct from rebinding. But the rebinding mechanism and the overloading mechanisms can be constructively utilized together, and together they make for even more power and flexibility of managing the command namespace.

In current Maple there is an overload option for procedures which can allow for a dynamic dispatch functionality according to argument type, say. In other words the code's branches off, according to the type of the arguments. But even before that option was introduced a procedure could be written to examine its arguments and dispatch dynamically.

Several packages have exports which examine the type of the arguments and, according to what is discovered, either do a computation or return a call to the global instance of the same or similar name. For example, Units:-Standard:-`+` will eventually return an expression in terms of the usual global :-`+` after dealing with units or if no units were detected. But some other commands (whose name happens to match a global version) will return as an unevaluated call to themselves rather than to as a call to the global version. There are no hard and fast rules -- the functionality needs, implementations, strengths and weaknesses vary.

Another related piece of functionality for dynamic dispatch involves the static exports of an object.

There is a great deal that could be written about these topics, and I'm not about to write a book here. I suggest reading the Programming Guide and relevant Help pages, and then asking specific questions about specific examples as wanted.

Hopefully I have not misunderstood your intention.

Once I'd set up cartesian coordinates under VectorCalculus I used command-completion in 2D Input.

I typed Del and pressed the Escape key (for Maple GUI command-completion on my Linux), and picked the entry "Del (divergence)" which shows the Nabla-dor markup.

Then I typed Gradient and pressed the Escape key, and picked gthe entry "PhysicsGriadient" because, well, because it seemed to show the right 2D markup.

Here's the result. I used 2D Input only for the line in question. I also include what the input converted to as 1D Notation.

restart;

with(VectorCalculus):

f := y*sin(x)+y^2:

SetCoordinates(cartesian[x,y]):

VectorCalculus[Nabla].Nabla(f)

2-y*sin(x)

(VectorCalculus:-Nabla) . (Nabla(f));

2-y*sin(x)

``

Download VC.mw

It also worked for me if (in 2D Input mode) I used the "Del" entry from the "Common Symbols" palette, along with either a typed period or the center-dot from the same pallete. But I used just f, having already set the coordinates.

Escape the doublequotes, eg.

-c 'path:=\"/home/eduardo/examples\";'

@janhardo Your procedures are named InflectionF which is capitalized, but you accidentally tried to call them as uncapitalized inflectionF.

You should generally not have your procedures rely on having loaded a package at the top-level by the with command. It's better (IMO) to utilize the uses facility within a procedure body, or to utilzie the fully qualified names for commands. I show one way to do that below.

Your declaration of G as local is enough. Your attempt to declare G[1..6,1] as local is invalid. I corrected that.

I leave it to you to add the interval as an additional parameter for your procedures.

 

 

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

Seems that task 6 is about drawing tangentlines in graph for 6 points (x0..x5) and dividing the interval a..b in 5 intervals
So the procedure input  must be
procedure ( function,interval a..b)
Did not add the interval a..b in the interval in the procedure and  the tw procedures below are not working yet.

================================================================

Example 2.3 code ..

restart;

with(Student[Calculus1]):

 

f := x -> x^sin(x):
df := D(f):
ddf := D(D(f)):
G := Array(1..6, 1..4):
P := Array(1..6, 1..2):
G[1..6, 1] := <Student:-Calculus1:-Roots(ddf(x), x=0..16, numeric)>:
for i from 1 to 6 do
  G[i, 2] := f(G[i, 1]):
  G[i, 3] := df(G[i, 1]):
  G[i, 4] := G[i,2]+G[i,3]*(x-G[i,1]):
  P[i, 1] := plot(G[i,4], x=G[i,1]-1..G[i,1]+1,
                  colour=red, adaptive=false, numpoints=2):
  P[i, 2] := plots:-pointplot([G[i,1],G[i,2]], symbol=solidcircle,
                              symbolsize=15, color=blue):
end do:
plots:-display(plot(f, 0..16, color=black),
               seq(seq(P[i,j], i=1..6), j=1..2),
               size=[500,300]);

 

 

Using this code for making a procedure.
Function input in procedure : as expression or as function ?

Procedurename : InflectionF (function, interval,two points in interval  )

Note: in code above the interval has a fixed value, so a variable intvx=a..b is needed

 

restart;

InflectionF := proc(f)
  local df, ddf, G, P, i, j ;
  uses Student:-Calculus1, plots;   
  df := D(f):
  ddf := D(D(f)):
  G := Array(1..6, 1..4):
  P := Array(1..6, 1..2):
  G[1..6, 1] := <Student:-Calculus1:-Roots(ddf(x), x=0..16, numeric)>:
  for i from 1 to 6 do
    G[i, 2] := f(G[i, 1]):
    G[i, 3] := df(G[i, 1]):
    G[i, 4] := G[i,2]+G[i,3]*(x-G[i,1]):
    P[i, 1] := plot(G[i,4], x=G[i,1]-1..G[i,1]+1,
                    colour=red, adaptive=false, numpoints=2):
    P[i, 2] := pointplot([G[i,1],G[i,2]], symbol=solidcircle,
                         symbolsize=15, color=blue):
  end do:
  display(plot(f, 0..16, color=black),
          seq(seq(P[i,j], i=1..6), j=1..2),
         size=[500,300]);
end proc:

InflectionF(x -> x^sin(x));  

 

 

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

Other solution of task .. procedure ?

restart;

with(Student:-Calculus1):
with(plots):

f := x -> x^sin(x);

proc (x) options operator, arrow; x^sin(x) end proc

df := D(f);

proc (x) options operator, arrow; x^sin(x)*(cos(x)*ln(x)+sin(x)/x) end proc

ddf := D(D(f));

proc (x) options operator, arrow; x^sin(x)*(cos(x)*ln(x)+sin(x)/x)^2+x^sin(x)*(-sin(x)*ln(x)+2*cos(x)/x-sin(x)/x^2) end proc

Inflpts := [ fsolve(ddf(x), x=0..16, maxsols=6) ];

[1.395288666, 2.916095859, 7.258616747, 8.576145755, 13.57205647, 14.75675948]

Q := map(p->[p,f(p)], Inflpts);

[[1.395288666, 1.388167079], [2.916095859, 1.270355627], [7.258616747, 5.161057836], [8.576145755, 5.015577540], [13.57205647, 9.048000408], [14.75675948, 8.947326153]]

# The tangent lines, using point-slope form
T := seq(plot(df(p)*(x-p)+f(p), x=p-1..p+1), p=Inflpts):

display(FunctionPlot(f(x), x=0.0..16.0, sign=[], slope=[],
                     caption="", pointoptions=[symbolsize=1],
                     concavity=[color(cyan,magenta),filled(coral,wheat)]),
        T,
        pointplot(Q, symbolsize=10, symbol=solidcircle,
                  color=blue, legend="inflection points"),
        axis[1]=[tickmarks=Inflpts], size=[800,400]);

 

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

restart;

InflectionF := proc(f)
  local df, ddf, G, P, Inflpts, Q, T;
  uses Student:-Calculus1, plots;
  df := D(f);
  ddf := D(D(f));
  Inflpts := [ fsolve(ddf(x), x=0..16, maxsols=6) ];
  Q := map(p->[p,f(p)], Inflpts);
  T := seq(plot(df(p)*(x-p)+f(p), x=p-1..p+1), p=Inflpts):
  display(FunctionPlot(f(x), x=0.0..16.0, sign=[], slope=[],
                       caption="", pointoptions=[symbolsize=1],
                       concavity=[color(cyan,magenta),filled(coral,wheat)]),
          T,
          pointplot(Q, symbolsize=10, symbol=solidcircle,
                    color=blue, legend="inflection points"),
          axis[1]=[tickmarks=Inflpts], size=[800,400]);
end proc:

InflectionF(x -> x^sin(x));

 

 

Download betounes_ex_set_2_opg_6_ac.mw

I suggest that you also add the name x as a local to your procedure, if you intend to continue to utilize it as a dummy name therein. Otherwise your procedure will not work if the name x has been assigned, say, a numeric value at the higher level.

You can use the maplemint command to get an idea of which names in your procedure should be guarded against colliding with assigned values at the higher level. I include this attachment, for some ideas on making your procedures robust against collision with assigned global names.
  betounes_ex_set_2_opg_6_maplemint.mw

Your procedure foo returns an unevaluated name if it is passed a name and is not passed an actual table. And not just any name. Your procedure foo returns the very same name that it is passed (when passed a name).

Even though the formal parameter of foo is specified to have be of type table, it also accepts any name which evaluates to a table. It allows that because tables have last-name-eval, so that they can be operated on in-place as a usefully behaving mutable structure.

The returned name happens to evaluate to a table, unless you somehow unassign it -- which can be done in a few ways.

In your first example B does not get assigned a table per se, but rather B gets assigned the returned, unevaluated global name A which was passed as argument in the call to foo. Your first example unhelpfully used a colon to suppress the output. I change that to a semicolon, which shows that a call to procedure foo returns the name that was passed. Since that A evaluates to a table then a subsequent, full evaluation of B does also. But notice that a 1-level evaluation of B returns just A the name.

restart;

foo:=proc(A::table)
  A["c"]:=3; #add new field
  return A;
end proc:

A:=table():
A["a"]:=1:
A["b"]:=2:

B:=foo(A);
                      B := A

eval(B);
          TABLE(["a" = 1, "c" = 3, "b" = 2])

eval(B,1);
                         A

In your second example you are assigning the unevaluated name A (both passed in the call to foo and also returned by that call to foo) to A itself. You are not explicitly (re)assigning any table to A, but rather you are assigning a name that would evaluate to a table (unless it were reassigned something else -- which is precicely what's happening here!). Recall, foo returns a name, not an actual table.

In the second example your call,

   A:=foo(A);

is assigning the unevaluated name A to A itself. You have probably seen that kind of thing before. It is a common way to unassign a name:

   A := 'A';

In other words, your second example happens to assign to A its very own name, unevaluated. That unassigns it.

That should be enough to explain your second example. It assigns the unevaluated name A to itself. And so A no longer evaluates to anything else.

Of course, if you passed foo an actual table (for example, the value to which A evaluated after its original assignment) then it would also return an actual table.

A:=table():
A["a"]:=1:
A["b"]:=2:

eval(A);
                   TABLE(["a" = 1, "b" = 2])

A:=foo(eval(A)):
eval(A);

               TABLE(["a" = 1, "c" = 3, "b" = 2])

As I mentioned at the start, your procedure foo returns the same name as it gets passed. I think that your examples would be a bit less confusing if it used another name for the formal parameter of the procedure foo. The examples would behave the same if foo were defined as follows:

foo:=proc(H::table)
  H["c"]:=3; #add new field
  return H;
end proc:

Lastly, there are other things with last-name-eval which would also be unassigned by your second kind of example. For instance, procedures also have last-name-eval, so your procedure foo also unassigns f below.

restart;

foo:=proc(K)
  K["c"]:=3; #add new field
  return K;
end proc:

f := x -> sin(x):
eval(x);

x

f := foo(f);

f

eval(f);

f

 

And here are your original two examples

 

A:=table():
A["a"]:=1:
A["b"]:=2:

B:=foo(A):

eval(B,1);

A

eval(B);

table( [( "b" ) = 2, ( "a" ) = 1, ( "c" ) = 3 ] )

A:=table():
A["a"]:=1:
A["b"]:=2:

A:=foo(A):

eval(A);

A

 

Download LNE_example.mw

 

Is this adequate?

restart;

f := proc(Z::[identical(a,b,c,d),identical(a,b,c,d)])
  print("ok");
end proc:

f([a,a]), f([a,b]), f([d,c]);

"ok"

"ok"

"ok"

f([a]);
f([a,b,c]);
f([a,x]);

Error, invalid input: f expects its 1st argument, Z, to be of type [identical(a, b, c, d), identical(a, b, c, d)], but received [a]

Error, invalid input: f expects its 1st argument, Z, to be of type [identical(a, b, c, d), identical(a, b, c, d)], but received [a, b, c]

Error, invalid input: f expects its 1st argument, Z, to be of type [identical(a, b, c, d), identical(a, b, c, d)], but received [a, x]

 

Download type_list.mw

Was the "extra" information to ban repeats there when I first answered this? I don't recall seeing it. But perhaps I didn't notice. If I'd noticed then my answer would include a check for nops of the list. The key thing is the identical(a,b,c,d) I suppose.

The implicit declaration of `a` as local happens when the procedure is created, as opposed to when it is run. In your second example both `a` and `b` are implicitly declared local variables.

So, after the procedure is created, it is the same as if it were defined using,

   local a,b;

So the line

   b:=a+10;

will access the local instance of `a`.

It's unclear to me why you would expect 20 for the second example's returned value. (You didn't explain your reasoning.)

The following behaves just as you have originally described. The originally posted question was this:

   How can I create an even function in Maple—i.e. g(−x) = g(x)—so
   that g(−3) returns g(3), g(10) returns g(−10), and so on?

I'm, not sure that's really what you after, though. Did you want it to compute anything more concretely?

g:=proc(ee)                                        
   return 'procname'(-ee);                          
end proc:

g(-3);
                g(3)

g(10);
                g(-10)

g(-x);
                g(x)

g(x); 
                g(-x)

g(0);
                g(0)

 

1 2 3 4 5 6 7 Last Page 1 of 213