acer

32480 Reputation

29 Badges

20 years, 6 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are replies submitted by acer

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

@janhardo That is certainly not my favourite command for finding real roots within a finite real range, which is why I did not suggest it. It happens to handles your example, but for other examples you could need to exclude nonreal (imaginary) roots, which could require special handling in the case of unfortunate scaling.

Also, it was accidentally used wrongly because you misstated the problem, originally. The expression you gave as fprime_expr is in fact already the 1st derivative of x^sin(x). which is the actual expression in the documents you eventually attached. And so you'd need to pass diff(fprime_expr,x) to Analytic and not diff(fprime_expr,x,x).
  expression:   f(x) = x^sin(x)
  1st deriv.       fprime_expr = diff(f(x),x)
  2nd deriv.      diff(fprime_expr,x) = diff(f(x),x,x)

So the Analytic call you once again mentioned is not right for your problem. You need to find the roots of the 1st derivative of fprime_expr instead of its 2nd derivative, in order to find the inflection points of x^sin(x).

I suggest to you that the Student:-Calculus1 package has commands which handle your problem gracefully.

But we do not know whether the goal of the coursework is primarily to teach you Maple programming or Calculus.

@janhardo The following uses x^sin(x) for the expression.

It uses fsolve to find the six roots of the 2nd derivative within x=0..16, which are the inflection points.

It plots the curve f(x), Q[i] the inflection points on the curve, and T[i] the 6 tangent lines to the curve (at those inflection points, from x=p[i]-1 to x=p[i]+1).

It also fills the region according to the sign of the 2nd derivative, ie. the concavity. But if you prefer you could replace that FunctionPlot call with merely a simple plot of f(x) itself.

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

 

inflectionpts_2018.mw

Here are several ways to compute multiple real roots numerically over a given finite range, which can be used to compute the inflection points of your example. (There are many ways to accomplish that goal -- this is a sample of them.) inflectionpts_multiple.mw

@janhardo Why did you wait until your 3rd or 4th comment to provide the full details of the question?

It seems that the first plot in my answer, extended to x=16, with tangent lines at the inflectuon points, is the goal.

Also, you still have not confirmed explicitly whether the expression (whose inflection points are desired) is x^sin(x) or your original expression. Which is it?!

Please submit your followup details for this example to this same thread, instead of submitting separate Question threads which unhelpfully split the details and responses.

(Duplicate threads will be flagged as such, and may be deleted.)

If you want to compute multiple roots then see the use of Rootfinding:-AnalyticStudent:-Calculus1:-Roots , fsolve, or RootFinding:-NextZero in the answers and attachments below. You can use those commands on the expression or its derivatives (according to what kind of points you are looking for). See also the use of the Student:-Calculus1:-InflectionPoints command.

First 178 179 180 181 182 183 184 Last Page 180 of 594