Question: PYTHON question: For reference, this is Exercise 6.1 (typo on paper): import math import numpy import matplotlib.pyplot as plt def func1(f,dx): ans = [] for

PYTHON question: PYTHON question: For reference, this is Exercise 6.1 (typo on paper): import

For reference, this is Exercise 6.1 (typo on paper):

math import numpy import matplotlib.pyplot as plt def func1(f,dx): ans = []

import math import numpy import matplotlib.pyplot as plt

def func1(f,dx): ans = [] for i in range(len(f)-1): ans.append((f[i+1]-f[i])/dx) return ans

f = numpy.sin(numpy.linspace(0,5,50)) calculated = func1(f,0.1) actual = numpy.cos(numpy.linspace(0,4.9,49)) diff = abs(calculated-actual) plt.plot(diff)

def func2(f,dx): return numpy.gradient(f,dx)

f = numpy.sin(numpy.linspace(0,5,50)) calculated = func2(f,0.1) actual = numpy.cos(numpy.linspace(0,5,50)) diff = abs(calculated-actual) plt.plot(diff)

for i in range(len(f)-1): ans.append((f[i+1]-f[i])/dx) return ans f = numpy.sin(numpy.linspace(0,5,50)) calculated =

Exercise 5.2 (10 points) (a) Write a function that takes a list of function values fi and the spacing dx between them, and returns a list of values for the second derivative of the function. Test your function by giving it a list of known values for "exp(x)" and making a graph for the difference between the output of your function and the expected results. (b) Instead of using the function you have defined for part (a) use 2 times the function you have defined in Exercise 6.1 for the 1st derivative. Again test your function with "exp(x)" and plot the difference between the output of your function and the expected results

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 Databases Questions!