# Q 4B
# Question is nothing but 1-D Heat Equation with heating at middle
# Solve by using finite difference method
import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import quad
x = np.linspace(0, 1, 101)
u = np.zeros(101)
u[0] = u[100] = 0 # Boundary Conditions
u[50] = 1 # Initial Condition
for t in range(100):
for i in range(1,100):
u[i] += (u[i+1] + u[i-1] -2*u[i])/4
plt.plot(x, u, 'r-', lw=3)
plt.xlabel("Length of rod")
plt.ylabel("Temperature (in reduced units)")
plt.title("Temperature Profile of Rod")
plt.show()
Comments
Post a Comment