![]() |
||||||
|
| Script S1_2_20A.m | |||
|
|||
|
%==============================================
%Cavity 3A %Function fcav is required %============================================== % %The radii of the mirrors and the distance between them in mm RB=-10; RA=10; dist=5:1:30; num=length(dist); % %we assume tetaA = -5° %and therefore yA=RA*tan(tetaA)=-0.8 tetaAg=-5; tetaA=tetaAg*pi/180; yA=-0.8; % %Function fcav is called varying the distance dist between the mirrors % for i=1:num d=dist(i); f=fcav(RB,RA,d,yA,tetaA); F(i,:)=[d,f]; %The function calculates f=[ypA,ypB,tetaBg,tetapAg]; %Hence F(i,:)=[d,ypA,ypB,tetaBg,tetapAg] end F % %First plot without the use of the MATLAB function AXIS % subplot(2,1,1) plot(F(:,1),F(:,2),'ro-',F(:,1),F(:,3),'bd-'),grid on title('ypA (red) and ypB (blue) function of d') subplot(2,1,2) plot(F(:,1),F(:,4),'ro-',F(:,1),F(:,5),'bd-'),grid on title('tetaB (red) and tetapA (blue) function of d'),figure % %Second plot with the use of the MATLAB function AXIS % subplot(2,1,1) plot(F(:,1),F(:,2),'ro-',F(:,1),F(:,3),'bd-') title('ypA (red) and ypB (blue) function of d') axis([5,20,-2,2]),grid on subplot(2,1,2) plot(F(:,1),F(:,4),'ro-',F(:,1),F(:,5),'bd-') title('tetaB (red)and tetapA (blue) function of d'),grid on axis([5,20,-10,10]) %============================================== % |
|||
| Top | |||
| Script S1_2_20B.m | |||
|
|||
|
%==========================================
%Cavity 3B %Function fcav is required %========================================== % %radii of the two mirrors in mm are given RB=-10; RA=10; % %we assume tetaA = -5° %and therefore yA=RA*tan(tetaA)=-0.8 mm tetaAg=-5; tetaA=tetaAg*pi/180; yA=-0.8; % %the distance between the mirrors is set to d d=15; %the function fcav is called n times, for example, %determining for n times the pair (yA, tetaA) % n=15 % for i=1:n f=fcav(RB,RA,d,yA,tetaA); %from the function we have f=[ypA,ypB,tetaBg,tetapAg]; %yA and tetaA are updated yA=f(1); tetaA=f(4)*pi/180; F(i,:)=[f(1),f(4)]; end % the array F has n rows and two columns F %the x array is simply a count of the time the pair is calculated by the %function fcav allowing an abscissa for the next plots x=1:n; subplot(2,1,1) plot(x,F(:,1),'ro-'),grid on,title('the first n = 15 subsequent values of ypA'), axis([1,15,-1,0.6]) subplot(2,1,2) plot(x,F(:,2),'bd-'),grid on,title('the first n = 15 subsequent values of tetapA'), axis([1,15,-5.1,5.1]) |
|||
| Top | |||
| Function fcav.m | |||
|
|||
|
%==============================================
%function fcav %necessary to run %Cavity_3A and Cavity 3B %============================================== % function f=fcav(RB,RA,d,yA,tetaA) % %values transmitted by the main script %%%%radii of the two mirrors RA and RB %%%%distance d between the two mirrors %%%%distance yA %%%%angle tetaA % %================================================ %a ray is moving from the mirror A to B % %d has the minus sign according to our conventions %(see Sec.1.1.2) t1=[1 -d;0 1]; t2=[yA;tetaA]; T=t1*t2; %================================================ %angle of incidence on the mirror B is calculated % s1=[1 0;2/RB -1]; s2=T; S=s1*s2; %================================================ %the ray moves back from the mirror B to A % %now d has the positive sign x1=[1 d;0 1]; x2=S; X=x1*x2; %================================================ %angle of incidence on the mirror A is calculated % y1=[1 0;2/RA -1]; y2=X; Y=y1*y2; %================================================ %a ray is moving again from the mirror A to B % %d has now the minus sign z1=[1 -d;0 1]; z2=Y; Z=z1*z2; % %================================================ %values conveyed back to the main script % y'A and y'B ypA=Y(1); ypB=Z(1); %tetaB and tetapA tetaBg=X(2)*180/pi; tetapAg=Z(2)*180/pi; result=[ypA,ypB,tetaBg,tetapAg]; %final instruction od the function f=result; %================================================ % |
|||
| Top | |||