Question: In this problem we will implement an approximation to the exp(x) function, which is represented by the following infinite series, 2 exp(x) n! n=0 Your

In this problem we will implement an

In this problem we will implement an

In this problem we will implement an

In this problem we will implement an approximation to the exp(x) function, which is represented by the following infinite series, 2 exp(x) n! n=0 Your approximation will be a truncated finite series with N + 1 terms, N ch exp(x,N) = n! n=0 Part 1 For the first part of this problem, you are given a random real number x and will investigate how well a finite series expansion for exp(x) approximates the infinite series. Compute exp(x) using a finite series approximation with N = [0, 9] C N (i.e. N is an integer). Assign a numpy array named exp_approx with the 10 floating point values from your approximation. exp_approx should be of shape (10,) and should be ordered with increasing N (i.e. the first entry of exp_approx should correspond to exp(x, N) when N = 0 and the last entry when N = 9). Plot exp(x, N) vs. N, with your series approximation exp(x, N) on the y-axis and n on the x-axis. You should have 10 values. Make sure to provide appropriate formatting (e.g. labels, title, markers, etc...) Part 2 For the second part of this problem, you will be asked to find an integer value for Ne (0, 9] such that the finite series is guaranteed to have a relative error less than some desired amount. The relative error is with respect to the true exp(x) value that would result from an infinite series. N should be the smallest one that satisfies the desired relative error constraint. First, put the absolute and relative errors for each value of N in abs_error and rel_error. Given a desired relative error, desired_rel_error, compute the smallest N that will guarantee the relative error is below desired_rel_error. Assign this N to an integer variable called N. Note: desired_rel_error is given as a % error, not a fraction. Input/Output The setup code gives the following variables: Name IX Type Description float random real number where the function will be evaluated float the error limit in computing the value of N desired_rel_error Your code snippet should define the following variables: Name Type exp_approx 1-D Numpy Array abs_error 1-D Numpy Array rel_error 1-D Numpy Array IN int Description array giving your estimates for exp(x) array giving the absolute error for using the taylor approximation array giving the relative error for using the taylor approximation the smallest N satisfies the desired relative error constraint Your code snippet must also generate the following plot: Plot of exp(x) vs. N. (Provide appropriate axes labels and a title.) user_code.py 1 import numpy as np 2 import matplotlib.pyplot as plt 3 4 exp_approx = np.zeros(10) 5 abs_error = np.zeros(10) 6 rel_error np.zeros(10) 7 N = 0

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related General Management Questions!