Presentation is loading. Please wait.

Presentation is loading. Please wait.

PH24010 Data Handling and Statistics Photon Scattering program written in MathCAD.

Similar presentations


Presentation on theme: "PH24010 Data Handling and Statistics Photon Scattering program written in MathCAD."— Presentation transcript:

1 PH24010 Data Handling and Statistics Photon Scattering program written in MathCAD

2 The Golden Rule of Programming Applies to all programming K.I.S.S. principle –Keep –It–It –Simple –Stupid

3 MathCAD Programs Structures if, otherwise, for, while –Indentation & vertical bars –Watch selection rectangle – to increase (more lines) – to swap sides No GOTO –Considered harmful

4 MathCAD programs if statement Better than if() function for complicated cases. otherwise statement to catch unhandled cases.

5 Programmed if statement Note: –Comparisons –use of otherwise to catch all cases

6 MathCAD programs – The for loop Loop extend shown by indent ‘Result’ array built up Note syntax of ‘for’ line Use when you know in advance how many iterations

7 The while loop Execute statements while a condition is true Used when you don’t know in advance how many times loop will be executed. Loop while you are searching Loop while error is too big Loop while system is stable

8 A while loop example Find first member of vector ‘Vec’ greater than threshold, ‘t’ Written as function j is index while loop return index & value as vector

9 Longer Loops Use ‘Add Line’ in body of loop to extend scope of loop. Lines added at vertical bar key swaps sides of selection bar

10 Longer Loops

11 Program Example Photon Scattering #1 1.Photon enters box 2.Travels random distance 3.Scatter through random angle 4.Repeat from step 2 until photon leaves box 5.Record walk for posterity

12 Photon Scattering Program to create Walk

13 Program Example Photon Scattering #2 Store x-y co-ordinates and i (loop count) Write functions for –Pathlength() –ScatterAngle(  ) –InBox(x,y) Test these functions !!!

14 Photon Scattering PathLength function  path is related to ln(2)/mean path x placeholder is dummy rexp(1,  path ) function returns vector of 1 number from distribution indexing to extract element 0 from vector

15 Photon Scattering ScatterAngle(  ) Isotropic scatter - uniform Give 1 angle randomly between –    Similar use of built-in random numbers to earlier. Deal with anisotropy later

16 Photon Scattering InBox(V) function Takes x,y as arguments 2 way logical expression –LoLimit < x < HiLimit Uses multiplication to form AND Returns 1 if in box, 0 otherwise

17 Photon Scattering Program to create Walk

18 Photon Scattering Using the program

19 Photon Scattering Conclusions 14 line program + functions Records entire walk Extract info from result vector Easy to extend –3D scatter –Anisotropy Change ScatterAngle(  )

20 Combining Many Walks Use stack() to join results together

21 Simple anisotropy Assume ‘normal’ distribution about angle

22 Many walks with anisotropy


Download ppt "PH24010 Data Handling and Statistics Photon Scattering program written in MathCAD."

Similar presentations


Ads by Google