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))

Write in Python 3 Write a program that takes the value of an angle x in...
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 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 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 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 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 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 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...
Program 2 #include <iostream> #include <cmath> using namespace std; int main() { const double PI = 3.141592653; int degrees; double radians; cout << "Enter a value for the degree of an angle\n"; cin >> degrees; // translate the formula for converting degrees to radians into C++: // // degrees x PI // ------------ = radians // 180 radians = _____________________________________; // Refer to p. 127 for help below....
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 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.