## 18245 Reputation

14 years, 243 days

## pardon?...

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

## not my favourite...

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

## ok...

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

 > df := D(f);

 > ddf := D(D(f));

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

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

 > # 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

## hmm...

@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?!

## followups...

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

## Maple 2016.2...

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

## what?@...

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

## Vector...

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

## fyi...

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

## diff versus D...

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

 > ans1 := D(f3);

 > ans1(2.3);

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

 > eval(ans2, x=2.3);

 >

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.

## domain?...

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

## comment...

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

## why...

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?

## hmm...

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

## Typeset...

`Typesetting:-Typeset(log[10](sigma^2))`
```plot([[0,0]], labels=[ typeset('log[10](sigma^2)'), "y" ]);