Question

Write a program that takes the value of an angle x in degrees, such that 0 s x <90, and calculates approximate value of sine

Write in Python 3

0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE

import math

def mysin(x):

sum = 0

term = 1

i = 0

while(term > 10**(-6)):

term = x**(2*i+1)/math.factorial(2*i+1)

if i % 2 == 1:

sum -= term

else:

sum += term

i += 1

return sum

print(mysin(2))

1 import math 3 def mysin(x): 4 sum 0 term1 while(term > 10*-6)): term- x** (2*1+1) /math. factoria ï (2*1+1) 10 sum- term 12

Add a comment
Know the answer?
Add Answer to:
Write in Python 3 Write a program that takes the value of an angle x in...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a computer program that takes as input a floating point number x in the interval...

    Write a computer program that takes as input a floating point number x in the interval [−π, π], and an integer n in the range 1, 2, ..., 10, and calculates sin(x) using the Taylor series definition within an accuracy of 10−n . Indicate your programming language of choice, and include a screen shot of your test cases.

  • Write a program that inputs from the user an angle (measured in degrees) then computes and...

    Write a program that inputs from the user an angle (measured in degrees) then computes and prints: (the trigonometric sine of the angle in radians) squared + (the trigonometric cosine of the angle in radians) squared. Test your program on different degrees; if your program is working correctly, the result should be 1 each time (pythagorean trigonometric identity). IN JAVA THANK YOU

  • a.) Write a C++ program that calculates the value of the series sin x and cos...

    a.) Write a C++ program that calculates the value of the series sin x and cos x, sin 2x or cos 2x where the user enters the value of x (in degrees) and n the number of terms in the series. For example, if n= 5, the program should calculate the sum of 5 terms in the series for a given values of x. The program should use switch statements to determine the choice sin x AND cos x, sin...

  • Problem1. Write a C program, called cos.approx.c, that computes the approximate value of cos(x) according to...

    Problem1. Write a C program, called cos.approx.c, that computes the approximate value of cos(x) according to its Tavlor series expansion: (-1)"r2n (2n)! x2 x4x6x8x10 cos(x)-Σ 1 This series produces the exact value of cos(x) for any real number x, but contains an infinite number of terms. Obviously, a computer program can compute only a finite number of terms. Thus, you will have to truncate the infinite series in (1). Your program should be able to do so in two different...

  • The cosine function can be evaluated by the following infinite series as (where the angle x...

    The cosine function can be evaluated by the following infinite series as (where the angle x is given in radians) cos x =1--+ + 2! 4! 6! Create a second function M-file mycos that takes the angle x (in radians), and returns cos(x) with an absolute iterative error less than 1.0e-18. Test your function to find cosine of ?/2 and 2? Display the Expansion order, and the actual error (absolute error, not the relative one) and iterative error using fprintf...

  • Programming Assignment 3 CSCI 251, Fall 2015 Infinite Series Trigonometric and math functions are...

    Programming Assignment 3 CSCI 251, Fall 2015 Infinite Series Trigonometric and math functions are usually calculated on computers using truncated Taylor series (an infinite series). An infinite series is an infinite set of terms whose sum is a particular function or expression. For example, the infinite series used to evaluate the natural log of a number is (x - 1)2 (x-1)3 (x-1)* (x-1)5 2 4 where x E (0, 2], or 0

  • Write a c++ program to calculate the approximate value of pi using this series. The program...

    Write a c++ program to calculate the approximate value of pi using this series. The program takes an input n that determines the number of values we are going to use in this series. Then output the approximation of the value of pi. The more values in the series, the more accurate the data. Note 5 terms isn’t nearly enough. You will try it with numbers read in from a file. to see the accuracy increase. Use a for loop...

  • This is the given code: /** * This program uses a Taylor Series to compute a...

    This is the given code: /** * This program uses a Taylor Series to compute a value * of sine. * */ #include<stdlib.h> #include<stdio.h> #include<math.h> /** * A function to compute the factorial function, n!. */ long factorial(int n) { long result = 1, i; for(i=2; i<=n; i++) { result *= i; } return result; } int main(int argc, char **argv) { if(argc != 3) { fprintf(stderr, "Usage: %s x n ", argv[0]); exit(1); } double x = atof(argv[1]); int...

  • Use in MATLab (b) Write a computer program to calculate ex as an approximate series summation, to an accuracy of 101...

    Use in MATLab (b) Write a computer program to calculate ex as an approximate series summation, to an accuracy of 1010. The value of x should be supplied to the program with the "input" command. Do not run the program. (b) Write a computer program to calculate ex as an approximate series summation, to an accuracy of 1010. The value of x should be supplied to the program with the "input" command. Do not run the program.

  • Convince yourself that the Maclaurin Series for cos(x) is: A. Write a function script called cos...

    Convince yourself that the Maclaurin Series for cos(x) is: A. Write a function script called cos_series that takes that takes as its inputs, x and N and has output given by the sum in the N-term Maclaurin Series approximation for Cos(x). Hint: try a “for loop” and set “format long” in your code. You may use the MATLAB built-in function factorial() B. Check your code by finding the 2-terms, 3-terms, 4-terms, 5-terms and 6-terms Maclaurin Series approximations every 30 degrees...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT