By setting L = 3*pi and making some other small changes we obtain:
Physically we could interpret the result as follows:
the heat flows spontaneously towards areas where the temperature is lower, therefore the temperature should go up in the middle of the rod (since it has been cooled down and has a lower temperature compared its surroundings) and go down in the sides. Assuming that the left and right boundaries of the rod are kept at constant temperature through an ideal thermostat.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from numpy import pi | |
import matplotlib.pyplot as plt | |
import matplotlib.animation as animation | |
fig = plt.figure() | |
fig.set_dpi(100) | |
ax1 = fig.add_subplot(1,1,1) | |
#Diffusion constant | |
k = 2 | |
#Scaling factor | |
scale = 5 | |
#Length of the rod (0,L) on the x axis | |
L = 3*pi | |
#Initial contitions | |
x0 = np.linspace(0,L,10000) | |
t0 = 0 | |
temp0 = 5 #Temperature of the thermostat | |
#Increment | |
dt = 0.02 | |
#Heat equation | |
def u(x,t): | |
return temp0 + scale*np.exp(-k*t)*np.sin(x) | |
#Gradient of the Heat Equation | |
def grad_u(x,t): | |
#df/dx #df/dt | |
return scale*np.array([np.exp(-k*t)*np.cos(x),-k*np.exp(-k*t)*np.sin(x)]) | |
a = [] | |
for i in range(500): | |
value = u(x0,t0) + grad_u(x0,t0)[1]*dt | |
t0 = t0 + dt | |
a.append(value) | |
k = 0 | |
def animate(i): | |
global k | |
x = a[k] | |
k += 1 | |
ax1.clear() | |
plt.plot(x0,x,color='red',label='Temperature while cooling after heating') | |
plt.plot(x0,temp0*np.ones(x0.shape),color='green',label='Thermostat temperature of the rod') | |
plt.grid(True) | |
plt.legend() | |
plt.ylim([-4,2.5*scale]) | |
plt.xlim([-0.2,L+0.2]) | |
anim = animation.FuncAnimation(fig,animate,frames=360,interval=20) | |
plt.show() |
Why not checking if this solution is mathematically and physically consistent?
Cloud Computing has been the stage for emerging technologies and an increase in career opportunities for both fresher and professional.
ReplyDeleteCloud Computing Course Fees in Bangalore
ReplyDeleteVery informative blog! There is so much information here that can help thank you for sharing.
Data Science Syllabus
Really impressed! Information shared was very helpful Your website is very valuable. Thanks for sharing..
ReplyDeleteBusiness Analytics Course in Bangalore
I got to this amazing site not long ago. I actually captured with the piece of resources you have got here. Thanks for making such wonderful blog page.
ReplyDeleteBusiness Analytics Course in Indore
amazing write , keep posting and if you are intresting in big data coder and code developer then checkout java classes in satara
ReplyDelete