After NumberForm I cannot apply a Sine function. Why?

After NumberForm I cannot apply a Sine function. Why?

This works:

sol1 = x /. Solve[x^2 – 3 == 0, x]
Sin[sol1]

Output = {−Sin[√3],Sin[√3]}\{-Sin[\sqrt{3}],Sin[\sqrt{3}]\}

Also this works:

sol2 = x /. Solve[x^2 – 3 == 0, x] // N
Sin[sol2]

Output = {−0.987027,0.987027}\{-0.987027,0.987027\}

Then why doesn’t this work? Meaning, why is Sin[] not applied to the elements of the list?

sol3 = NumberForm[x /. Solve[x^2 – 3 == 0, x] // N, 6]
Sin[sol3]

Output = Sin[{−1.73205,1.73205}]Sin[\{-1.73205,1.73205\}]

What can I do to make this work?

=================

  

 

Point nr. 7 here is relevant.
– C. E.
Sep 3 ’15 at 21:42

=================

2 Answers
2

=================

Use FullForm to see the differences

sol3 = NumberForm[x /. Solve[x^2-3 == 0, x]//N, 6]
(* {-1.73205,1.73205} *)

This definition includes the NumberForm wrapper that was intended just for printing.

sol3//FullForm
(* NumberForm[List[-1.7320508075688772`,1.7320508075688772`],6] *)

Alternatively, use Information to look at the stored definition

?sol3
(* Global`sol3
sol3=NumberForm[{-1.73205,1.73205},6] *)

Consequently, the input to Sin is neither numeric nor a List of numeric values

Sin[sol3]//FullForm
(* Sin[NumberForm[List[-1.7320508075688772`,1.7320508075688772`],6]] *)

You could Map the Sin to the appropriate level

Map[Sin,sol3,{2}]//FullForm
(* NumberForm[List[-0.9870266449903538`,0.9870266449903538`],6] *)

However, the common approach is to put the wrapper outside the definition

NumberForm[sol32=x/.Solve[x^2-3==0,x]//N,6]//FullForm
(* NumberForm[List[-1.7320508075688772`,1.7320508075688772`],6] *)

However, you have to use NumberForm again if you want the output of Sin to also be formatted with NumberForm

Sin[sol32]//FullForm
(* List[-0.9870266449903538`,0.9870266449903538`] *)

NumberForm[Sin[sol32],6]//FullForm
(* NumberForm[List[-0.9870266449903538`,0.9870266449903538`],6] *)

NumberForm[N[x /. Solve[x^2 – 3 == 0, x]], 6]

Sin[%]

(* {-1.73205,1.73205} *)

(* {-0.987027, 0.987027}*)

  

 

The first input needs to be evaluated before you apply Sine function, therefore use Sin[%]
– thils
Sep 3 ’15 at 10:58

  

 

Hmm, interesting. But why isn’t the Sin applied directly when I do Sin[sol3]?
– Imre Végh
Sep 3 ’15 at 10:58

  

 

Yeah, what is going on here? This doesn’t answer the question of “Why?” at all. Taking Sin[sol3] doesn’t get evaluated. But typing sol3;Sin[%] does. So what gives?
– JasonB
Sep 3 ’15 at 11:01

  

 

This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post.
– blochwave
Sep 3 ’15 at 11:27

  

 

@thils On my computer (MMA 10.2 Win7-64) running your code outputs Sin[{-1.73205,1.73205}], not the values you show. How did you generate this behavior?
– MarcoB
Sep 3 ’15 at 16:09