Document 14539468

advertisement
Physics 2660: Fundamentals of Scientific Computing Lecture 9 News and Announcements
•  HW08 is assigned – due 6pm Sunday 3 April at 6pm
•  Reminder: Use piazza for asking questions and pay aBention to the discussions there
•  Office hours reminder:
–  My office hours are in Room 022-­‐‑C (our computer lab) from 3:30-­‐‑5pm on Tuesdays or by appointment
–  TA office hours, also in Room 022-­‐‑C
•  Mondays 5-­‐‑8pm
•  Tuesdays 5-­‐‑8pm
•  Lab09 will be this week Thursday as normal
2
Review and Today’s Outline
•  Last time:
– 
– 
– 
– 
Exam
Structures
Libraries Statistics
•  Today:
– 
– 
– 
– 
Review of exam
More on strings
More on arrays and pointers
Debugging
3
Exam Review
4
Exam Results
•  Average:
•  Multiple choice went fairly well
16 14 N_students –  Mult choice: 39.33/46
–  WriBen: 40.63/54
Mul4ple Choice: Max 46 –  Performance on this portion of the exam was reasonable
8 6 2 0 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 Score [points] Wri=en Por4on: Max 54 N_students •  Short answer: •  Code examination:
10 4 –  Some repeats from in-­‐‑
lecture examples
–  Touched on material across the first 7 weeks
–  Lenient on the ten-­‐‑word-­‐‑
max criteria
12 9 8 7 6 5 4 3 2 1 0 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 Score [points] 5
Multiple Choice: Challenging Top Five Multiple Choice: Challenging Top Five Short Answer: Notes
•  Don’t ever forget the mathematical form of the Gaussian distribution!
8
Example Code: Notes
This is actually a poorly-­‐‑
asked question, since the answer is simply “YES”.
while(..) does not strictly need { } brackets, since execution statement s just one line
also, the argument of the while (..) statement is a conditional – remember that conditionals all evaluate to some value (0 implies ‘false’, non-­‐‑zero implies ‘true’
type this code up yourself and see if it compiles!
9
Example Code: Notes
10
Algorithm: Notes
•  Simply wanted exactly a response like HW01
11
Algorithm: Notes
•  Simply wanted exactly a response like HW01
12
Extra Credit
Extra Credit: Max 5 35 30 N_students 25 20 15 10 5 0 0 1 2 3 4 5 Scores [points] 13
Extra Credit
14
Monte Carlo Integration
15
Multiple Measurements
16
Multiple Measurements
17
Multiple Measurements
Important vocabulary:
-­‐‑ mean
-­‐‑ variance -­‐‑ standard deviation or RMS
The standard deviation has an intimate relationship to the definition of the Gaussian (aka normal) distribution.
Here the standard deviation of the sample of measurements is usually the best estimate of the standard deviation of the parent distribution.
18
Standard Deviation
19
The Importance of the Gaussian Distribution
•  If ploBed, our measurements will look approximately like a Gaussian Distribution.
–  Is this magic?
–  No!
•  Recall the Central Limit Theorem, paraphrased
–  Any collection of random measurements of some variable will resemble a Gaussian
20
The Importance of the Gaussian Distribution
•  If ploBed, our measurements will look approximately like a Gaussian Distribution.
–  Is this magic?
–  No!
•  Recall the Central Limit Theorem, paraphrased
–  Any collection of random measurements of some variable will resemble a Gaussian
•  Back to the whale:
–  Our random measurements here are the results of MC integration of the whale shape
–  An infinite number of such measurements would be a perfect Gaussian
21
But…What about the True Value?
22
But…What about the True Value?
The change to using N-­‐‑1 is called Bessel’s Correction. Read more here What happens below as N gets very large?
23
Computing the Standard Deviation
24
Uncertainty on the Mean
25
Uncertainty on the Mean
26
Confidence Levels
27
Back to the Whale!
28
Back to the Whale!
The thing that maBers is the TOTAL number of points that are thrown!
It does not maBer if they are in 100, 10 or even 1 experiment – it is the number of points.
What if we treated each single randomly-­‐‑thrown point as a single measurement?
29
Back to the Whale!
30
Back to the Whale!
31
More on Character Strings
32
Arrays of Characters
*
Single characters are nice but …many in succession can be more meaningful to us.
Array of characters are called a string.
33
Arrays and Pointers
34
String Utilities: strlen
What is going on?!
35
Character Encoding
•  American Standard Code for Information Interchange (ASCII):
–  ~first new widely adopted code for laBer communication since Morse code
–  Ea. character represented by 8 bits
–  128 characters supported
• 
• 
• 
• 
26x2 leBers of the english alphabet
10 single-­‐‑digit numerals
33 symbols, incl. “space”
33 control characters
–  Facilitates communication between terminal and computer
–  Other standards are used today (eg., UTF-­‐‑8, others) but the spirit is the same
36
String Termination and Arrays
37
String Utilities: strcmp
38
More on Arrays and Pointers
39
Recall…
40
Incrementing a Pointer
41
Array Names ARE Pointers Already!
42
Array Names ARE Pointers Already -­‐‑-­‐‑ proof
43
Pointer Arithmetic
44
Storage of 2D Arrays
45
Memory and 2D Arrays
46
2D Arrays and Pointer Arithmetic: I
47
2D Arrays and Pointer Arithmetic: II
48
2D Arrays and Pointer Arithmetic: III
49
Using 1D Notation for 2D Arrays
50
All Arrays Are Linear in Memory
51
Example: Structs and Functions
52
Example: The Gravity Problem
53
Example: The Gravity Problem
54
Example: The Gravity Problem
55
Example: The Gravity Problem
56
Example: The Gravity Problem
57
Example: The Gravity Problem
58
Example: The Gravity Problem
You will also need to write functions for:
-­‐‑ calculating the distance between objects
-­‐‑ the difference between objects’ positions, using vectors
-­‐‑ calculating the total force on each object
-­‐‑ calculating the center of mass for the array of objects
59
We’ll pick up from there next time.
Have a good rest of the week and see you at labs on Thursday!
60
Download