1 / 22

PH24010 Data Handling and Statistics

PH24010 Data Handling and Statistics. Photon Scattering program written in MathCAD . The Golden Rule of Programming. Applies to all programming K.I.S.S. principle K eep I t S imple S tupid. MathCAD Programs Structures. if, otherwise, for, while Indentation & vertical bars

reilly
Download Presentation

PH24010 Data Handling and Statistics

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. PH24010Data 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 • Simple • Stupid

  3. MathCAD ProgramsStructures • if, otherwise, for, while • Indentation & vertical bars • Watch selection rectangle • <Space> to increase (more lines) • <Insert> to swap sides • No GOTO • Considered harmful

  4. MathCAD programsif 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 • <Insert> key swaps sides of selection bar

  10. Longer Loops

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

  12. Photon ScatteringProgram to create Walk

  13. Program ExamplePhoton Scattering #2 • Store x-y co-ordinates and i (loop count) • Write functions for • Pathlength() • ScatterAngle(q) • InBox(x,y) • Test these functions !!!

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

  15. Photon ScatteringScatterAngle(q) • Isotropic scatter - uniform • Give 1 angle randomly between –pp • Similar use of built-in random numbers to earlier. • Deal with anisotropy later

  16. Photon ScatteringInBox(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 ScatteringProgram to create Walk

  18. Photon ScatteringUsing the program

  19. Photon ScatteringConclusions • 14 line program + functions • Records entire walk • Extract info from result vector • Easy to extend • 3D scatter • Anisotropy • Change ScatterAngle(q)

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

  21. Simple anisotropy • Assume ‘normal’ distribution about angle

  22. Many walks with anisotropy

More Related