acer

32333 Reputation

29 Badges

19 years, 322 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are replies submitted by acer

@radaar If you read my Answer closely enough, you would see that I stated that the procedure is the same whether the locals are declared explicitly or implicitly. The procedure is the same, either way.

Let's see that:

ff:=proc() a:=a+10: return a: end proc:
Warning, `a` is implicitly declared local to procedure `ff`
print(ff);

       proc() local a; a := a + 10; return a end proc

gg:=proc() local a; a:=a+10: return a: end proc:
print(gg);                                      

       proc() local a; a := a + 10; return a end proc

evalb(eval(ff)=eval(gg));

                      true

evalb(ToInert(eval(ff))=ToInert(eval(gg))); 

                      true

I also stated in my Answer that the local declaration is something that becomes a part of the procedure as soon as it is defined. So, the "localness" of `a` will hold throughout the procedure, and not occur, say, just when it gets assigned.

Also, your followup Comment stated that the "output" was a+10 . But that's just the return value. The output in my session also includes the message about `a` being declared local to `ff`. This is also true for your Question's second example.

restart;

a:=10:

ff:=proc()
  a:=a+10:
  return a:
end proc:
Warning, `a` is implicitly declared local to procedure `ff`

ff();
                 a + 10

In the second example of your Question you commented that `b` is an "implicit local". But `a` is also an "implicit local", for the very same reason.

The second one doesn't follow your original description. Originally, you wrote: "g(−3) returns g(3)".

If what you actually meant was that g(-3) should return the same thing as what g(3) returns then the original description was incorrect.

That contradicts your original description's implications.

You see, your original description implied that g(10) would return g(-10) and also that g(-10) would return g(10). If both of those hold then g(10) - g(-10) won't return 0. Instead, it would return g(-10) - g(10).

However, here are two variants, for both of which your followup condition  g(-x) - g(x) = 0  holds:

g := proc(ee)
  if sign(ee)=-1 then 'procname'(-ee);
  else 'procname'(ee); end if;
end proc:

g(10);
                   g(10)

g(-10);
                   g(10)

g(-10) - g(10);                       
                     0

g(x);          
                    g(x)

g(-x);         
                    g(x)

g(-x) - g(x);  
                      0

and,

g := proc(ee)
  ('procname'(ee)+'procname'(-ee))/2;
end proc:

g(10);                                                     
               1/2 g(-10) + 1/2 g(10)

g(-10);                                                    
               1/2 g(-10) + 1/2 g(10)

g(-10) - g(10);                                            
                      0

g(x);                                                      
               1/2 g(x) + 1/2 g(-x)

g(-x);                                                     
               1/2 g(x) + 1/2 g(-x)

g(-x) - g(x);                                              
                       0

I am having trouble downloading the attachment from the link. Could you try relinking it? (Perhaps give it a simpler name, with only alphanumeric characters? Though I don't know whether that is the issue.)

ps. In one of those older threads I made a comment about a reusable procedure to generate an actual (scaled, inset) subplot.

@janhardo If you are beginning in programming in Maple, and if you want something gentler than the Maple Programming Guide, then I would recommend this recent book:

   Understanding Maple, by Ian Thompson

It is not expensive, is relatively new (2017), and is really quite good and straightforward. I have only a few quibbles with it. Associated worksheets are available from the author's homepage.

Another good book -- by someone with good experience in teaching with Maple -- is the following, older (2009) book. The author still has the associated worksheets available for download at his website.

   Getting started with Maple, 3rd ed., by Douglas Meade et al.

@janhardo The procedure in the shown image has a side-effect assignment on one of the arguments.

There are a few stock Maple commands that use such side effects as a way to accomplish an additional return value -- ie. in addition to the main returned result. But it was mostly only done that way because in the very distant past procedure calls could not do multiple assignment -- ie. return a sequence and assign to a sequence of names. 

It has never been a good Maple programming practice to use such a side-effect instead of doing any return value, which is what the procedure in the image does. This is further evidence that the book is not very good.

Similarly, having a procedure assign to a declared global instead of making any normal return value is not good practice.

For Maple versions 2018.0 to 2020.0, stored values for nonderived and adjusted constants appear to match what is in the published CODATA 2014.

For example,

ScientificConstants:-GetConstant(h);                                              
                                                    -33                       -41
Planck_constant, symbol = h, value = 0.6626070040 10   , uncertainty = 0.81 10   ,

    units = J s

The ScientificConstants references help page of Maple versions 2018.0 to 2020.0 indicates that the CODATA site was last accessed in 2015.

The ScientificConstants updates help page indicates that, since Maple 9, the methology of deriving additional values follows what was first advocated by NIST in 1998. See,
   P. J. Mohr and B. N. Taylor, Rev. Mod. Phys. 72(2), 351-495 (2000)
Unfortunately, the 2014 CODATA adjustment is not cited on that Maple help page.

Addionally, the set of CODATA values now published is larger. For example the current set also contains certain reciprocals. Accomodating any additional "adjusted constants" could be useful, though that might involve some awkward naming issues. See,
    P. J. Mohr, D. B. Newell, and B. N. Taylor, Rev. Mod. Phys. 88(3), 035009 (2016)

A more recent "CODATA 2018" collection of values has been available since May 20, 2019. These could be used to update the values stored in Maple. See here

@vv The evaluation done inside that SEQ will not always produce the same behaviour as seq, if the example is executed within some procedure for which a is declared local.

@janhardo Please don't repost a duplicate of this.

@Hnx Please use the Reply button (whichever one appears at the bottom of the subthread to which you are responding), instead of using the Answer button.

I have converted your accidental Answers into Comments (Replies).

@Carl Love Changing the imaginary unit is insufficient to fix three of the four examples.

Your second equation contains the name y , which is unassigned and does not match either of the dependent functions y[o2] or y[co2]. That does not make sense.

You will need to correct those instances of y before you'd be able to plot any solution.

@janhardo No, it's not a lot more work. Look, the same approach can be done as in the earlier attachment you gave, CD2-5.MWS. The loops are merged together, as I mentioned could be done.

f := x -> x^sin(x):
df := D(f):
L := Student:-Calculus1:-Roots(D(D(f))(x), x=0..16, numeric):
G := Array(1..6, 1..3):
P := Array(1..6):
for i from 1 to 6 do
  G[i, 1] := L[i];
  G[i, 2] := df(G[i, 1]);
  G[i, 3] := f(G[i,1])+G[i, 2]*(x-G[i,1]);
  P[i] := plot(G[i,3], x=G[i,1]-1..G[i,1]+1, colour=red);
end do:
plots:-display(plot(f, 0..16, color=black),
               seq(P[i], i=1..6));

I made it a little longer earlier to get a few little effects (pointplot, etc), but mostly to make it easier for you to read.

I made the tangent lines run from L[i]-1 to L[i]+1 where L[i] is the ith inflection point. That is exactly what the attached question requested.

Here is is with a few more bells and whistles. The angle-brackets <...> around the call to Student:-Calculus1:-Roots create a column Vector, which I then write directly ino the first column of Array G. Since the values are stored in G then I may as well use another column and store both y values as well as the slopes y' at the inflection points.

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]);

Now compare with an approach that does not use loops and stored values which serve no great purpose. This is very similar to what I did earlier. It produces the same plot as immediately above.

f := x -> x^sin(x):
df := D(f):
L := Student:-Calculus1:-Roots(D(D(f))(x), x=0..16, numeric):
Q := map(p->[p,f(p)], L):
T := seq(plot(df(p)*(x-p)+f(p), x=p-1..p+1, color=red), p=L):
plots:-display(plot(f, 0.0..16.0, color=black), T,
        plots:-pointplot(Q, symbolsize=10, symbol=solidcircle,
                  color=blue), size=[800,400]);

As far as I can tell the author of your book prefers using loops and Arrays, even for things which seq and map would make somewhat simpler.

Yes, that last does compute f(p) twice, but it could also have used elements from Q instead. This produces the same tangents.

T := seq(plot(df(Q[i,1])*(x-Q[i,1])+Q[i,2], x=Q[i,1]-1..Q[i,1]+1, color=red),
         i=1..6):

@janhardo Sure, one could store all intermediary values in Arrays (lowercase array is deprecated now). In my opinion that just makes the task longwinded.

In the attached I do the Array assigments using loops (and equivalents using seq, commented out).

inflection_Array_loop_seq.mw

[edit] When I submitted this response the link to the .mws worksheet was not yet present in the previous Comment. Having now seen the .mws sheet I still think that storing the values/formulas/plots in arrays has no major benefit here -- except to learn technique. Even with all the loops are merged together, it doesn't seem to give a great deal of added insight or convenience.

@janhardo I don't understand what you are now trying to accomplish. I already showed how the tangent lines could be constructed from the inflection points (using point-slope form).

The computation of where the 1st derivative is zero is irrelevant to the question asked. You simply do not need these for the question in the attachment:
  solve( df_expr =0, x)
  Roots(df(x), x=0.1..16, numeric)
That is the same mistake as in your original posted Question, where you had,
  solve( fprime_expr =0, x)
It is irrelevant to the inflection points computation. The fact that you try it again here make it look like you do not understand the concept of inflection point.

Also, there is little benefit in putting the results (point, eqautions of tangent lines etc) into a single array.

The tangent lines' slopes are the 1st derivative of x^sin(x) evaluated at the inflection points (at which its 2nd derivative is zero). You could store those in an Array, prior to forming the tangent lines' plots, but that doesn't seem especially useful as they only get used once. Again, this does not involve points at which the 1st derivative is zero.

All I see is that you have taken something that should be straightforward and made it unnecessarily more complicated, and muddled.

The question in the attachment can be answered as easily as this:

f := x -> x^sin(x);
Inflpts := [fsolve(D(D(f))(x), x=0..16, maxsols=6)];
Q := map(p->[p,f(p)], Inflpts):
T := seq(plot(D(f)(p)*(x-p)+f(p), x=p-1..p+1, color=red), p=Inflpts):
plots:-display(plot(f, 0.0..16.0, color=black), T,
        plots:-pointplot(Q, symbolsize=10, symbol=solidcircle,
                  color=blue, legend="inflection points"),
        axis[1]=[tickmarks=Inflpts], size=[800,400]);

Another way to label the inflection points is to use textplot, eg.

f := x -> x^sin(x):
Inflpts := [fsolve(D(D(f))(x), x=0..16, maxsols=6)];
Q := map(p->[p,f(p)], Inflpts):
T := seq(plot(D(f)(p)*(x-p)+f(p), x=p-1..p+1, color=red), p=Inflpts):
plots:-display(plot(f, 0.0..16.0, color=black), T,
        plots:-pointplot(Q, symbolsize=10, symbol=solidcircle, color=blue),
        map(p->plots:-textplot(evalf[4]([p[1]-sign(D(f)(p[1]))*2/3,p[2]+1,p]),
                               font=[Times,8]),Q), size=[800,400]);

First 175 176 177 178 179 180 181 Last Page 177 of 591