3
$\begingroup$

Using V12. I don't understand this:

Nest[sin, x, 3]

gives

sin[sin[sin[x]]]

and

Nest[Sin,1.2,3]` 

gives

71933

Table[Nest[Sin,x,3],{x,-6,6}] 

gives

{-Sin[Sin[Sin[6]]], -Sin[Sin[Sin[5]]], -Sin[Sin[Sin[4]]], 
 -Sin[Sin[Sin[3]]], -Sin[Sin[Sin[2]]], -Sin[Sin[Sin[1]]], 0, 
 Sin[Sin[Sin[1]]], Sin[Sin[Sin[2]]], Sin[Sin[Sin[3]]], 
 Sin[Sin[Sin[4]]], Sin[Sin[Sin[5]]], Sin[Sin[Sin[6]]]}. 

But

Table[Nest[Sin, x, 3],{x, -2Pi, Pi}] 

gives

{0, Sin[Sin[Sin[1]]], Sin[Sin[Sin[2]]], Sin[Sin[Sin[3]]], 
 Sin[Sin[Sin[4]]], Sin[Sin[Sin[5]]], Sin[Sin[Sin[6]]], 
 Sin[Sin[Sin[7]]], Sin[Sin[Sin[8]]], Sin[Sin[Sin[9]]], 
 Sin[Sin[Sin[10]]], Sin[Sin[Sin[11]]], Sin[Sin[Sin[12]]]}

Isn't this supposed to be something like:

{0, - Sin[Sin[Sin[**5.28**]]], ... Sin[Sin[Sin[6.28]]]=0}

Of note: the plot of the same seems to make sense:

Plot[Nest[Sin, x, 3],{x, -2Pi, 2Pi}]

Plot

$\endgroup$
8
$\begingroup$

The results are correct. The Table expression iterates over values of x that range from 0 - 2π to 9 - 2π. We can see this if we use NestList:

Table[NestList[Sin, x, 3], {x, -2 Pi, Pi}] // Column

output screenshot

The -2π terms drop out because they adjust the angles by a full circle turn, i.e. to no effect. Since the remnant arguments to Sin are exact integers, Mathematica leaves the results in exact symbolic form. If we wish to force them to be evaluated numerically, we can use N:

Table[N@Nest[Sin, x, 3], {x, -2 Pi, Pi}]
(* {0., 0.67843, 0.7097, 0.140189, -0.633911,
    -0.730172, -0.272311, 0.573469, 0.741749, 0.389926} *)

Should we wish to view the numeric values of x but leave the nested Sin expressions unevaluated, we can use Inactive:

Table[N@Nest[Inactive[Sin], x, 3], {x, -2 Pi, Pi}] // Column

result screenshot

... which can be subsequently activated:

Activate[%]

result screenshot

The small inaccuracy in the first result shows why Mathematica prefers to work in exact symbolic form.

We can verify the individual symbolic and numeric results to confirm that they are equivalent within the vagaries of inexact arithmetic. For example, the second result for 1 - 2π:

Sin[Sin[Sin[1 - 2π]]] // N
(* 0.678429 *)

Sin[Sin[Sin[1]]] // N
(* 0.678429 *)

1 - 2π // N
(* -5.28319 *)

Sin[Sin[Sin[-5.28319]]]
(* 0.678429 *)
| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.