2
$\begingroup$

After NumberForm I cannot apply a Sine function. Why?

This works:

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

Output = $\{-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\}$

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\}]$

What can I do to make this work?

$\endgroup$
1
  • $\begingroup$ Point nr. 8 here is relevant. $\endgroup$
    – C. E.
    Sep 3, 2015 at 21:42

2 Answers 2

7
$\begingroup$

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] *)
$\endgroup$
0
$\begingroup$
NumberForm[N[x /. Solve[x^2 - 3 == 0, x]], 6]

Sin[%]

(* {-1.73205,1.73205} *)

(* {-0.987027, 0.987027}*)
$\endgroup$
6
  • $\begingroup$ The first input needs to be evaluated before you apply Sine function, therefore use Sin[%] $\endgroup$
    – thils
    Sep 3, 2015 at 10:58
  • $\begingroup$ Hmm, interesting. But why isn't the Sin applied directly when I do Sin[sol3]? $\endgroup$ Sep 3, 2015 at 10:58
  • $\begingroup$ 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? $\endgroup$
    – Jason B.
    Sep 3, 2015 at 11:01
  • $\begingroup$ @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? $\endgroup$
    – MarcoB
    Sep 3, 2015 at 16:09
  • $\begingroup$ @MarcoB pls delete ";" , have edited this bit. Numberform attributes are described in the manual. $\endgroup$
    – thils
    Sep 3, 2015 at 23:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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