-2

*For this function $f(\text{x$\_$})\text{:=}x^{\sin (x)}$ want to do some research:

The start with the definition of the function already creates a error?

f[x_] := x^Sin[x]

$Failed

Then i did some function investigation for inflection points

Interesting how to do this for the inflection points ?

enter image description here

janhardo
  • 659
  • 3
  • 12
  • I just typed f[x_] := x^Sin[x] in V 13.0.1 on windows and got no error. Did you try with clean kernel? I do not see why this definition would give $Failed What version are you using? – Nasser Mar 02 '22 at 10:00
  • I am also on windows 10 with 12.3 MMA version, i will try to restart. Note: make same adjustment to my question to focus on this issue – janhardo Mar 02 '22 at 10:13
  • Ok, its working again, maybe opening two notebooks at the same time for one kernel is not allowed? – janhardo Mar 02 '22 at 10:24
  • One definition overriding the other without the user realizing it is not good for the user. – Syed Mar 02 '22 at 10:27
  • It is generally considered good practice (best practice?) to Clear variables before using them as the function name in the definition of a new function. Clear[f]; f[x_] := x^Sin[x] will avoid potential conflicts. – LouisB Mar 02 '22 at 11:13
  • @ LouisB , i did ClearAll[x]... – janhardo Mar 02 '22 at 11:43

1 Answers1

1

Plotting with a ColorFunction does not draw the curve, therefore you must draw the curve separately and then use Show.

f[x_] = x^Sin[x];

mm1 = {x, f[x]} /. FindRoot[f'[x] == 0, {x, 2}] ; mm2 = {x, f[x]} /. FindRoot[f'[x] == 0, {x, 8}]; mm3 = {x, f[x]} /. FindRoot[f'[x] == 0, {x, 14}];

r11 = {x, f[x]} /. FindRoot[f''[x] == 0, {x, 1}] ; r12 = {x, f[x]} /. FindRoot[f''[x] == 0, {x, 3}]; r21 = {x, f[x]} /. FindRoot[f''[x] == 0, {x, 7}]; r22 = {x, f[x]} /. FindRoot[f''[x] == 0, {x, 8.5}]; r31 = {x, f[x]} /. FindRoot[f''[x] == 0, {x, 13.5}]; r32 = {x, f[x]} /. FindRoot[f''[x] == 0, {x, 15}];

l11 = {{x - 1, f[x] - f'[x]}, {x + 1, f[x] + f'[x]}} /. x -> r11[[1]]; l12 = {{x - 1, f[x] - f'[x]}, {x + 1, f[x] + f'[x]}} /. x -> r12[[1]]; l21 = {{x - 1, f[x] - f'[x]}, {x + 1, f[x] + f'[x]}} /. x -> r21[[1]]; l22 = {{x - 1, f[x] - f'[x]}, {x + 1, f[x] + f'[x]}} /. x -> r22[[1]]; l31 = {{x - 1, f[x] - f'[x]}, {x + 1, f[x] + f'[x]}} /. x -> r31[[1]]; l32 = {{x - 1, f[x] - f'[x]}, {x + 1, f[x] + f'[x]}} /. x -> r32[[1]];

col = Function[{x, y}, Piecewise[{{Orange, x < r11[[1]]}, {LightGray, r11[[1]] < x < r12[[1]]}, {Orange, r12[[1]] < x < r21[[1]]}, {LightGray, r21[[1]] < x < r22[[1]]}, {Orange, r22[[1]] < x < r31[[1]]}, {LightGray, r31[[1]] < x < r32[[1]]}, {Orange, r32[[1]] < x}}]];

Show[ Plot[f[x], {x, 0, 16}, ColorFunction -> col, Filling -> Axis, ColorFunctionScaling -> False, Epilog -> {{PointSize[0.01], Blue, Point[{r11, r12, r21, r22, r31, r32}], Red, Point[{mm1, mm2, mm3}]},Green, Line[{l11, l12, l21, l22, l31, l32}]}] , Plot[f[x], {x, 0, 16}] ]

enter image description here

Daniel Huber
  • 51,463
  • 1
  • 23
  • 57
  • Thanks , interesting also for me is the mapping of the functionvalues into f''(x) . Suppose instead i used Nsolve. NSolve[{f''[x] == 0, 0 < x < 20}, x] (*{{x -> 1.39529}, {x -> 2.9161}, {x -> 7.25862}, {x -> 8.57615}, {x -> 13.5721}, {x -> 14.7568}, {x -> 19.8785}}*) – janhardo Mar 02 '22 at 11:52
  • Of course, this will also work. – Daniel Huber Mar 02 '22 at 11:59
  • Findroot works with a search interval for f''(x) and NSolve gives directly these 6 values. – janhardo Mar 02 '22 at 12:32