Question
1.) The following is the expansion of sin(x) in an infinite series: sin(x) = x x^3/3! + x^5/5! x^7/7! + .... Write a program that
1.) The following is the expansion of sin(x) in an infinite series:
sin(x) = x x^3/3! + x^5/5! x^7/7! + ....
Write a program that accepts an angle from the user and then computes its sine using the above expansion, up to 100 terms. Then compare the result that you get with the function Math.sin(x). You can display the absolute error, i.e., the absolute value of the difference of Math.sin(x) and the computed result.
2.) The function log(x) can be expanded in the following infinite series:
log(x) = (x 1) (1/2)(x 1)^2 + (1/3)(x 1)^3 - (1/4)(x 1)^4 + ...... (for 0 < x <= 2).
Compute the sum of the infinite series up to 100 terms for an input x provided by the user. The input should fall in the range specified above, otherwise the program should display Invalid input. For a valid input, compute the difference of the result from what you compute with Math.log(x).
3.) The sum of the infinite series:
f(r) = 1 + r + r2 + r3 + ......
is equal to 1/(I r), if |r| < 1.
Calculate the sum of the infinite series up to 100 and 200 terms and verify that the result is more accurate as we take more terms in the infinite series. For example, if r = 0.5, then the sum of the infinite series is 2. Check the value of f(r) when you take 100 terms and 200 terms in the expansion.
4.) Write a program that simulates the rolling of a pair of dice. You can simulate rolling one die by randomly choosing an integer from 1 to 6. The number you pick represents the number on the die after you roll it. Do this twice and add the results to get the value of the total roll. The program should output the number on each die as well as the total roll. A sample output should look like this, for example:
The number on the first die = 2
The number on the second die = 6
Total roll = 8
Hint: Use Math.random() to generate one roll of a die.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started