Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from numpy import *
- import scipy as sp
- import matplotlib.pyplot as plt
- from scipy._lib.six import xrange
- def f(x, y):
- return y
- y0 = f(1, 1)
- xmin = 0.
- xmax = 10.
- npoints = 150
- dx = (xmax - xmin) / float(npoints)
- x = sp.linspace(xmin, xmax, npoints)
- forwardSol = x * 0.
- forwardSol[0] = y0
- for i in xrange(1, npoints):
- forwardSol[i] = forwardSol[i-1] + dx * f(forwardSol[i-1], forwardSol[i-1])
- sol_exact = exp(x)
- plt.figure()
- plt.plot(x, forwardSol, '--r')
- plt.plot(x, sol_exact, 'g')
- plt.ylabel("forward")
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement