summaryrefslogtreecommitdiff
path: root/session.out
blob: 7832cf9da4e8c4bfedbce0deecd4ecfba974c887 (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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
Starts dribbling to session.out (2006/7/5, 20:11:29).
(%i2) 
dist(z):=(MATRIX([1,z],[0,1]))$

(%i3) lens(f):=(MATRIX([1,0],[-1/f,1]))$

(%i4) 
abcd(optics_system):=block([tmp:MATRIX([1,0],[0,1])], (for i:1 thru length(optics_system) do tmp:optics_system[i].tmp ), return(tmp))$ 

prop(q0,abcd):=(abcd[1][1]*q0+abcd[1][2])/(abcd[2][1]*q0+abcd[2][2])$

(%i6) 
wr2q(w,r):=1/(1/r-%I*lamb/%PI/(w^2))$

(%i7) q2w(q):=sqrt(-lamb/%PI/imagpart(1/q))$

(%i8) q2r(q):=block([rp:(realpart(1/q))],
	(if (rp = 0)
		then
		(print("#dbg: R=1/0, will substitute R with something big"),
		return(1e100))
		else
			return(1/rp)
	)  
) $

(%i9) 

/* find q0 for such q */
q2w0(q):=block([w,r,w0],
	w:q2w(q),r:q2r(q), 
	w0:(w/sqrt(1+(%Pi*w^2/lamb/r)^2)), 
	return (w0) 
	)$

(%i10) q2z0(q):=block([w,r],
	w:q2w(q),r:q2r(q), return(r/(1+(lamb*r/%Pi/w^2)^2))
	)$

(%i11) q2q0(q):=%I*%Pi*q2w0(q)^2/lamb$

(%i12) 
q0f2z_for_colim_lens(q0,f):=f+%Pi*q2w(q0)^2/lamb$

(%i13) 
qf2colim_lens_posit(qstart,f):= block([q0,z0,zd],
	q0:q2q0(qstart),
	z0:q2z0(qstart),
	zd:q0f2z_for_colim_lens(q0,f),
	return(zd-z0)
)$

(%i14) 

check_real(x):=if featurep(x[1],real) then if featurep(x[2],real) then if featurep(x[3],real) then true else false $

(%i15) 
check_posit(x):=if (part(x[1],2)>0) then if (part(x[2],2)>0) then if (part(x[3],2)>0) then true else false $

(%i16) 
check_sm1(x):=if (part(x[1],2)<ltotal) then if (part(x[2],2)<ltotal) then if (part(x[3],2)<ltotal) then true else false $

(%i17) 
select_realsolutions(x):=block([temp:[]], for i:1 thru length(x) do (if check_real(x[i]) then temp:float(append(temp,[x[i]])) ), return(temp) ) $ 

select_posit_solutions(x):=block([temp:[]], for i:1 thru length(x) do (if check_posit(x[i]) then temp:float(append(temp,[x[i]])) ), return(temp) ) $ 

select_sm1_solutions(x):=block([temp:[]], for i:1 thru length(x) do (if check_sm1(x[i]) then temp:float(append(temp,[x[i]])) ), return(temp) ) $ 

/*=========================================================*/
/* 
   match one Gauss beam parameter q0(w0,r0)
   to another one qf(wf,qf)
   with the help of two known lens.
   distance between q0 and qf is 'ltotal'
   q0>|----z1-----(f1)------z2-------(f2)------z3--------|>qf
      ^                                                  ^
      |-------------------ltotal-------------------------|
   the system should looks like above.
 */  
/*=========================================================*/
qffql2z1z2z3(q0,f1,f2,qf,ltotal):=block(
	[
	 m1,m2,m3,m4,m5,z1,z2,z3,
	 optics, mfull, 
	 q0r,qoi, qfr,qfi,
	 eqt,eq1,solut,
	 eq1,eq2,eq3,
	 eqn1, eqn2,eqn3,
	 eqnev1, eqnev2, eqnev3,
	 slt, rsol
	 ],
	 
	m1:dist(z1),
	m2:lens(f1),
	m3:dist(z2),
	m4:lens(f2),
	m5:dist(z3),

	optics:[m1,m2, m3, m4, m5],
	mfull:abcd(optics),

	eqt:qf=prop(q0,mfull),
	
	q0r:float(realpart(q0)),
	q0i:float(imagpart(q0)),
	qfr:float(realpart(qf)),
	qfi:float(imagpart(qf)),
	
	eq1:ev(eqt, q0=q0r+q0i*%I, qf=qfr+qfi*%I),

	solut:solve([eq1], [z3]),

	eqn1:imagpart(solut[1]),
	eqn2:realpart(solut[1]),
	eqn3:z1+z2+z3=ltotal,

	eqnev1:ev(eqn1,numer),
	eqnev2:ev(eqn2,numer),
	eqnev3:ev(eqn3,numer),
	

	slt:solve([eqnev1,eqnev2,eqnev3],[z1,z2,z3]),
	
	print("slt=",slt),

	rsol:select_realsolutions(slt),
	rsol:select_posit_solutions(rsol),
	rsol:select_sm1_solutions(rsol),
	
	print("rsol=",rsol),


	return(rsol)
);

(%o20) qffql2z1z2z3(q0, f1, f2, qf, ltotal) := 
block([m1, m2, m3, m4, m5, z1, z2, z3, optics, mfull, q0r, qoi, qfr, qfi, eqt, 
eq1, solut, eq1, eq2, eq3, eqn1, eqn2, eqn3, eqnev1, eqnev2, eqnev3, slt, 
rsol], m1 : dist(z1), m2 : lens(f1), m3 : dist(z2), m4 : lens(f2), 
m5 : dist(z3), optics : [m1, m2, m3, m4, m5], mfull : abcd(optics), 
eqt : qf = prop(q0, mfull), q0r : float(realpart(q0)), 
q0i : float(imagpart(q0)), qfr : float(realpart(qf)), 
qfi : float(imagpart(qf)), eq1 : ev(eqt, q0 = q0r + q0i %I, 
qf = qfr + qfi %I), solut : solve([eq1], [z3]), eqn1 : imagpart(solut ), 
								     1
eqn2 : realpart(solut ), eqn3 : z1 + z2 + z3 = ltotal, 
		     1
eqnev1 : ev(eqn1, numer), eqnev2 : ev(eqn2, numer), eqnev3 : ev(eqn3, numer), 
slt : solve([eqnev1, eqnev2, eqnev3], [z1, z2, z3]), print("slt=", slt), 
rsol : select_realsolutions(slt), rsol : select_posit_solutions(rsol), 
rsol : select_sm1_solutions(rsol), print("rsol=", rsol), return(rsol))
(%i21) /*=========================================================*/
/*
	Zero ewaste to zero waste transformatin with lense
	q0|------------(f)-----------|qf0
	  ^             ^            ^
	  |----z--------|            |
	  |                          |
	  |-------------l------------|
	  we are lookking for z1,l
*/
	q0fq02z1(q0,f,qf):=block([f0,z1,w0tmp:q2w(q0),wftmp:q2w(qf)],
		f0:%Pi*w0tmp*wftmp/lamb,
		z1:f+w0tmp/wftmp*sqrt(f^2-f0^2),
		return(z1)
		)$

(%i22) 	q0fq02z2(q0,f,qf):=block([f0,z2,w0tmp:q2w(q0),wftmp:q2w(qf)],
		f0:%Pi*w0tmp*wftmp/lamb,
		z2:f+wftmp/w0tmp*sqrt(f^2-f0^2),
		return(z2)
		)$

(%i23) 	q0fq02l(q0,f,qf):=q0fq02z1(q0,f,qf)+q0fq02z2(q0,f,qf)$

(%i24) /*=========================================================*/
/*
   for back propogation we need to change R -> -R
*/
q2bq(q):=wr2q(q2w(q),-q2r(q));

(%o24) 		       q2bq(q) := wr2q(q2w(q), - q2r(q))
(%i25) /*=========================================================*/
/*=========================================================*/
/*=========================================================*/
/*=========================================================*/



/*=========================================================*/
/* lets solve final waste to parrallel beam, 
   (actually back propogation)
*/
/*=========================================================*/
/* 
   this code tryes to find configuration of 3 given lenses with focal
   length f1,f2, f_col 
   in such a way that starting from with initial waste (w0) 
   and radius (r0)
   after propogation through lens 1 (f1 focal length) 
   and 2 (f2 focal length) 
   we have a collimated region with length (dist_betw_f2_f_col)
   and then after passing through the lense 3 we at some distance
   match to the final waste and radius (wend, rend).
   Total distance between starting and final lense position will be
   calculated in to the 'ltotal'
   Beam have a wave length 'lamb'.
   Everything calculated in meters.
*/   
/*======== Initial condition ==============================*/
ltotal:4.85$

(%i26) lamb:1.064e-6$

(%i27) /* starting waste */
w0:0.30e-3$

(%i28) r0:1e100$

(%i29) /* final waste */	
wend:37.09e-6$

(%i30) rend:1e100$

(%i31) 
/* lenses focal length */
f1:.025$

(%i32) f2:.075$

(%i33) f_col:0.7118$

(%i34) 
/* collimated region size */
dist_betw_f2_f_col:.30$

(%i35) /*=========================================================*/

optics_after_parral_beam:[lens(-.111),dist(.05)]$

(%i36) 
	q0:ev(wr2q(w0,r0),numer)$

(%i37) 	qend:wr2q(wend,rend)$

(%i38) /*
qf:prop(qend,abcd(reverse(optics_after_parral_beam)))$
float(realpart(qf))$
float(imagpart(qf))$
*/
qf:qend$

(%i39) 
/*finally position of collimated lens */
z_col:float(qf2colim_lens_posit(qf,f_col))$

Division by 0
#0: q2w(q=1/(1.0E-100-773.4423732003382*%I/%PI))
#1: q2w0(q=1/(1.0E-100-773.4423732003382*%I/%PI))
#2: q2q0(q=1/(1.0E-100-773.4423732003382*%I/%PI))
 -- an error.  Quitting.  To debug this try debugmode(true);
(%i40) if (z_col <0) 
	then (print("it is not possible to get collimated beam  z_col=",z_col),
	quit() 
) $

Maxima was unable to evaluate the predicate:
z_col < 0
 -- an error.  Quitting.  To debug this try debugmode(true);
(%i41) qf:prop(qf,abcd([dist(z_col),lens(f_col)]))$

(%i42) 



qf:prop(qf,abcd([dist(dist_betw_f2_f_col),lens(f2)]) )$

(%i43) 
/* below something wrong */
dist2waste:ev(-q2z0(qf),numer)$

Division by 0
#0: q2w(q=((MATRIX([1,0],[-13.33333333333333,1]) . MATRIX([1,0.3],[0,1]) . MATRIX([1,0],[0,1]))[1][1]*((MATRIX...)
#1: q2z0(q=((MATRIX([1,0],[-13.33333333333333,1]) . MATRIX([1,0.3],[0,1]) . MATRIX([1,0],[0,1]))[1][1]*((MATRIX...)
 -- an error.  Quitting.  To debug this try debugmode(true);
(%i44) rad_now:ev(q2r(qf),numer)$

(%i45) qf:ev(q2q0(qf),numer)$

Division by 0
#0: q2w(q=((MATRIX([1,0],[-13.33333333333333,1]) . MATRIX([1,0.3],[0,1]) . MATRIX([1,0],[0,1]))[1][1]*((MATRIX...)
#1: q2w0(q=((MATRIX([1,0],[-13.33333333333333,1]) . MATRIX([1,0.3],[0,1]) . MATRIX([1,0],[0,1]))[1][1]*((MATRIX...)
#2: q2q0(q=((MATRIX([1,0],[-13.33333333333333,1]) . MATRIX([1,0.3],[0,1]) . MATRIX([1,0],[0,1]))[1][1]*((MATRIX...)
 -- an error.  Quitting.  To debug this try debugmode(true);
(%i46) /*===========================================*/


space_between_wastes:ev(q0fq02l(q0,f1,qf), numer)$

Division by 0
#0: q2w(q=1/(1.0E-100-11.82222222222223*%I/%PI))
#1: q0fq02z1(q0=1/(1.0E-100-11.82222222222223*%I/%PI),f=0.025,qf=((MATRIX([1,0],[-13.33333333333333,1]) . MATRIX([1,0.3],[0,1]) . MATRIX([1,0],[0,1]))[1][1]*((MATRIX...)
#2: q0fq02l(q0=1/(1.0E-100-11.82222222222223*%I/%PI),f=0.025,qf=((MATRIX([1,0],[-13.33333333333333,1]) . MATRIX([1,0.3],[0,1]) . MATRIX([1,0],[0,1]))[1][1]*((MATRIX...)
 -- an error.  Quitting.  To debug this try debugmode(true);
(%i47) dist2first_lens:ev(q0fq02z1(q0,f1,qf),numer)$

Division by 0
#0: q2w(q=1/(1.0E-100-11.82222222222223*%I/%PI))
#1: q0fq02z1(q0=1/(1.0E-100-11.82222222222223*%I/%PI),f=0.025,qf=((MATRIX([1,0],[-13.33333333333333,1]) . MATRIX([1,0.3],[0,1]) . MATRIX([1,0],[0,1]))[1][1]*((MATRIX...)
 -- an error.  Quitting.  To debug this try debugmode(true);
(%i48) dist2first_lens_tmp:ev(q0fq02z2(q0,f1,qf),numer)$

Division by 0
#0: q2w(q=1/(1.0E-100-11.82222222222223*%I/%PI))
#1: q0fq02z2(q0=1/(1.0E-100-11.82222222222223*%I/%PI),f=0.025,qf=((MATRIX([1,0],[-13.33333333333333,1]) . MATRIX([1,0.3],[0,1]) . MATRIX([1,0],[0,1]))[1][1]*((MATRIX...)
 -- an error.  Quitting.  To debug this try debugmode(true);
(%i49) 
z1:ev(dist2first_lens,numer)$

(%i50) z2:ev(space_between_wastes+dist2waste,numer)$

(%i51) z3:ev(z2+dist_betw_f2_f_col,numer)$

(%i52) 
ltotal:z3+z_col$

(%i53) 
/*
qf:wr2q( -q2r(qf), q2w(qf) )$
*/ 


/*
rsol:qffql2z1z2z3(q0,f1,f2,qf,ltotal-z_col)$
	print("rsol=",rsol),
*/


	with_stdout("answ.txt", 
		print("##########################################"),
		print( "lambda=",lamb),
		print( "Ltot=",  ltotal),
		print( "r0=",  r0),
		print( "w0=",  w0),
		print(),
		print( "lns1.abcd=abcd_lens(", f1 , ")" ),
		print( "lns1.x=",  z1   ),
		print( "lns2.abcd=abcd_lens(", f2 , ")" ),
		print( "lns2.x=", (z2) ),
		print( "lns3.abcd=abcd_lens(", f_col , ")" ),
		print( "lns3.x=", (z3) ),
		print("wf=", wend),
		print("rf=", rend),
		/*
		qfinal:prop(q0,ev(mfull)),
		wfinal:float(q2w(qfinal)),
		rfinal:float(q2r(qfinal)),
		print("#final waste=", wfinal),
		print("#I was aiming to final waste"),
		print("#final radius=", rfinal),
		print("#I was aiming to final radius"),
		*/
		print("##########################################")
	)$

(%i54) 	system("cat answ.txt")$

(%i55) 	system("xterm -e octave abcd.m") $

(%i56) 
quit()$