Integrating html forms, multipart & web enabled content management with SAP Process Integration
Physics 2660: Fundamentals of Scientific...
Transcript of Physics 2660: Fundamentals of Scientific...
![Page 1: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/1.jpg)
Physics 2660: Fundamentals of Scientific Computing
Lecture 14 Instructor: Prof. Chris Neu ([email protected])
![Page 2: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/2.jpg)
Notes• Last lecture!• Upcoming homeworks:
– HW13 due Wednesday 2 May at 11:59pm– HW14 due Wednesday 2 May at 11:59pm – a course evaluation
• alt3zq Tuma, Andrew• ces2fa Stephens, Catherine• ecj4wb Jones, Ethan• jls6gw Selby, Jonathan• raj9qv Jennings, Robert• rm3xw Mora, Raymundo• sam3bf Murri, Samuel• vh2[ Huang, Vicki
• Solutions to all labs and hw’s are in the process of being posted …sorry for recent delays
2
Why have you not completed
this?
![Page 3: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/3.jpg)
Reminder• Grading of HWs almost caught up!
• Register for piazza! – Only 50 out of 60 so far– All questions about final exam will only be answered via piazza
• Office hours: all held in our computer lab, room 022-C of this bldg
– Me: After lecture 3:30-4:30 every Tuesday – TAs:
• Mondays: 3-5pm and 6-8pm• Wednesdays: 5-9pm
3
![Page 4: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/4.jpg)
Notes
• Final exam is coming:
– Take-home projects• 3 problems
– Like a more involved, longer multipart homework assignment– Assigned last week of semester on Tuesday 2 May
• will be posted by 3:30pm today
– Due Thursday May 10:• electronic copies by 9:00am • hard-copies must be submiied Thursday 10 May between 08:00-10:00
in room 022-C, our computer lab….or earlier by personal arrangement with me.
4
![Page 5: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/5.jpg)
Notes• Final exam is coming:
– Take-home projects• 3 problems
– Like a more involved, longer multipart homework assignment– Assigned last week of semester on Tuesday 1 May– Due Thursday May 10:
• electronic copies by 9:00am • hard-copies must be submiied Thursday 10 May between 08:00-10:00
in room 022-C, our computer lab….or earlier by personal arrangement with me.
5
Due Thursday May 10, electronically by 9:00am and hard copies between 08:00 and 10:00 in 022-C
![Page 6: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/6.jpg)
Review and Outline• Last time:
– Comparing data to a prediction
• Today:– Tuning a model to best represent the data– More tests of compatibility
6
![Page 7: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/7.jpg)
Summary so far…• Compare some data to a model, account
for uncertainties• Calculate reduced χ2
• If good agreement– should see different points sometimes
high/low– if k large, reduced χ2 ~ 1.0
7
![Page 8: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/8.jpg)
Tuning a Model to Best Match Some Data
8
![Page 9: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/9.jpg)
Tuning a Model
9
![Page 10: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/10.jpg)
Tuning a Model
10
Can we figure out which model – which values of a and b – the data most
favors?
![Page 11: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/11.jpg)
Probability of Some Observation
11
![Page 12: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/12.jpg)
Probability of Multiple Observations
12
The probability of the collection of data – 3 observations – is just the product of the three individual probabilities
![Page 13: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/13.jpg)
Probability of Multiple Observations
13
The probability of the collection of data – k observations – is just the product of the k individual probabilities
![Page 14: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/14.jpg)
P: The χ2 Likelihood Function
14
![Page 15: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/15.jpg)
Minimizing the χ2
15
![Page 16: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/16.jpg)
Minimizing the χ2
16
![Page 17: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/17.jpg)
Minimizing the χ2
17
![Page 18: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/18.jpg)
Minimizing the χ2
18
![Page 19: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/19.jpg)
More Powerful Application: An Arbitrary Theory
19
![Page 20: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/20.jpg)
FiPing with Gnuplot
20
P(x;a,b,c) = 12πc2
e−(ax−b)2
2c2
![Page 21: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/21.jpg)
Assessing the Quality of a Fit
21
![Page 22: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/22.jpg)
Assessing the Quality of a Fit
22
Consequence: If the number of fit parameters is greater than or equal to the number of data points the χ2 is undefined.
Trivial case
![Page 23: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/23.jpg)
Assessing the Quality of a Fit
23
P(x;a,b,c) = 12πc2
e−(ax−b)2
2c2
![Page 24: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/24.jpg)
Assessing the Quality of a Fit
24
So there is a 90% probability that, if the data were consistent with the model (here a Gaussian-like thing with 3 params), the data would have a higher chi2 value. Too good to be true? Why are the points so close to the model? Did the fit procedure cheat in some way? Are the uncertainties over-estimated?
![Page 25: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/25.jpg)
FiPing is Done EVERYWHERE
25
![Page 26: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/26.jpg)
Aside: Gravitational Waves
hips://www.nytimes.com/video/science/100000004200661/what-are-gravitational-waves-ligo-black-holes.html
26
![Page 27: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/27.jpg)
Curve FiPing
27
![Page 28: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/28.jpg)
Deviations from the Model
28
![Page 29: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/29.jpg)
The Pull Distribution
29
![Page 30: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/30.jpg)
Bias – Is the Prediction In Accord with the Data?
30
![Page 31: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/31.jpg)
Clusters of Data Above/Below
31
![Page 32: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/32.jpg)
Clusters of Data Above/Below
32
![Page 33: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/33.jpg)
What Have We Learned
33
![Page 34: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/34.jpg)
What Have We Learned
• We learned a whole lot this semester!
• Computers• Programming Language• C
– For many of you this was your first entrypoint into the use of a computer as a tool for data analysis
– Many of you started from very liile experience– Generated a set of tools you can rely on in the future for a whole
host of problems in your chosen field, science or otherwise
• Data Presentation• Data Analysis and Assessment• Some Statistics – some very important statistical concepts
34
![Page 35: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/35.jpg)
C vs. C++
35
![Page 36: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/36.jpg)
C vs. C++
0 C is much simpler for beginners than C++ but far less powerful1 C++ can run most C code but not the other way round!2 Functions are the building blocks of C whereas objects are the building
blocks of C++3 In C, the program is formulated step-by-step but in C++ the base
elements are formulated first and then linked together in larger systems4 In C++, functions can be overloaded, but not in C5 C++ has a much larger library than C6 C++ allows user to create classes (similar to structures) to which methods
and functions can be assigned and within which they can operate7 In C++ you can add your own types and objects inheriting properties and
routines from other classes. This allows you to add more features to your own classes and the standard library as well
8 C++ uses “Namespace”, which is very useful in avoiding multiple declarations
9 C++ has built in exception support
36
![Page 37: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/37.jpg)
What is next? What more could you learn?
37
![Page 38: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/38.jpg)
What Could You Try Next?
• You now have a firm foundation in C. What could be next?– Another powerful language used in scientific seiings, such as python
– Some scripting language: Bash scripts, perl, etc., to automate many types of text and data manipulation, etc.
– Object Oriented features of C++, Java, C#, etc: Powerful (and sometimes dangerous) design tools!
– A physics/math library, like ROOT, R, CERNLIB, CLHEP, LINPACK, GSL, etc…
– Overview of analytical techniques in classes like PHYS 5630/40(Computational Physics 1/2)
– Get a job w/ a research group, apply your skills, and learn more!38
![Page 39: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/39.jpg)
What Could You Try Next?• Worldwide distributed computing grids
– hip://www.opensciencegrid.org
• UVa’s High-Performance Computing cluster:– hip://arcs.virginia.edu/rivanna
• Massively Parallel Processing
• Real time controls– automation– robotics– eg. autonomous vehicles, ...
• Quantum Computing
– hip://www.sciencedaily.com/news/computers_math/quantum_computers/
39
![Page 40: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/40.jpg)
Grid Computing
• We have operated this semester in the following fashion:– sit down at some personal or lab computer– use this as a portal to a cluster of computers, galileo, featuring
• large amounts of storage• many nodes allowing multiple users to exploit the same resource
simultaneously
• Some drawbacks:– galileo can get slow – bogged down by other users. What do we do in
these cases? Other clusters available to us – and where?– /home is a shared resource and has goien full a few times,
preventing work – not an infinite space resource– interactive jobs are tempermental: what if you needed to run 1000s of
jobs – need 1000s of terminal sessions?– what if I needed lots of data to be stored but only needed it very
occasionally?
40
![Page 41: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/41.jpg)
TIER-0 CERN
• AT LHC, need to store, analyze and distribute 15 Petabytes of data per year (1% of digital information produced in the world)• All data is processed at CERN and backed up on tape• But CERN provides only ~20% total compute capacity
![Page 42: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/42.jpg)
Tier-1 sites
• Sufficient storage capacity for large fraction of the data
• Large scale reprocessing
• Distribution to Tier-2 sites
• 11 sites for all LHC experiments
Distributes data to ~30 Tier-3 sites
Only store data specific to given task
Distributed Computing
![Page 43: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/43.jpg)
Worldwide LHC Computing Grid
• LHC Grid gives access to more than 7000 scientists in more than 30 countries• World’s largest computer grid connecting more than 200,000 CPUs at universities and research institutes • Runs over 1,000,000 tasks every day
![Page 44: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/44.jpg)
TIER-0/1s
TIER-3sTIER-2s
• CMS observes more than 400 unique users submitting jobs per week
• Capacity run up to 200,000 jobs per day on the Grid
CMS Data Processing on the Grid
![Page 45: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/45.jpg)
CERN Computing
45
hips://www.youtube.com/watch?v=jDC3-QSiLB4
![Page 46: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/46.jpg)
The Final Exam
46
![Page 47: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/47.jpg)
Notes
• Final exam:– Take-home projects– Like a more involved, longer multipart homework assignment– Due Thursday May 10:
• electronic copies by 9:00am • hard-copies must be submiied Thursday 10 May between 08:00-10:00
in room 022-C, our computer lab…or earlier by personal arrangement with me
47
Due Thursday May 10, electronically by 9:00am and hard copies between 08:00 and 10:00 in 022-C
![Page 48: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/48.jpg)
Some Guidelines for Final• All students must work individually, no collaboration.
• You can ask questions via email or chat or on Piazza but the insight will be limited to conceptual assistance or clarifications.
• TA hours will be held on Thursday 3 May xxxxx and Friday 4 May yyyyyyy. • These will not be standard lab-TA hours: students can come individually to ask questions to
the TA but then you will go and work on the questions on your own. Conceptual and clarifications on content only, no assistance in determining the solutions. No examination of code will be allowed.
• Pose all questions before Monday 8 May 8pm.
• Allowed resources: class texts, class notes, class web page (including solutions), and web links provided directly from the class web pages. You can use functions available in the standard C libraries we have used in class/lab/homeworks.
• Email/chat/Piazza any requests for problem clarifications by Monday, May 7, 8pm. This may be followed by a single FAQ email covering appropriate questions. Watch for this email. After this, there will be no more discussion during the exam.
48
![Page 49: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/49.jpg)
Some Guidelines for Final• All students must work individually, no collaboration.
• You can ask questions via email or chat or on Piazza but the insight will be limited to conceptual assistance or clarifications.
• TA hours will be held on Thursday 3 May xxxxx and Friday 4 May yyyyyyy. • These will not be standard lab-TA hours: students can come individually to ask questions to
the TA but then you will go and work on the questions on your own. Conceptual and clarifications on content only, no assistance in determining the solutions. No examination of code will be allowed.
• Pose all questions before Monday 8 May 8pm.
• Allowed resources: class texts, class notes, class web page (including solutions), and web links provided directly from the class web pages. You can use functions available in the standard C libraries we have used in class/lab/homeworks.
• Email/chat/Piazza any requests for problem clarifications by Monday, May 7, 8pm. This may be followed by a single FAQ email covering appropriate questions. Watch for this email. After this, there will be no more discussion during the exam.
49
Start your work early!
There is an early deadline on questions to encourage you to start working on it – at least
thinking about it – right away.
![Page 50: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/50.jpg)
The End!
50
![Page 51: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/51.jpg)
More Testing of Compatibility
51
![Page 52: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/52.jpg)
Cumulative Distribution Function
52
![Page 53: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/53.jpg)
Cumulative Distribution Function
53
![Page 54: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/54.jpg)
Example: PDF and CDF
54
![Page 55: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/55.jpg)
Empirical Distribution Function
55
![Page 56: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/56.jpg)
Empirical Distribution Function• The ECDF is made from
“unbinned” data– not from a binned
histogram– use raw measured values
• Do this by:1. say you have N values, xi2. sort the N values in order
of increasing value3. plot each of the N values
with xi on the x-axis and i/N on the y-axis
• Now, compare model’s CDF and the data’s ECDF…
56
![Page 57: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/57.jpg)
Testing Compatibility
57
![Page 58: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/58.jpg)
Testing Compatibility
58
![Page 59: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/59.jpg)
Manipulating Binary Data
59
![Page 60: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/60.jpg)
Bits and Bytes
60
![Page 61: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/61.jpg)
Flipping Bits
61
![Page 62: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/62.jpg)
Bitwise Operators
62
![Page 63: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/63.jpg)
Bitwise AND
63
![Page 64: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/64.jpg)
Bitwise OR
64
![Page 65: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/65.jpg)
Bitwise Left Shift
65
![Page 66: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/66.jpg)
Bitwise Right Shift
66
![Page 67: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/67.jpg)
Bitwise Inverse
67
![Page 68: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/68.jpg)
Bitwise Shift on Constants
68
![Page 69: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/69.jpg)
Testing and SePing Bits
69
( )
![Page 70: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/70.jpg)
Testing and SePing Bits: Masks
70
( )“Mask”
![Page 71: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/71.jpg)
Testing and SePing Bits: Masks
71
( )
![Page 72: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/72.jpg)
Clearing a Bit
72
![Page 73: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/73.jpg)
Manipulating Binary Data: Example
73
![Page 74: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/74.jpg)
Hexadecimal Representation
74
![Page 75: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/75.jpg)
Hexadecimal Representation
75
![Page 76: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/76.jpg)
Hexadecimal Representation
76
![Page 77: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/77.jpg)
Data Storage
77
![Page 78: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/78.jpg)
Example
78
![Page 79: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/79.jpg)
Example
79
![Page 80: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/80.jpg)
Example
80
![Page 81: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/81.jpg)
The Exclusive Or (XOR) Operation
81
![Page 82: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/82.jpg)
The Exclusive Or (XOR) Operation
82
![Page 83: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/83.jpg)
XOR Application
83
![Page 84: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/84.jpg)
XOR Application
84
1 01 1 0 0 0 0
1 010 1 010
010 1 0100
Say you want to send this plain-text “message”:
You and the recipient have a copy of some pre-determined “key”
key ^ message = encrypted message:
And you send this encrypted message to your intended recipient….
^ ^ ^ ^ ^ ^ ^ ^
![Page 85: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/85.jpg)
XOR Application
85
1 01 1 0 0 0 0
1 010 1 010
010 1 0100Your recipient receives your encrypted message:
and applies the key:
^ ^ ^ ^ ^ ^ ^ ^
and gets a copy of the plain-text message. Successful secret communication!
![Page 86: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/86.jpg)
XOR Application
86
1 01 1 0 0 0 0
1 010 1 010
010 1 0100
One flaw: if someone intercepts both the coded and plain message:
^ ^ ^ ^ ^ ^ ^ ^
They can derive the key!This a problem if the sender/recipient ever re-use a key.
![Page 87: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/87.jpg)
Review: Bitwise Operators
87
![Page 88: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/88.jpg)
Review: Testing and SePing Bits
88
![Page 89: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/89.jpg)
Storage of Binary Data
89
![Page 90: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/90.jpg)
The fputc Function
90
![Page 91: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/91.jpg)
The fputc Function
91
1 byte
1 byte4 bytes
4 bytes = 4 chars
![Page 92: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/92.jpg)
Comparison of ASCII and Binary Storage
92
4 bytes = 4 chars
10 bytes = 10 chars
![Page 93: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/93.jpg)
More on Characters
93
![Page 94: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/94.jpg)
Signed v. Unsigned Vars
94
![Page 95: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/95.jpg)
Signed vs. Unsigned Vars
• Example:– Say
a = 1d = 00000001b and b = -1d = 10000001b
95
![Page 96: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/96.jpg)
Signed vs. Unsigned Vars
• Example:– Say
a = 1d = 00000001b and b = -1d = 10000001b
– Thena+b = 1d + (-1d) = ?
96
![Page 97: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/97.jpg)
Signed vs. Unsigned Vars
• Example:– Say
a = 1d = 00000001b and b = -1d = 10000001b
– Thena+b = 1d + (-1d) = 00000001b + 10000001b
97
![Page 98: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/98.jpg)
Signed vs. Unsigned Vars
• Example:– Say
a = 1d = 00000001b and b = -1d = 10000001b
– Thena+b = 1d + (-1d) = 00000001b + 10000001b
= 10000010b
98
![Page 99: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/99.jpg)
Signed vs. Unsigned Vars
• Example:– Say
a = 1d = 00000001b and b = -1d = 10000001b
– Thena+b = 1d + (-1d) = 00000001b + 10000001b
= 10000010b = -2d
99
![Page 100: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/100.jpg)
Signed vs. Unsigned Vars
• Example:– Say
a = 1d = 00000001b and b = -1d = 10000001b
– Thena+b = 1d + (-1d) = 00000001b + 10000001b
= 10000010b = -2d
– That looks wrong to me….
100
![Page 101: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/101.jpg)
Trick: Two’s Complement Notation
101
![Page 102: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/102.jpg)
Trick: Two’s Complement Notation
• To form the two’s complement of any negative number:1. Convert |number| to N-bit representation2. Subtract |number| from 2N
3. Add one to the number
• Examples, 8-bit negative numbers:– If a = -1 then |-1| in 8-bit representation is 00000001
a2c = (11111111 – 00000001) + 00000001 = 11111111
– If a = -5 thena2c = 11111111 – 00000101 + 00000001 = 11111011
102
![Page 103: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/103.jpg)
Signed vs. Unsigned Vars
• Example:– Say
a = 1d = 00000001b and b = -1d = 11111111b (using 2’s complement)
– Thena+b = 1d + (-1d) = 00000001b + 11111111b
= 00000000b = 0d
– That’s beier!
103
![Page 104: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/104.jpg)
More On Binary Data Output
104
![Page 105: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/105.jpg)
More On Binary Data Output
105
![Page 106: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/106.jpg)
More On Binary Data Output
106
![Page 107: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/107.jpg)
More On Binary Data Input
107
![Page 108: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/108.jpg)
More On Binary Data Output
108
![Page 109: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/109.jpg)
More On Binary Data Output
109
![Page 110: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/110.jpg)
More On Binary Data Input
110
![Page 111: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/111.jpg)
More On Binary Data Input
111
![Page 112: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/112.jpg)
fopen: File I/O Modes
112
![Page 113: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/113.jpg)
fopen, fwrite and fread
113
![Page 114: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/114.jpg)
rewind
114
![Page 115: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/115.jpg)
fseek
115
![Page 116: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/116.jpg)
fseek
116
![Page 117: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/117.jpg)
ftell
117
![Page 118: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/118.jpg)
feof
118
![Page 119: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/119.jpg)
Writing Binary for Arbitrary Structs
119
![Page 120: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/120.jpg)
Filesize Comparison of Binary v. ASCII Formats
120
![Page 121: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/121.jpg)
Solving Differential Equations
121
![Page 122: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/122.jpg)
A Trajectory
122
![Page 123: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/123.jpg)
A Trajectory
123
We don’t know v(t) but we know v(t0) and the time derivative.We seek v(t).
![Page 124: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/124.jpg)
A Trajectory
124one step:
result:
not very accurate!!!All we know is the derivative of v! Here v=y and t=x.
![Page 125: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/125.jpg)
A BePer Method
125
![Page 126: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/126.jpg)
A BePer Method
126
All we know is the derivative!
![Page 127: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/127.jpg)
A BePer Method
127
All we know is the derivative!
![Page 128: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/128.jpg)
A BePer Method
128
![Page 129: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/129.jpg)
A BePer Method
129
![Page 130: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/130.jpg)
Passing Pointers to Structures
130
![Page 131: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/131.jpg)
Unintended Consequences
131
![Page 132: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/132.jpg)
Unintended Consequences
132
Warning tells you to rewrite this!
![Page 133: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/133.jpg)
Optional Function Arguments
133
![Page 134: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/134.jpg)
Default Argument Values in Functions: C++
134
![Page 135: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/135.jpg)
Default Argument Values in Functions: C++
135
![Page 136: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/136.jpg)
Default Argument Values in Functions: C++
136
Example:
![Page 137: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/137.jpg)
Searching in Arrays
137
![Page 138: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/138.jpg)
Searching for a Particular Item
138
![Page 139: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/139.jpg)
Method: Linear Search
139
![Page 140: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/140.jpg)
Method: Binary Search
140
![Page 141: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/141.jpg)
Method: Binary Search
141
![Page 142: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/142.jpg)
Method: Binary Search
142
![Page 143: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/143.jpg)
Method: Binary Search
143
![Page 144: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/144.jpg)
Method: Binary Search
144
![Page 145: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/145.jpg)
Search Speed: Linear Method
145
![Page 146: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/146.jpg)
Search Speed: Binary Method
146
![Page 147: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/147.jpg)
Sorting
147
![Page 148: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/148.jpg)
Sorting Methods
148
![Page 149: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/149.jpg)
Method: Selection Sort
149
![Page 150: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/150.jpg)
Method: Selection Sort
150
![Page 151: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/151.jpg)
Method: Selection Sort
151
![Page 152: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/152.jpg)
Method: Quicksort
152
![Page 153: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/153.jpg)
Method: Quicksort
153
![Page 154: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/154.jpg)
Method: Quicksort
154
![Page 155: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/155.jpg)
Method: Quicksort
155
![Page 156: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/156.jpg)
Method: Quicksort
156
![Page 157: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/157.jpg)
Method: Quicksort
157
![Page 158: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/158.jpg)
Linked Lists
158
![Page 159: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/159.jpg)
Reminder About Arrays
159
![Page 160: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/160.jpg)
Linked Lists: A Special Data Structure
160
![Page 161: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/161.jpg)
Linked Lists: A Special Data Structure
161
mallccallocrealloc
![Page 162: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/162.jpg)
Linked Lists: A Special Data Structure
162
![Page 163: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/163.jpg)
Linked Lists: A Special Data Structure
163
![Page 164: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/164.jpg)
Linked Lists: A Special Data Structure
164
If these were stored in an array, this could be a huge job.
![Page 165: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/165.jpg)
Linked Lists: A Special Data Structure
165
If these were stored in an array, this could be a huge job.
![Page 166: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/166.jpg)
Linked Lists: A Special Data Structure
166
![Page 167: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/167.jpg)
Linked Lists: A Special Data Structure
167
![Page 168: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/168.jpg)
Linked Lists: A Special Data Structure
168
![Page 169: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/169.jpg)
Linked Lists: A Special Data Structure
169
![Page 170: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/170.jpg)
Linked Lists: A Special Data Structure
170
![Page 171: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/171.jpg)
171
So What?
These things can actually be very useful!
![Page 172: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/172.jpg)
Linked Lists Example: FIFOs
172
![Page 173: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/173.jpg)
Linked Lists: Summary
173
![Page 174: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/174.jpg)
Dynamic Memory Allocation:
Memory is typically allocated by the compiler…but what if we need to change the requirements on the fly while executing a
program?
(We did not go through this unit in lecture.)
174
![Page 175: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/175.jpg)
The Stack
175
![Page 176: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/176.jpg)
The Stack
• Each running program has its own stack
• As functions are called, the variables local to that function are loaded to the top of the stack. When the function is complete that memory is freed for other uses
• One can use up all the available memory in a stack:“stack overflow” error
176
![Page 177: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/177.jpg)
The Heap
177
![Page 178: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/178.jpg)
The malloc function
178
![Page 179: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/179.jpg)
The calloc function
179
![Page 180: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/180.jpg)
The free function
180
![Page 181: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/181.jpg)
The realloc function
181
![Page 182: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/182.jpg)
Memory Allocation Failure
182
![Page 183: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/183.jpg)
Dynamic Memory Allocation: Example I
183
![Page 184: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/184.jpg)
Dynamic Memory Allocation: Example II
184
![Page 185: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/185.jpg)
Dynamic Memory Allocation: Example II
185
![Page 186: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/186.jpg)
Optional Function Arguments
186
![Page 187: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/187.jpg)
Default Argument Values in Functions: C++
187
![Page 188: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/188.jpg)
Default Argument Values in Functions: C++
188
![Page 189: Physics 2660: Fundamentals of Scientific Computingfaculty.virginia.edu/comp-phys/phys2660/html/notes/...– Like a more involved, longer multipart homework assignment – Assigned](https://reader034.fdocuments.us/reader034/viewer/2022050110/5f481edcb15e36466c757e7c/html5/thumbnails/189.jpg)
Default Argument Values in Functions: C++
189
Example: