Ask Your Question

justinus's profile - activity

2021-11-13 15:04:55 +0200 received badge  Famous Question (source)
2018-09-17 21:04:59 +0200 received badge  Notable Question (source)
2017-12-04 18:01:10 +0200 received badge  Popular Question (source)
2016-11-02 20:45:31 +0200 received badge  Nice Question (source)
2016-11-02 06:28:40 +0200 received badge  Organizer (source)
2016-11-02 06:24:31 +0200 commented question Plot 3D Surface Heat Equation

The question has been updated. Sorry for my bad. Hope you can help :)

2016-11-02 06:23:53 +0200 received badge  Editor (source)
2016-11-01 11:39:42 +0200 received badge  Student (source)
2016-11-01 03:06:26 +0200 asked a question 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: Heat Equation

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