Learning Machines

Taught by Patrick Hebron at ITP, Fall 2015


Numerical Differentiation:


import numpy as np
import matplotlib.pyplot as plt

def func(x):
    return np.sin(x)

def dfunc(x):
    return np.cos(x)

xData = np.arange( -10.0, 10.0, 0.1 )
yData = func( xData ) 
yDeriv = dfunc( xData ) 
yDerivApprox = np.diff( yData ) / np.diff( xData )

plt.axis( [ -10.0, 10.0, -1.1, 1.1 ] )
plt.plot( xData, yData, 'r', xData, yDeriv, 'g', xData[0:len(xData)-1], yDerivApprox, 'b--' )
plt.show()

plot_numerical_diff