Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Recall that there are several layers during the implementation and execution of numerical methods where error can accumulate. One source of error occurs when we

Recall that there are several layers during the implementation and execution of numerical methods where error can accumulate. One source of error occurs when we use an approximation for mathematical formulations that would otherwise be too costly in terms of computational run-time or memory resources for our numerical method. One routine example is the approximation of infinite series by a finite series that mostly captures the important behavior of the infinite series.

image text in transcribed

image text in transcribedimage text in transcribed

In this problem we will implement an approximation to the exp(x) function, which is represented by the following infinite series, exp(x)- n-0 Your approximation will be a truncated finite series with N + 1 terms, rn exp(2, N) = TL 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(z) using a finite series approximation with N E [0.9] C N (ie. 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(z, M when = 0 and the last entry when = 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 N E [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: Type Description float random real number where the function will be evaluated float the error limit in computing the value of N Name desired ret error Your code snippet should define the following variables: Name Type exp_approx-D Numpy Array array giving your estimates for exp(x) abs_error 1-D Numpy Array array giving the absolute error for using the taylor approximation rel error 1-D Numpy Array array giving the relative error for using the taylor approximation Description int 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 exp-approx = np.zeros(10) 5 abs_error -np.zeros(10) 6 rel_error np.zeros

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions