So I wont pretend it's not HW..it's a HW question.. it says:
Write a program that computes the approximate sine of an angle (θ) by using the following infinite series:
Approximate sine of θ = θ – (θ^3 /3!) + (θ^5 /5!) - (θ^7 /7!) + (θ^9 /9!) … (other terms follow)
Where θ is in radians and the factorial computations are given as
3! = 3*2*1
5! = 5*4*3*2*1
7! = 7*6*5*4*3*2*1
9! = 9*8*7*6*5*4*3*2*1
…
N! = N*(N-1)*(N-2)…..*1
Of course, you can’t compute an infinite sum. Just keep adding values until an individual summation term is less that a certain threshold.
For example, the equation below:
Approximate sine of θ = θ – (θ^3 /3!) + (θ^5 /5!) - (θ^7 /7!) + (θ^9 /9!)
computes the sin(θ) to 5 terms.
Also, use the C++ library function to compute the sine of theta (sin(θ)) and compute the Percent Error between the approximate value of sine computed using the approximation and the sine library function computation. The Percent Error formula is given below:
%error = ((1.0 – sin(θ))/approximate_sine_ θ)*100
Where sin(θ) is the C++ library function used for computing sine of an angle.
I did most of the question..but only 2 points are confusing me..how do i do the theta to the power 3 or 5 etc! I can't just use theta*theta... cuz then ill get no marks..so it's gotta be some kind of loop..but i have no idea how!
I also don't see how theta being in radians make any difference!
thanks a LOT!
leena=)