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

Slides:



Advertisements
Similar presentations
Lists, Loops, Validation, and More
Advertisements

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 5- 1 STARTING OUT WITH Visual Basic 2008 FOURTH EDITION Tony Gaddis.
Programming with App Inventor Computing Institute for K-12 Teachers Summer 2012 Workshop.
Formulas, Ranges, and Functions. Formulas n Formulas perform operations such as addition, multiplication, and comparison on worksheet values. n Formulas.
Introduction to Computing Science and Programming I
String and Lists Dr. Benito Mendoza. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list List.
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Writing Programs in MathCAD
Chapter 8 and 9 Review: Logical Functions and Control Structures Introduction to MATLAB 7 Engineering 161.
HCI 530 : Seminar (HCI) Damian Schofield. HCI 530: Seminar (HCI) Transforms –Two Dimensional –Three Dimensional The Graphics Pipeline.
Week 10 Recap CSE 115 Spring For-each loop When we have a collection and want to do something to all elements of that collection we use the for-each.
Starting Out with C++: Early Objects 5/e © 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5 th Edition Chapter 16 Exceptions,
C How to Program, 6/e Summary © by Pearson Education, Inc. All Rights Reserved.
Chapter 6 Advanced Functions Copyright 2005 Radian Publishing Co.
The foreach LooptMyn1 The foreach Loop The foreach loop gives an easy way to iterate over arrays. foreach works only on arrays, and will issue an error.
Python – Part 4 Conditionals and Recursion. Modulus Operator Yields the remainder when first operand is divided by the second. >>>remainder=7%3 >>>print.
Chapter 13 Recursion. Topics Simple Recursion Recursion with a Return Value Recursion with Two Base Cases Binary Search Revisited Animation Using Recursion.
08/10/ Iteration Loops For … To … Next. 208/10/2015 Learning Objectives Define a program loop. State when a loop will end. State when the For.
CIS 218 Advanced UNIX1 CIS 218 – Advanced UNIX (g)awk.
5-1 Chapter 5 The Repetition Process in VB.NET. 5-2 Learning Objectives Understand the importance of the repetition process in programming. Describe the.
20-753: Fundamentals of Web Programming 1 Lecture 12: Javascript I Fundamentals of Web Programming Lecture 12: Introduction to Javascript.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
Arrays BCIS 3680 Enterprise Programming. Overview 2  Array terminology  Creating arrays  Declaring and instantiating an array  Assigning value to.
Arrays An array is a data structure that consists of an ordered collection of similar items (where “similar items” means items of the same type.) An array.
MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright.
Interpretation Environments and Evaluation. CS 354 Spring Translation Stages Lexical analysis (scanning) Parsing –Recognizing –Building parse tree.
Copyright © 2010 Certification Partners, LLC -- All Rights Reserved Perl Specialist.
BACS 287 Programming Logic 1. BACS 287 Programming Basics There are 3 general approaches to writing programs – Unstructured – Structured – Object-oriented.
Built-in Data Structures in Python An Introduction.
sequence of execution of high-level statements
What does C store? >>A = [1 2 3] >>B = [1 1] >>[C,D]=meshgrid(A,B) c) a) d) b)
Slide 1 PHP Arrays and User Defined Functions ITWA133.
Dale Roberts 1 Program Control - Algorithms Department of Computer and Information Science, School of Science, IUPUI CSCI N305.
Control Structures sequence of execution of high-level statements.
PH24010 Data Handling and Statistics Use of MathCAD to handle statistical data Data storage in vectors and matrices MathCAD’s built-in functions: –Mean,
Copyright © 2003 ProsoftTraining. All rights reserved. Perl Fundamentals.
Lecture 26: Reusable Methods: Enviable Sloth. Creating Function M-files User defined functions are stored as M- files To use them, they must be in the.
Quiz 3 is due Friday September 18 th Lab 6 is going to be lab practical hursSept_10/exampleLabFinal/
Access Queries Agenda 6/16/14 Review Access Project Part 1, answer questions Discuss queries: Turning data stored in a database into information for decision.
 2008 Pearson Education, Inc. All rights reserved. 1 Arrays and Vectors.
CS190/295 Programming in Python for Life Sciences: Lecture 6 Instructor: Xiaohui Xie University of California, Irvine.
Searching CSE 103 Lecture 20 Wednesday, October 16, 2002 prepared by Doug Hogan.
Data Structures Arrays and Lists Part 2 More List Operations.
CS 153: Concepts of Compiler Design October 12 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
Finishing up Chapter 5. Will this code enter the if statement? G=[30,55,10] if G
Loop Applications and Review CS 103 February 27, 2004.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy.
Python – Part 4 Conditionals and Recursion. Conditional execution If statement if x>0:# CONDITION print (‘x is positive’) Same structure as function definition.
Loops and Arrays Chapter 19 and Material Adapted from Fluency Text book.
Chapter 15 Running Time Analysis. Topics Orders of Magnitude and Big-Oh Notation Running Time Analysis of Algorithms –Counting Statements –Evaluating.
String and Lists Dr. José M. Reyes Álamo. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list.
26/06/ Iteration Loops For … To … Next. 226/06/2016 Learning Objectives Define a program loop. State when a loop will end. State when the For.
String and Lists Dr. José M. Reyes Álamo.
EasyCode Foundations Vocabulary Terms.
CS1371 Introduction to Computing for Engineers
Scripts & Functions Scripts and functions are contained in .m-files
Programming Fundamentals
Beginning C Lecture 4 Lecturer: Dr. Zhao Qinpei
While Loops BIS1523 – Lecture 12.
Call Stacks, Arguments and Returns
Arrays, For loop While loop Do while loop
Supplementary exercise : Generation of a random value picked
Structured Programming Taken from notes by Dr. Neil Moore
String and Lists Dr. José M. Reyes Álamo.
Logical Operations In Matlab.
Vocabulary Memory Cards--Sample
Chap 7. Advanced Control Statements in Java
Presentation transcript:

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 –Keep –It–It –Simple –Stupid

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

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

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

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

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

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

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

Longer Loops

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

Photon Scattering Program to create Walk

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 !!!

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

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

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

Photon Scattering Program to create Walk

Photon Scattering Using the program

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

Combining Many Walks Use stack() to join results together

Simple anisotropy Assume ‘normal’ distribution about angle

Many walks with anisotropy