Question
In Python,
1) Write a function called myCos(x) that accepts an input number x measured in degrees la. Therefore, your function needs to first convert a degree to a radian. For example, if x is 67 degrees, x can be converted to a radian as follows: x = 67 # x is 67 degrees. x-x/ 180 * math.pi # x is now measured in radian. You can stop your loop after your approximation and math.cos(x) differ less than 1.0e-13. (50 points).
Using this formula:
media%2Fe69%2Fe69713de-849f-4ae4-b8fb-f3
Using this setup:

media%2Fb13%2Fb13744b5-922c-4955-88de-ed
Gets this output:

media%2Fe3c%2Fe3ca9e1a-6264-4e01-9e9a-ae
0 0
Add a comment Improve this question Transcribed image text
Answer #1

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

Add a comment
Know the answer?
Add Answer to:
In Python, Using this formula: Using this setup: Gets this output: 1) Write a function called...
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
  • Please help, using Python Write a Python function sum_of_4th_powers, which accepts one argument. You can assume...

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

  • Language is Python 3, please include comments Question 1 Write function collatz, that takes a positive...

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

  • 1) Write and test a well-commented Python function, called “myexp” that approximates the value for the...

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

  • 1.  When using a function in the Python standard library, do you need to import the library...

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

  • can someone write me a wing101 python code for this please Question: For a projectile launched with a velocity vIm/s) at an angle to the horizontal 6 Iradl, the horizontal distance travelled (al...

    can someone write me a wing101 python code for this please Question: For a projectile launched with a velocity vIm/s) at an angle to the horizontal 6 Iradl, the horizontal distance travelled (also called the range) is given by where the altitude of the landing position is Δh higher than that of the launch position and g is the gravitational acceleration (use 9.81 m/s^2). Note: θ in theformula is in radians write a Python function that accepts ν, θ and...

  • PYTHON:please display code in python Part 1: Determining the Values for a Sine Function Write a...

    PYTHON:please display code in python Part 1: Determining the Values for a Sine Function Write a Python program that displays and describes the equation for plotting the sine function, then prompts the user for the values A, B, C and D to be used in the calculation. Your program should then compute and display the values for Amplitude, Range, Frequency, Phase and Offset. Example input/output for part 1: Part 2: Displaying a Vertical Plot Header A vertical plot of the...

  • With using Python . Write a function that: 1. Takes two arguments and returns the product...

    With using Python . Write a function that: 1. Takes two arguments and returns the product of the arguments. The return value should be of type integer. 2. Takes two arguments and returns the quotient of the arguments. The return value should be of type float. 3. Takes one argument and squares the argument. It then uses the two values and returns the product of the two arguments.(Reuse function in 1.) 4. Takes one argument and prints the argument. Use...

  • Your task is to write the initDeck() function, which will be called at the start of...

    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[]) {...

  • Using PyCharm, under lab8, under Directory exercise, create a Python file called more_loops.py. Write a function,...

    Using PyCharm, under lab8, under Directory exercise, create a Python file called more_loops.py. Write a function, nbrs_greater that accepts 2 integer lists as a parameters, and returns a list of integers that indicates how many integers in the second list are greater than each integer in the first list. For example: nbrs_greater([3, 4, 1, 2, 7], [10, 1, 4, 2, 5, 3]) returns [3, 2, 5, 4, 1] because: Number of numbers in Element of first list Numbers greater from...

  • (Python) Write a program called sales.py that uses a list to hold the sums of the...

    (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,...

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