Advertisement
Guest User

Plot 3D Surface Heat Equation

a guest
Nov 1st, 2016
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.11 KB | None | 0 0
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. from mpl_toolkits.mplot3d import Axes3D
  4. from matplotlib import cm
  5. from sympy import *
  6. from math import *
  7.  
  8. x = np.linspace(int(-8), int(8), 100)
  9. t = np.linspace(int(-8), int(8), 100)
  10.  
  11. n = symbols('n', integer=True)
  12. X, T = np.meshgrid(x, t)
  13.  
  14. Z = []
  15. y = symbols('y')
  16. for ix, ea in enumerate(x):
  17.     ans = 0.
  18.     for n in range(11): # do summation with simple for-loop
  19.         ans = ans + (2 / 10.) * integrate(50. * sin(radians((2. * n + 1.) * pi * x[ix] / 20.)), (y, 0, 10)) * e**(2. * n + 1. / 20.)**2*pi**2*x[ix] * sin(radians((2. * n + 1.) * pi * x[ix] / 20))
  20.     Z.append(ans)
  21. Z = np.array(Z, dtype=float)
  22.  
  23. fig = plt.figure()
  24. ax = fig.gca(projection = '3d')
  25.  
  26. surf = ax.plot_surface(X, T, Z,
  27.                       rstride = 3,
  28.                       cstride = 3,
  29.                       cmap = cm.coolwarm,
  30.                       linewidth = 0.5,
  31.                       antialiased = True)
  32.  
  33. fig.colorbar(surf,
  34.              shrink=0.8,
  35.              aspect=16,
  36.              orientation = 'vertical')
  37.  
  38. ax.view_init(elev=60, azim=50)
  39. ax.dist=8
  40. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement