Plot 3D Surface Heat Equation
I am trying to plot a 3D surface using SageMath Cloud but I am having some trouble with my plot result. Anyways the program I have written is to plot the Heat Equation solution that I got from analytical method.
The case is:
Here is my code:
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
from sympy import *
from math import *
L = 10
x = np.linspace(0, 10, 5)
t = np.linspace(0, 20, 5)
n = symbols('n', integer=True)
X, T = np.meshgrid(x, t)
Z = []
y = symbols('y')
for ix, ea in enumerate(x):
ans = 0.
for n in range(L + 1): # do summation with simple for-loop
f_pi = 0.
if x[ix] >= 6 and x[ix] <= 8:
f_pi = 50
ans = ans + ((2 / 10.) * integrate(f_pi * sin(radians((2. * n + 1.) * pi * x[ix] / 20.)), (y, 0, 10)) * e**(-1 * (2. * n + 1. / 20.)**2*pi**2*t[ix]) * sin(radians((2. * n + 1.) * pi * x[ix] / 20)))
Z.append(ans)
Z = np.array(Z, dtype=float)
fig = plt.figure()
ax = fig.gca(projection = '3d')
plt.xticks(x, x)
plt.yticks(t, t)
surf = ax.plot_surface(X, T, Z,
rstride = 3,
cstride = 3,
cmap = cm.coolwarm,
linewidth = 0.5,
antialiased = True)
fig.colorbar(surf,
shrink=0.8,
aspect=16,
orientation = 'vertical')
ax.view_init(elev=60, azim=60)
ax.dist=8
plt.show()
The plot I got: https://s11.postimg.org/6lk5xrj2r/fig...
It should be: https://s22.postimg.org/4kzl6ff1d/ima... (expected result, using Matlab)
What's wrong with my plotting?
Thanks in advance
Could you re write the code please.
The question has been updated. Sorry for my bad. Hope you can help :)