NB. Isotropic scattering of source distributed iniformly in slab. NB. Usage: (T; hnmu) Uslab k; nscat NB. Here, T=slab thickness, hnmu= number of (positive) mu bins NB. k= number of Monte Carlo scattering photons, scatter "nscat" times NB. since this is a lambda-iteration, we must set nscat >> T^2 Uslab=: 4 : 0 'T hnmu'=. x T2=. -: T NB. optical depth to midplane nmu=. +: hnmu NB. total (positive and negative) mu bins 'k nscat'=. y NB. number of initial photons and scatterings Int=. k# 1 NB. Set Int=1 for the "k" initial photons z=. T2- T*rand k NB. initially emitted photons have uniform fret=: _1+ 2*int01 nmu NB. frets to divide -1Su;Sd NB. plot emergent intensities NB. they should be equal -- difference indicates statistical error NB. Let's compare to the "exact" solution at the mu's of bin centers: NB. load '/your_path/Uniform.ijs' NB. get matrix transform routine NB. tau=. tau_grid2 0.001 10 1 NB. define a 63-point tau grid over [0,2]. NB. 'Ftot Itop'=. Uniform tau;mubin NB. run code NB. plot mubin;>(1p1*Itop);((1-remain)%~(-:Su+Sd)) NB. plot comparison NB. (1-remain)%~ corrects for the photons still trapped in the slab NB. Also, we multiply the matrix transform result by pi: physical vs. NB. "astrophysical flux" (i.e., per steradian) used in matrix equations. NB. We sholudn't make nphoton so large that memory is filled and there NB. are page faults. Then to get better statistics, do many runs: NB. Run "Uslab" ncycle times: UCYC=: 3 : 0 'T hnmu nphoton nscat ncycle'=. y z=. (T;hnmu) Uslab nphoton;nscat 'mubin SSu SSd'=. z count=. 1 while. count< ncycle do. 'mubin Su Sd'=. (T;hnmu)Uslab nphoton;nscat SSu=. SSu + Su SSd=. SSd + Sd count=. >: count NB. Look at 'UCYC_count.log' to monitor progress: ((": count),LF) (1!:2)