If you've taken trigonometry, you probably know about taking the sine of a number. Like $\sin 45^\circ=0.701$.
You probably also learned that $\sin$ (and $\cos$) can be found using the unit circle.
Well, did you know that the sin of any number can also be found by adding together a bunch
of numbers in a particular way? That's right, the sin of a number can come from a big addition problem. The sum
(or big addition problem) to find $\sin$ looks like this:
Using a for-loop to handle the sum, test the results of this sum for $\sin(x)$ vs. the
built in math.sin(x) function. Feel free to take many more terms that just 4 in the sum.
We've provided the factorial function for you already.
Now you try. Fix up the contents of the for-loop to find the sin of x using the big sum.
Type your code here:
See your results here:
You'll have to work carefully here. Here are some notes:
In the running sum, some terms are added,
others are subtracted. We're proposing to use the variable c to keep track
of when to add and when to subtract a term (even terms subtracted, odd terms added).
We're using variable x as the
number "to take the sin of."
We're using the for-loop in i to run from 1,2,3.. up to
the number of terms we want in our sum. Inside of the for-loop, we have n=2*i-1 which
will cause the variable n match the power of x and needed factorial in any term in the sum.