summaryrefslogtreecommitdiff
path: root/abcd.m
blob: faa46c0c274a3762fdd4deda0255123337e14bb0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
function fs_abcd = abcd_free_space( distance)
	fs_abcd=[1, distance; 0,1];
endfunction

function lens_abcd =abcd_lens(focal_distance)
	lens_abcd = [1, 0; -1/focal_distance, 1];
endfunction

function qnew=q_afteer_element(q_old,abcd)
	qnew=(q_old*abcd(1,1)+abcd(1,2))/(q_old*abcd(2,1)+abcd(2,2));
endfunction

function q = prop(x_final, q_in, elements)
	q(size(x_final,2))=0;
	for i=1:size(x_final,2)
		x_final_i=x_final(i);
		xend=0;
		q_end=q_in;
		for k=1:size(elements,2) 
			el=nth(elements,k);
			if ( el.x <= x_final_i)
				abcd=abcd_free_space(el.x-xend);
				q_end=q_afteer_element(q_end,abcd);
				q_end=q_afteer_element(q_end,el.abcd);
				xend=el.x;
			endif
		endfor
		if (x_final_i > xend);
			abcd=abcd_free_space(x_final_i-xend);
			q_end=q_afteer_element(q_end,abcd);
			xend=x_final_i;
		endif
		q(i)=q_end;
	endfor
endfunction

function waste =q2waste(q, lambda)
	for i=1:size(q,2)
		waste(i)=sqrt (-lambda/pi/imag(1/q(i)));
	endfor
endfunction

function radius =q2radius(q, lambda)
	for i=1:size(q,2)
		radius(i)=(1/real(1/q(i)));
	endfor
endfunction

function q=waste_r2q(waste,R,lambda)
	q=1/(1/R-I*lambda/pi/waste/waste);
endfunction




########################################## 
lambda= 1.064E-6 ;
Ltot= 1 ;
r0= 1.0E+100 ;
w0= 25.63e-6;
#w0= 3.79E-4 ;
lns1.abcd=abcd_lens( 0.25 ) ;
lns1.x= 0.37680270021479 ;
lns2.abcd=abcd_lens( 0.1 ) ;
lns2.x= 0.90277021575519 ;
rf=1e100;
wf=25.630e-6;
########################################## 
source("answ.txt")


q0=waste_r2q(w0,r0,lambda);
optics=list(lns1,lns2,lns3);
optics_forward=optics;

x=0:.01:Ltot;
printf("=================================\n")
q1=prop(x,q0,optics);
printf("=================================\n")
w1=q2waste(q1, lambda);
r1=q2radius(q1,lambda);

printf("=================================\n")
#q1b=prop(Ltot,q0,optics)
#wb=q2waste(q1b, lambda)
#rb=-q2radius(q1b,lambda)
#because of back propogation
rf=-rf;
q1b=waste_r2q(wf,rf,lambda);

lns1.x=Ltot-lns1.x;
lns2.x=Ltot-lns2.x;
lns3.x=Ltot-lns3.x;
optics=list(lns3,lns2,lns1);
q2b=prop(x,q1b,optics);
printf("=================================\n")
wb=q2waste(q2b, lambda);
rb=q2radius(q2b,lambda);
xb=Ltot-x;
#plot (x,w1, "1")
plot (x,w1, "1", xb, wb, "2")

printf("=================================\n")
printf("======= final check =============\n")
printf("======= after propogatin ========\n")
printf("following are theoretical values: \n")
w0
r0
wf
rf
q0=waste_r2q(w0,r0,lambda);
optics=list(lns1,lns2,lns3);
qtf=prop(Ltot, q0, optics_forward);
printf("values below should match 'wf' and 'rf': \n")
waste = q2waste(qtf, lambda)
radius = q2radius(qtf,lambda)

pause(100)
quit()
system("cat answ.txt answ.txt")
answ=menu("Is it reasonable mode matching?","yes","no")
if (answ ==1)
	printf("xxxxxxxxxxxxxxxxxxxxxxxxxxxx")
	system("cat answ.txt >>good_mode_matching.txt")
else
	printf("------------------------------")
endif	

exit
#
#gset term postscript
#gset output "foo.ps"
#plot (x,w1, "1", xb, wb, "2")