Mathematica 加快计算速度与作图Clear["Global`*"];lamda = 0.6; k = 2.*Pi/lamda;R = 1.;(*Radius of the diffraction hole*)z0 = 0.9;(*Distance between the diffraction screen and the reception \screen*)ra = 5.;(*Radius of the diffration result*)dl

来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/26 03:04:30
Mathematica加快计算速度与作图Clear["Global`*"];lamda=0.6;k=2.*Pi/lamda;R=1.;(*Radiusofthediffractionhole*)z0=

Mathematica 加快计算速度与作图Clear["Global`*"];lamda = 0.6; k = 2.*Pi/lamda;R = 1.;(*Radius of the diffraction hole*)z0 = 0.9;(*Distance between the diffraction screen and the reception \screen*)ra = 5.;(*Radius of the diffration result*)dl
Mathematica 加快计算速度与作图
Clear["Global`*"];
lamda = 0.6; k = 2.*Pi/lamda;
R = 1.;(*Radius of the diffraction hole*)
z0 = 0.9;(*Distance between the diffraction screen and the reception \
screen*)
ra = 5.;(*Radius of the diffration result*)
dl = 0.1;
intensity = {};
r1 = {\[Rho]1*Cos[\[Theta]1],\[Rho]1*Sin[\[Theta]1],z0};(*Coordinates describing the recption Screen*)
r0 = {x,y,0};(*Coordinates describing the screen where diffraction hole lies*)
\
area = UnitStep[R^2 - x^2 - y^2];
integrand = area*Exp[-I*k*(r0.r1)];
u[\[Rho]1_,\[Theta]1_] :=
NIntegrate[integrand,{x,-R,R},{y,-R,R}];
Do[
Do[AppendTo[
intensity,{\[Rho]1,\[Theta]1,Norm[u[\[Rho]1,\[Theta]1]]^2/Norm[r1[\[Rho]1,\[Theta]1,z0]]}],{\[Rho]1,0.,ra,l}]
,{\[Theta]1,0.,2*Pi,2*Pi*dl}];
ListDensityPlot[intensity,Mesh -> False]
这是一个模拟衍射图像的程序.看看怎么加快一下运行速度,跑了半个小时还没结果.而且,我用希腊字母rou和theta(极坐标)表示投影屏上的点的位置,所以希望画出来的衍射图像能呈圆形而不是方形,但第一次跑出来的结果是方形的图像.
程序的大致意思就是按照老师给出的一个电(磁)振幅积分公式,然后用NIntegrate做积分。取函数u的平方作为光强,画图。
附注:在Append命令中,把r1[/Rho,/Theta,zo]这个函数形式去掉,可以出一些结果,但还是很慢

Mathematica 加快计算速度与作图Clear["Global`*"];lamda = 0.6; k = 2.*Pi/lamda;R = 1.;(*Radius of the diffraction hole*)z0 = 0.9;(*Distance between the diffraction screen and the reception \screen*)ra = 5.;(*Radius of the diffration result*)dl
l的定义到哪里去了?