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:
For reference, this is Exercise 6.1 (typo on paper):
![math import numpy import matplotlib.pyplot as plt def func1(f,dx): ans = []](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f38c8b161cd_25866f38c8a77ebf.jpg)
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 =](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f38c8c0f0ed_25966f38c8b730a5.jpg)
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
Get step-by-step solutions from verified subject matter experts
