acer

32348 Reputation

29 Badges

19 years, 330 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are replies submitted by acer

@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.

@J F Ogilvie 

It works in my Maple 2016.2 if I replace the definition of the frame procedure with this:

frame := proc(t)
  plots:-display(plots:-display(P1,color="Red",_rest),
    plots:-display(rotate(P2, Pi/2*t, [[1,1,0],[1,0,0]]),color="Green",_rest),
    plots:-display(rotate(P3, Pi/2*t, [[0,1,0],[1,1,0]]),color="Blue",_rest));
end proc:

square-partitioned-into-pyramids_2016.mw

I am not sure whether Reuben had modifed the animation play controls for playback, say for looping.

This post reminds me of something that I had been meaning to post on myself. The help page for topic plot3d,viewpoint claims in its Notes that, "The viewpoint option can only be used with a static plot and not with an animation created through the plots[display] or plots[animate] command." But this is not true, and the current case is a counterexample. My experimentation indicates that a usual animation of a sequence of plots can work nicely with the viewpoint option, though it seems to work best if the number of frames (plots) matches what the viewpoint option specifies (or has as its own default, or inherits from the animation -- ie. is not forced higher by the option than the supplied number of plots). 

@tomleslie You wrote, "inflection points are where the gradient of the function is zero - that's the first derivative, not the second as given by Kitonum."

That is wrong.

However, there is a chance that fprime_expr provided by the OP is actually the first derivative of the thing for which he is expected to obtain the inflection points.

 

@janhardo Why do you use Array instead of Vector and Matrix?

Upload a worksheet/document, that contains the 1D Array example that is problematic for you.

(Whenever you have any problem, upload a representative worksheet and attach it to your Question/Reply.)

@janhardo You can do this using so-called simplify with side-relations.

simplify(1/a^2+1/b^2+1/c^2,
         {1/a+1/b+1/c=7, a+b+c=3*a*b*c});

                          43
First 176 177 178 179 180 181 182 Last Page 178 of 592