通过Matlab Web Server实现的网络虚拟实验室,不必在客户端安装MATLAB软件,不管在何时何地,只要有浏览器,只要网络通畅,在浏览器中输入要访问的服务器地址,就可以在线浏览实验的全过程。科研人员不必知道太多有关MATLAB编程的知识,只需要知道要得到什么样的实验数据,选取相关实验即可。其出现极大的方便了教学和科研,对教学和科研展现了新的模式。同时从上述讨论可以看出,利用计算机对光的干涉实验进行仿真模拟,不受实验仪器和实验场所的限制,在教学中,可以通过改变实验参数获得不同的实验结果,并在显示屏上直接显示出来,对于帮助学生理解光学理论具有积极的作用。运用计算机数值计算与模拟仿真技术对各种物理现象进行模拟仿真,对大学物理教学现代化有很大的帮助。
附件一:(用MATLAB语言对杨氏双缝干涉模拟M文件)
function rs = yanshisuangfeng(h)
%得到唯一ID,用于图片名字
mlid = getfield(h, 'mlid');
%设置当前目录,以便储藏文件(图片)
cd(h.mldir);
%清理一小时前的图片.
wscleanup('yanshisuangfeng*.jpeg', 1);
%得到数据
Lambda = str2double(h.Lambda)*10^(-6);
d= str2double(h.d);
z= str2double(h.z);
Ny= str2double(h.Ny);
if(~isfinite(Lambda)|~Lambda)
error('请输入波长.');
end
if(~isfinite(d)|~d)
error('请输入双缝的间隔.');
end
if(~isfinite(z)|~z)
error('请输入屏幕到双狭缝平面的距离.');
end
if(~isfinite(Ny)|Ny<5|Ny>1000)
error('请输入正确条纹清晰度(50-1000).');
end
%开始创画板
Fig = figure('visible','off');
xMax=5*Lambda*z/d;
ys=xMax;
xs=linspace(-xMax,xMax,Ny);
for i=1:Ny
L1=sqrt((xs(i)-d/2).^2+z.^2);
L2=sqrt((xs(i)+d/2).^2+z.^2);
Phi=2*pi*(L2-L1)/Lambda;%相位差
I(i)=sum(4*cos(Phi/2).^2);%光强
end
NCLevels=255;
Ir=(I/4.0)*NCLevels;
subplot(2,1,1);
colormap(gray(NCLevels));
image(xs,ys,Ir);
xlabel('双缝干涉条纹');
title('杨氏双缝干涉计算机模拟');
subplot(2,1,2);
plot(xs,I);
grid on
xlabel('双缝干涉相对光强的分布'); %x标签
ylabel('相对强度\itI/I\rm_1');%y标签
%读写图片到文件.
drawnow;
s.GraphFileName = sprintf('yanshisuangfeng%s.jpeg', mlid);
wsprintjpeg(Fig, s.GraphFileName);
s.GraphFileName = sprintf('/icons/yanshisuangfeng%s.jpeg', mlid);
close all;
%写入到网页中.
templatefile = which('showpicture.html');
rs = htmlrep(s, templatefile);
附件二:(用MATLAB语言对牛顿环模拟M文件)
function rs = niutunhuan(h)
%得到唯一ID,用于图片名字
mlid = getfield(h, 'mlid');
%设置当前目录,以便储藏文件(图片)
cd(h.mldir);
%清理一小时前的图片.
wscleanup('niutunhuan*.jpeg', 1);
%得到数据
Lambda = str2double(h.Lambda)*10^(-6);%Lamada表示波长
R= str2double(h.R)*10^3;%R为透镜的曲率半径,
range= str2double(h.range);
n= str2double(h.n);
if(~isfinite(Lambda)|~Lambda)
error('请输入波长.');
end
if(~isfinite(R)|~R)
error('请输入透镜的曲率半径.');
end
if(~isfinite(range)|~range)
error('请输入取值坐标.');
end
if(~isfinite(n)|n<5|n>1000)
error('请输入正确条纹清晰度(50-1000).');
end
%开始创画板
Fig = figure('visible','off');
x=linspace(-range,range,n);
y=x;
[X,Y]=meshgrid(x,y);
I=4*cos(pi/Lambda*((X.^2+Y.^2)/R+Lambda/2)).^2;%等厚干涉的光强
NCLevels=255;
Ir=(I/4.0)*NCLevels;
image(x,y,Ir);
colormap(gray(NCLevels));
title('牛顿环(等厚干涉)计算机模拟');
%读写图片到文件.
drawnow;
s.GraphFileName = sprintf('niutunhuan%s.jpeg', mlid);
wsprintjpeg(Fig, s.GraphFileName);
s.GraphFileName = sprintf('/icons/niutunhuan%s.jpeg', mlid);
close all;
%写入到网页中.
templatefile = which('showpicture.html');
rs = htmlrep(s, templatefile);
附件三:(用MATLAB语言对迈克尔逊干涉仪模拟M文件)
function rs = maikexunganshe(h)
%等倾干涉的光强分布为:
%得到唯一ID,用于图片名字
mlid = getfield(h, 'mlid');
%设置当前目录,以便储藏文件(图片)
cd(h.mldir);
%清理一小时前的图片.
wscleanup('maikexunganshe*.jpeg', 1);
%得到数据
Lambda = str2double(h.Lambda)*10^(-6);%Lamada表示波长
f= str2double(h.f);%f屏幕前透镜的焦距
d= str2double(h.d);%d由分光板分束,经相互垂直的两平面反射镜反射的二相干光束的光程差的一半
range= str2double(h.range);
n= str2double(h.n);
if(~isfinite(Lambda)|~Lambda)
error('请输入波长.');
end
if(~isfinite(d)|~d)
error('请输入光程差的一半.');
end
if(~isfinite(f)|~f)
error('请输入屏幕前透镜的焦距.');
end
if(~isfinite(range)|~range)
error('请输入请输入取值坐标.');
end
if(~isfinite(n)|n<5|n>1000)
error('请输入正确条纹清晰度(50-1000).');
end
%开始创画板
Fig = figure('visible','off');
x=linspace(-range,range,n);
y=x;
[X,Y]=meshgrid(x,y);
r=sqrt(X.^2+Y.^2);
I=4*cos(pi*2*d*cos(atan(r/f)/Lambda)).^2;
NClevels=255;
Ir=(I/4.0)*NClevels;
image(x,y,Ir);
colormap(gray(NClevels));
title('克尔逊干涉仪(等倾干涉)计算机模拟');
%读写图片 到文件.
drawnow;
s.GraphFileName = sprintf('maikexunganshe%s.jpeg', mlid);
wsprintjpeg(Fig, s.GraphFileName);
s.GraphFileName = sprintf('/icons/maikexunganshe%s.jpeg', mlid);
close all;
%写入到网页中.
templatefile = which('showpicture.html');
rs = htmlrep(s, templatefile);