Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I'm having difficulties creating a couple of python functions for scientific computing if anyone could help me out. I will post the code with descriptions

I'm having difficulties creating a couple of python functions for scientific computing if anyone could help me out. I will post the code with descriptions of what the functions should do below.

import numpy as np import matplotlib.pyplot as plt

def mysin(x, tol=1e-8): """ compute sin(x) by summing taylor expansion at 0,

sin(x) = x - x^3/3! + x^5/5! +.... + (-1)^k*x^(2k+1)/(2k+1)! + ...

up to accuracy of tol, i.e. break out of loop when the |new term to be added| <= tol """ # #note, for numerical efficiency, the new term to be added at the k-th step #need not be computed as (-1)**k* x**(2*k+1)/(2*k+1)! #instead, it can be computed by a simple update of term (-1)**(k-1)* x**(2*(k-1)+1)/(2*(k-1)+1)! #already computed at the previous step: you only need to multiply it by -x**2/2k/(2k+1) #(try to see if you can understand why. if you cannot do this, you may add term-by-term using #the straightforward (-1)^k*x^(2k+1)/(2k+1)!, which is less efficient) #

def mycos(x, tol=1e-8): """ compute cos(x) by summing taylor expansion at 0,

cos(x) = 1 - x^2/2! + x^4/4! +.... + (-1)^k*x^(2k)/(2k)! + ...

up to accuracy of tol, i.e. break out of loop when the |new term to be added| <= tol """ #if you can, apply the more efficient 'updating' method instead of direct sum term-by-term

def mysin_mod(x, tol=1e-8): """ compute sin(x) by summing taylor expansion at x0=j*pi, (for some integer j such that j*pi is closest to x), if j is even, then sin(x) = (x-x0) - (x-x0)^3/3! + (x-x0)^5/5! +.... + (-1)^k*(x-x0)^(2k+1)/(2k+1)! + ... if n is odd, multiply the above by -1. """ #if you can, apply the more efficient 'updating' method instead of direct sum term-by-term

def mycos_mod(x, tol=1e-8): """ compute cos(x) by summing taylor expansion at x0=j*pi, (for some integer j such that j*pi is closest to x), if j is even, then cos(x) = 1 + (x-x0)^4/4! + (x-x0)^8/8! + (x-x0)^12/12! + (x-x0)^16/16! + ... - (x-x0)^2/2! + (x-x0)^6/6! + (x-x0)^10/10! + ... ) if j is odd, multiply the above by -1. """ #if you can, apply the more efficient 'updating' method instead of direct sum term-by-term

If anyone could help me with at least a couple of these thatd be great. Will thumbs up.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Pro Database Migration To Azure Data Modernization For The Enterprise

Authors: Kevin Kline, Denis McDowell, Dustin Dorsey, Matt Gordon

1st Edition

1484282299, 978-1484282298

More Books

Students also viewed these Databases questions