Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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: image text in transcribed

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

image text in transcribed

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)

image text in transcribed

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

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

Making Databases Work The Pragmatic Wisdom Of Michael Stonebraker

Authors: Michael L. Brodie

1st Edition

1947487167, 978-1947487161

More Books

Students also viewed these Databases questions

Question

=+j Describe an effective crisis management program.

Answered: 1 week ago