I was trying to evaluate this product
$$ \sin (1^\circ) \sin (2^\circ) \sin (3^\circ) ... \sin (88^\circ) \sin (89^\circ) \sin (90^\circ) $$
But I think it got weird results with this Product[Sin[i], {i, pi/180, pi/2}]
Can anyone suggest me something??
2 Answers
$\begingroup$
$\endgroup$
0
You just have to modify the syntax a little.
pi
is not a predefined symbol. All predefined constants start with capital letters, and for the number $\pi$ that means you should enterPi
.- The
Product
syntax is probably also not what you want: with the previous correction you would have a range specification of{i, Pi/180, Pi/2}
. Buti
here will still be incremented in integer steps, so there are only two terms in the product. - To get a product where
i
varies in discrete steps that are not integers, you have to add a fourth element to the range specification,
Example:
result = Product[Sin[i], {i, Pi/180, Pi/2, Pi/180}]
- Finally, you may not be happy with the result of this line either, because it is printed with exact numbers in the arguments of the sine functions. This is because Mathematica tries to be as general as possible, and your input had only exact numbers in it.
- Exact numbers are symbols like
Pi
but also the number180
above. To get a numerical result you have to state somewhere that you want "floating-point" output. - This can be done by giving the input as floating-point numbers as in
180.0
. - Alternatively, you can take the exact value
result
and convert it to a numerical answer usingN
,
example:
N[result]
$1.53268\times 10^{-26}$
$\begingroup$
$\endgroup$
1
In addition to Jens' answer, there is a built-in constant Degree
which is equal to Degree == Pi/180
so you could simplify your code slightly by doing something like
result = Product[Sin[i Degree], {i,90}]
-
2$\begingroup$ @experimentX and of course many other similar ways like
Times @@ Sin@Array[# Degree &, 90]
orTimes @@ Sin /@ (Range[90] Degree)
$\endgroup$ Jun 16, 2012 at 20:46