Computational Methods in Physics 1 Important Questions Who knows computer programming? Which language(s)? How much experience? Who does *not* have access to a laptop? Have it with you today? If not, partner up What operating system is on it? Which plotting software do you use? How many of you got both my e-mails? Next, let us all go over the syllabus… 2 3 Steps to Projects in This Course Something you use write your code Something to compile your code into an executable “Computer program” can refer to either your raw source code or the executable In many cases, you want to make a graph of your results: something vs. something or a histogram, et al. Creating a simple plot of your data Occasionally a table or just one number 3 Word Processors Linux/Unix: emacs, vi/vim, pico, nano http://www.gnu.org/software/emacs/tour/ http://www.openvim.com https://www.cs.colostate.edu/helpdocs/pico.html http://www.howtogeek.com/howto/42980/the-beginnersguide-to-nano-the-linux-command-line-text-editor/ Mac: Xcode graphically or same as above in Terminal (Unix) https://developer.apple.com/xcode/ (free!) Windows: Microsoft Visual C++, Borland C++, OR install a Unix shell wrapper like Cygwin, VirtualBox, or Gow and use Unix https://cygwin.com/install.html (free!) 4 Compilers (Your Biggest Hurdle?) Linux/Unix: can use gcc or g++ natively (*best* option is a rare laptop OS) Mac: Xcode graphically or clang or gcc or g++ in Terminal (very close 2nd place) https://developer.apple.com/xcode/ (free!!) Windows: Microsoft Visual C++, Borland C++, OR install a Unix shell wrapper like Cygwin, VirtualBox, or Gow and use gcc or g++ (Windows is most work…) https://cygwin.com/install.html (free!!) 5 Plotters Excel of course (not very good) for PC, Mac gnuplot (free!) for any operating system http://www.gnuplot.info Warning -- command-line-based, not GUI KaleidaGraph for PC, Mac (student license) http://www.synergy.com/wordpress_650164087/ Excel on steroids (custom functions for example) A free, 30-day (?) student demo/trial available ROOT (for Windows you must get https://root.cern.ch (partially GUI) Cygwin...) 6 Help Getting Set Up For users of Windows machines (PCs): Code Blocks (word processing AND compiling in one; Sean can help you)-http://www.codeblocks.org/ Install https://www3.ntu.edu.sg/home/ehchua/ programming/howto/CodeBlocks_HowTo.html Another option: FREE latest version of MS Visual C++ potentially, https:// www.dreamspark.com/Support/FAQ/ 7 Unix and emacs Commands Quick reference “Cheat sheets” for both Linux and Mac (Terminal) unix https://ubuntudanmark.dk/filer/ fwunixref.pdf emacs https://www.gnu.org/software/emacs/ refcards/pdf/refcard.pdf 8 Your Very First Program Live demo on my machine, Apple laptop 10.8.5 (old version of OS X) I will use emacs, gcc, and Excel 9 Resources for Learning C & C++ http://www.sphoorthyengg.com/wp- content/uploads/2015/07/Teach-YourselfC-in-24-Hours-2nd-Edition.pdf http://www.angelfire.com/art2/ebooks/ teachyourselfcplusplusin21days.pdf Just use Google for even more help! Including searching the exact phrase of any error messages you get as you are working 10 Time Permitting http://plotdigitizer.sourceforge.net (all systems) Automatic version 11 Your First Homework Assignment Write a program about special relativity You input a velocity, a time, a length, and a mass The program spits out beta, gamma, the time dilation amount (seconds per second), the new, contracted length, and the new larger mass, plus the kinetic and the total energies Will be due on Friday Jan. 29 at 11:59 p.m. No extensions. You would get too far behind Bonus: Handle faster than light situations 12 Note: changing rooms to 225 13 Homework #2 Study the random number generator in C++ vs. another one I will provide you Make histograms of value frequencies (0 to 0.1, 0.1 to 0.2, etc.) and the digit frequencies (1st through 6th decimal places) Which generator (if either) is the better one? BONUS: Make 3D plot of random triplets (Excel can do this) and re-judge which better 14 More Links of Use How to make a histogram https://support.microsoft.com/en-us/kb/214269 (for multiple different versions of Excel) http://www.life.illinois.edu/biochem/455/Lab %20exercises/2Photometry/KaleidaGraph %20Manual.pdf (search the word histogram; you can also just take note of example in class) http://gnuplot.sourceforge.net/demo/histograms.html ftp://root.cern.ch/root/doc/ROOTUsersGuideHTML/ ch03s08.html https://en.wikipedia.org/wiki/ Random_number_generation 15 Homework #3 Create a Monte Carlo simulation of electrons traversing the element xenon, used as a detector Make the density a user input, but your default can be 3 grams per cm^3 (liquid xenon). Energy also an input Use the “total stopping power” tables from this website: http://physics.nist.gov/PhysRefData/Star/Text/ESTAR.html but convert values into MeV per cm OR spline the results Optimize the step size in distance until you get the right answer on average for the total track length (using the CSDA range from site above, converting into length units using the default density above) Allow for 15% variation on each mean dE/dx from the table as a function of the energy (Gaussian) Have your code do argon and water as well (also detectors) Output is histogram of track lengths for >=10,000 elec’s For several example energies: 1,2,5,10,20,50,100,200,500,1000 keV BONUS: Imagine electrons decay. New result=? Also, separate the radiative and collisional dE/dx losses 16 Links for HW #4,+ Plot Digitization http://tutorial.math.lamar.edu/Classes/DE/ EulersMethod.aspx Study the many examples on this webpage! For later/future: Java-based Plot Digitizer for Windows, Apple Mac, and Linux / Unix (at least some flavors) -http://plotdigitizer.sourceforge.net/ If for any reason this fails to work for your machine, Googling “digitizing plots” as an exact phrase should provide alternative programs 17 Homework #4, due Friday, Feb. 19 Solve the pendulum equation for both the small angle approximation and not, under conditions of damping and (sinusoid) driving too Damped: nothing, under, critically, over Driven: damped with all four cases above Angles: 15, 30, 45, 60, 90, 120, 180 deg. That’s 112 plots! I don’t want that many: combine things. Don’t plot for sake of plots. In email: analyze, draw conclusions on behavior! First things first: you have to make sure h is small enough that your program is accurate 2 ways to do this: analytical solutions or asymptoting EC: Euler vs. Euler-Cromer method. Optimize! 18 web links for HW # 4 Full analytical solution with sin(theta) which you can compare to: http://sbfisica.org.br/rbef/pdf/070707.pdf Damped oscillation http://farside.ph.utexas.edu/teaching/315/Waves/node10.html Different types: http://homepages.abdn.ac.uk/nph120/vpl/pendulum/ Equations.html http://hyperphysics.phy-astr.gsu.edu/hbase/pend.html Driven aka forced http://hyperphysics.phy-astr.gsu.edu/hbase/oscdr.html 19 If you ever have problems with getting random numbers You can always get them from https://www.random.org (best on web) 20 Homework #5: Cosmology, GR Compare Euler (or Euler-Cromer) to the “RK4” approach to differential equations that you’ll code up yourselves, for the ΛCDM model Use Runge-Kutta (RK4) exclusively for the rest of HW5 Determine in default scenario age of the universe plus the dark-energy inflection point (the correct answers are 13.82 billion years old and a = 0.57). Get it right Plot first and second derivatives of the scale factor a Plot all the omegas as a function of time, z, and scale factor Plot a(t) with z and “absolute” size for cases of Phantom dark energy (Big Rip, and find time scale) Decreasing dark energy (Big Crunch, and find out when) Matter-dominated cosmos: flat, open, closed (combined) Verify code working for 4 simple cases; show Bonus: *early* universe including inflation done well Was going to do adaptive step size but you’ll need it 21 What you need Cosmological parameter values (latest, final): http://arxiv.org/pdf/1502.01589v2.pdf Hyperphysics discussion of Friedmann equation with Hubble parameter: http://hyperphysics.phy-astr.gsu.edu/hbase/astro/fried.html Wikipedia Scale factor with redshift definition: https://en.wikipedia.org/wiki/Scale_factor_%28cosmology%29 Equation of state in cosmology: https://en.wikipedia.org/wiki/Equation_of_state_%28cosmology%29 How to code up the Runge-Kutta formulae: https://en.wikipedia.org/wiki/Runge%E2%80%93Kutta_methods For your further edification and knowledge http://www-com.physik.hu-berlin.de/~fjeger/Cosmolect1-7.pdf (Friedmann equations hard-core full solutions and explanations) Cutting edge research on scale factor (also, gives you the inflection point) http://www.ringermacher.com/images/stories/downloadable_pdfs/ aj_148_5_94o_scalefactorplot.pdf 22 Example Plot 23 Next topic BBN 24