Sinusoidal series¶
A sinusoidal series is defined as:
\[\begin{split}\begin{array}{l} x_0 = 1 \\ x_{i+1} = 2 \sin x_i+ 3 \cos x_i, i>=0 \end{array}\end{split}\]
This sequence begins with two positive terms and continues with negative terms. The first 10 values (rounded to 2 decimals) are: 1, 3.30, -3.28, -2.69, -3.57, -1.89, -2.83, -3.47 -2.21 -3.39.
Save both functions into file sinusoidal.py.
Write the function
sinusoidal1()that given an integer \(k\), computes the sum of the elements of the previous series to the kth term (included), that is, \(x_0 +x_1 +...+x_k\). Examples:>>> round(sinusoidal1(9), 2) -19.02 >>> round(sinusoidal1(10),2) -21.44 >>> round(sinusoidal1(100),2) -280.47 >>> round(sinusoidal1(345),2) -975.5 >>> round(sinusoidal1(1000),2) -2837.07 >>> round(sinusoidal1(2674),2) -7561.88 >>> round(sinusoidal1(1000000),2) -2830726.31
Note
You can download the file with tests
test-sinusoidal1.txtWrite the function
sinusoidal2()that given a real valuesmax, toleranceepsilon, returns the position of the term in the previous series that is equal to the givenvaluewith toleranceepsilon. To determine the equality between two real numbers you must check if the absolute value of the difference between them is less than epsilon. Examples:>>> sinusoidal2(-3.5, 0.01) 66 >>> sinusoidal2(-3.5, 0.001) 118 >>> sinusoidal2(-2.9, 0.001) 1767 >>> sinusoidal2(-1.99, 0.01) 23
Note
You can download the file with tests
test-sinusoidal2.txt
Solution
A solution of these functions is provided in file sinusoidal.py