acer

18245 Reputation

29 Badges

14 years, 243 days

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are replies submitted by acer

@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

@janhardo You are mixing up diff and D.

For an expression use the diff command. For an operator use the D command. (You accidentally tried to use D on an expression.)

restart;

f3:=x->4*sin(x^3)-x^2;

proc (x) options operator, arrow; 4*sin(x^3)-x^2 end proc

ans1 := D(f3);

proc (x) options operator, arrow; 12*x^2*cos(x^3)-2*x end proc

ans1(2.3);

53.88449890

ans2 := diff(f3(x),x);

12*x^2*cos(x^3)-2*x

eval(ans2, x=2.3);

53.88449890

 

Download set1_task4_comment.mw

Don't use the term function in the Maple context as you did above, as it's ambiguous and will confuse people. Use the term operator or procedure instead, which makes it completely clear that it is in contrast to an expression.

The Diff command provides an inert form of the diff command.

@AHSAN Your use of names is not good. You define lambda as a procedure, and then you define x as a polynomial in the name lambda. That confusion is going to cause you problems.

What is the domain over which you want your new polynomial to approximate your original rational polynomial? It may be difficult to produce such a single polynomial with 15-digit coefficients, that can approximate so closely both the domain -3..3 as well as the tails. (The numapprox package might serve better than just a polynomial fit.)

Why is a piecewise polynomial not adequate for your eventual task? You still have not informed us of where this original came from, or to what exact purposes you need to use the new approximation. Brief words don't help.

You appear to be stuck on the details of how to implement a scheme of your own devising to accomplish a goal that you won't explain. Maybe something other than your scheme could do better.

@AmirHosein Sadeghimanesh I only made one suggestion. The second thing I mentioned is something not to do.

You wrote, "I converted several 'ed variables into atomic variables."

What was the intended purpose of doing that? Was it a mistake?

Is one problem that you didn't keep a copy of the document from before you did that?

Do you intend on continuing to do that? Does that include copy&paste?

@AHSAN You didn't provide most of the details for which I asked.

I have deleted yet another duplicate of this question thread by you. Stop spamming this site with duplicates. Put your followup details here, instead of in a new Question.

@AmirHosein Sadeghimanesh 

Try this instead:

Typesetting:-Typeset(log[10](sigma^2))

I don't recommend the following approach, using uneval quotes -- the evaluation is only delayed, and the effect is undone by inadvertant, subsequent evaluation (which makes it fragile):

plot([[0,0]], labels=[ typeset('log[10](sigma^2)'), "y" ]);
%;

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