import math
def myCos(x):
x = x * math.pi / 180
s = 0.0
n = 0.0
while abs(math.cos(x) - s) >=1.0e-13:
s += ((-1)**n) * (x ** (2*n)) / (math.factorial(2 * n))
n = n + 1
print("Number of terms: ", n, "Approximation: ", s , "math.cos(x)", math.cos(x))
return s
print("Enter a degree: ")
x = float(input())
print("cos(",x,")-",myCos(x))
===============================
See Image for Indentation
Thanks, PLEASE UPVOTE
In Python, Using this formula: Using this setup: Gets this output: 1) Write a function called...
1) Write and test a well-commented Python function, called “myexp” that approximates the value for the function ?(?) = ? ? . This function can be approximated by a Taylor series ? ? ≈ ∑ ? ? ?! ∞ ?=0 , and recall that the factorial function is given by the recursive relationship ?! = ? (? − 1)!, ?ℎ??? ? ∈ ??? ≥ 0, ??? 0! = 1 1. You will need to write your own factorial function, and...
Please help, using Python Write a Python function sum_of_4th_powers, which accepts one argument. You can assume that the function is only called with an integer n as argument, i.e., no need to worry about invalid inputs. If the argument n can be written as a sum n=a4+b4+c4 with all of a,b,c being non-zero, your function should return such a decomposition. Otherwise your function must return False. For example: sum_of_4th_powers(5) must return False, sum_of_4th_powers(18) could return (1,1,2). *Please go step by...
USE PYTHON PLEASE Write a function called is prime which takes a single integer argument and returns a single Boolean value representing whether the given argument is prime (True) or not (False). After writing the function, test it by using a loop to print out all the prime numbers from 1-100. To check your results, the prime numbers from 1-100 are: 2, 3, 5, 7, 11. 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67,...
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...
Python 3 please and thank you Task 3: Create a Function 7 Create the function TotalRewardPoints which accepts the dictionary that you created in Task 1 and a list of ticket purchases and displays the information as shown below. Ticket Purchase List is formatted as [Number of Tickets, Type of Ticket....] The total reward points a user gets is calculated by using the following formula: Reward Points = Number of Ticket Bought x Reward Points for that Ticket Type Your...
Language is Python 3, please include comments Question 1 Write function collatz, that takes a positive integer x as input and prints the Collatz sequence starting at x. A Collatz sequence is obtained by repeatedly applying this rule to the previous number x in the sequence: 3/2 if x is even 3.2 +1 if x is odd. Your function should stop when the sequence gets to number 1. Note: It is an open question whether the Collatz sequence of every...
Your task is to write the initDeck() function, which will be called at the start of the program to initialize all of the cards data structures. The data structure definitions and a basic main program will be made available for you to use to develop your code. The initDeck() function: /* Function: initDeck() * Purpose: iterate through entire deck and set to default values * Accepts: array of Cards (the deck) * Returns: void */ void initDeck(struct Card deck[]) {...
Part 1: Using Idle Write a Python Script that Does the Following 1. At the top of your program, import the math library as in from math import * to make the functions in the math module available. Create a variable and assign into it a constant positive integer number of your choice. The number should be at most 10. 1 Suppose we call this variable x for this writeup document Try something like x = 4 2. Create another...
1. When using a function in the Python standard library, do you need to import the library into your program before using the function? 2. How does the walk of a pseudorandom sequence differ from the walk of a truly random sequence? 3. Is the computer capable of producing a truly random walk in a reasonable amount of time? 4. Based on your research in the standard library documentation, what is the name of the function that can be used to generate random integer...
(Python) Write a program called sales.py that uses a list to hold the sums of the sales for each month. The list will have 12 items with index 0 corresponds with month of “Jan”, index 1 with month “Feb”, etc. o Write a function called Convert() which is passed a string which is a month name (ex. “Jan”) and returns the matching index (ex. 0). Hint – use a list of strings to hold the months in the correct order,...