上海交通大学python期末大作业题目(姚天昉)(2)
Choose a random molecule (remember, the demon cannot be chosen here)
Generate a random number between -Dv and Dv, where Dv is the velocity corresponding to 10% of the total system energy divided by N. Thus, Dv = sqrt(2 * totalEnergy / N / 10).
Calculate the change in energy. Since we use unit mass (m = 1), the change in energy is deltaEnergy = vNew² / 2 - vOld² / 2.
If the change in energy is valid, then accept the change in velocity for that molecule. Remember that the change in energy is valid as long as the resulting demon energy is non-negative. Because not every change is legal, every iteration may not change N molecules, even though it executes N trials.
The demon and system energies must be updated to use in the next trial. However, since we must generate visuals for the next part of the project, we need to record these values in a list to keep track of the value at each iteration (not trial).
Calculate the average system energy and return it.
Experiments for the Ideal Gas Simulation
姚天昉是上海交大一位非常有名的计算机老师,期末大作业非常难,给弟弟妹妹们透露下。ps:这是大作业一,另有大作业二即将公布,敬请关注!
First, write and test the function ideal_gas. Note that in this project you will be handing in the function and the experimental work at the same time. Test the function ideal_gas with small values of N and small values of step. You won't know that you are computing the correct quantities until you generate the plots described next. Test the function with both initial system states.
Your experimental work should consider systems with N= 50 to 500, with an increment of 50. For each N, run the function ideal_gas with steps = 3000 and totalEnergy = 500. Each experiment should be done for each of the two initial system states.
The simulation can use MatPlotLib or VPython. Warning: If you use VPython, you should remove all traces of MatPlotLib from the skeleton code. The two have not been known to play well together. A starting point for the varying values of N is provided in the main of the skeleton code. This part of the project requires you to write code to draw two graphs and two histograms.
The main of the simulation uses the values returned by ideal_gas to generate the graph N_versus_Energy. The value returned by the function ideal_gas represents the average system energy of a simulation with particular value of N. You should graph the average system energy on the y-axis and N on the x-axis. In the same plot, show the total system energy in a different color (in the required experiment it is 500 for every value of N). You can generate the plot after the entire simulation or generate it incrementally after ideal_gas returns a value. Here is an example
plot. nvsenergy1.png
The ideal_gas function should generate two histograms and one graph. Whether and when these plots are generated is determined by the fifth parameter (visuals) of ideal_gas. For example, ideal_gas(N, 500, 3000, 2, N==500) will generate plots only when N=500 and start in initial state
2. Note that omitting the 5th argument will plot every time ideal_gas is called.
Histogram Final_Molecule_Velocity uses the values of the N molecule velocities after steps iterations of ideal_gas (i.e., the values just before ideal_gas returns). Plot the velocities on x-axis and their frequencies on y-axis. You should use the signed velocities and 0 is thus in the center of the x-axis. You should experiment with the most appropriate number of bins. Here is an example plot. velocitydistr1.png
姚天昉是上海交大一位非常有名的计算机老师,期末大作业非常难,给弟弟妹妹们透露下。ps:这是大作业一,另有大作业二即将公布,敬请关注!
Histogram Demon_Energy generates a histogram of the observed demon energy. The plot is generated after the steps of ideal_gas are completed. The demon energy is recorded after each simulation step (using a list or array of size step). Show the demon energies on the x-axis and their frequencies on the y-axis. Again, select an appropriate number of bins. Here is an example plot.
demonenergy1.png
Graph Demon_Energy_Time shows the steps demon energies over time. The graph has values from 1 to steps on the x-axis and the corresponding demon energies on the y-axis. Make sure to show these 3000 steps in an effective way.
If you are using VPython, you can show a histogram plot as soon you have data needed. If you are using Matplotlib, the interactive option allows showing results during the computation (See Interactive Matplotlib):
Interactive Matplotlib
Normally, matplotlib will not show plots until you call pylab.show(). However, if you call pylab.ion() before plotting, matplotlib will show the window immediately. For best results, decorate (set title, axis labels, etc) after calling pylab.plot().
Example code:
import pylab
姚天昉是上海交大一位非常有名的计算机老师,期末大作业非常难,给弟弟妹妹们透露下。ps:这是大作业一,另有大作业二即将公布,敬请关注!
xs = []
ys = []
pylab.ion()
for x in range(10):
xs.append(x)
ys.append(x ** 2)
pylab.plot(xs, ys, 'b-o')
pylab.pause(1)
pylab.title("curve of x squared")
pylab.xlabel("x")
pylab.ylabel("x ** 2")
pylab.show()
pylab.pause(10)
pylab.close()
Discussion
You need to hand in a discussion of your experimental results. The following questions should be addressed:
In graph N_versus_Energy, how close is the actual system energy to the total energy? How does it change as N changes? How do the plots differ for the two different initial system states?
Using histogram Final_Particle_Velocity, what kind of distribution do you judge the velocities to come from? How close is the molecule velocity to the initial velocity of sqr …… 此处隐藏:5452字,全部文档内容请下载后查看。喜欢就下载吧 ……
相关推荐:
- [高等教育]一年级家长课程教案
- [高等教育]封丘县人民医院深入推进纠正医药购销领
- [高等教育]2017年6月大学英语四级真题试卷及答案(
- [高等教育]2017年北京第二外国语学院文学院824中
- [高等教育]7 高中历史第7单元1861年俄国农奴制改
- [高等教育]【K12学习】4、实际测量-苏教版六年级
- [高等教育]药具培训试卷题库及部分参考答案
- [高等教育]本土电子元器件目录分销商如何赢得生意
- [高等教育]七年级岭南版美术教案
- [高等教育]书作文之书法活动通讯稿
- [高等教育]Endnote X 软件使用入门和用法总结(LS)
- [高等教育]嵌入式系统的现状及发展状况
- [高等教育]2012抗菌药物专项整治活动方案解读
- [高等教育]人教版新课本一年级数学下册期末试卷
- [高等教育]爱课程民法学观后感
- [高等教育]930机组使用说明书1
- [高等教育]煤气设备设施点检标准
- [高等教育]常见室内观叶植物图解
- [高等教育]312党员群众路线心得体会
- [高等教育]小学信息(苗版)第一册全册教案
- 在市---局2010党建大会上的讲话
- 《科哲》提纲及补充阅读材料(2010.7)
- 苏州高博软件技术职业学院论文开题报告
- 兼职导游管理的困境及对策探讨
- 基于通用设计理念的现代厨房产品语义研
- 康乐一中2010年至2011年度鼓号队、花束
- 第10章_数据收集整理与描述_期末复习课
- 2008年黑龙江林甸商贸购物中心营销策划
- 水硬度的测定实验报告
- 五分钟教你拍摄夜景光绘照
- 2014年临床妇产科三基三严试题及答案
- 0第二课 纾解压力第一站了解压力
- 解析建筑工程电气设备安装施工技术要点
- 地方性应用型本科高校“双师型”师资队
- 高考语文专题复习课件:小说阅读指导
- 装饰工程投标书2
- 大学生就业难问题探讨及对策
- English and Its History
- 青岛市城市房屋修缮工程质量监督管理办
- 初中英语形容词和副词的用法和练习题




