### unknown title

"... • Comparing floating point numbers. We saw in Session 3 the perils of comparing floats or doubles using if (x1 = = x2) { }. What we really want to do is check whether they are close enough to each other, which might mean within a factor of 2 of the machine precision (or something greater ..."

Abstract
- Add to MetaCart

• Comparing floating point numbers. We saw in Session 3 the perils of comparing floats or doubles using if (x1 = = x2) { <something>}. What we really want to do is check whether they are close enough to each other, which might mean within a factor of 2 of the machine precision (or something greater). So we define epsilon to be 2ǫm, and compare the relative difference: if (fabs((x1-x2)/(x1+x2)) < epsilon) { <something>}. Note the use of fabs, because we don’t know the signs of x1 and x2 or which is larger. • Number-one cause of “syntax errors”. If the compiler reports a “syntax error ” at a particular line number, check first that you haven’t omitted a semicolon at the end of the previous line. • Distribution of round-off errors. In order to discuss the accumulation of round-off errors, we’ve assumed that they are distributed randomly. More precisely, we’ve assumed that if we have a series of N operations with numbers z having round-off errors ǫ given by zc = z(1 + ǫ) where |ǫ | ≤ ǫm, (4.1) then the ǫ’s are symmetrically distributed about ǫ = 0 and are uncorrelated. But we could imagine different distributions for ǫ/ǫm, for example, either of the two pictured here:-2-1 0 1 2-2-1 0 1 2

### unknown title

"... Here are some brief comments on various things encountered in Session 2: • Problem 1 in Assignment #1 will be to compare summing 1/n from 1 to N to summing it from N to 1. When trying to understand what happens, keep in mind the simple example ..."

Abstract
- Add to MetaCart

Here are some brief comments on various things encountered in Session 2: • Problem 1 in Assignment #1 will be to compare summing 1/n from 1 to N to summing it from N to 1. When trying to understand what happens, keep in mind the simple example

### a. Follow-up to Richardson Extrapolation

"... Let’s consider a hypothetical situation. Suppose I had a function called f that calculated a quantity of interest (e.g., an integral, a derivative, a special function) given a parameter h (which could be a mesh spacing or something else entirely). Suppose also that I knew that the error in f(h) was ..."

Abstract
- Add to MetaCart

Let’s consider a hypothetical situation. Suppose I had a function called f that calculated a quantity of interest (e.g., an integral, a derivative, a special function) given a parameter h (which could be a mesh spacing or something else entirely). Suppose also that I knew that the error in f(h) was a constant times h n (plus higher-order corrections). How can I use Richardson extrapolation to eliminate the h n error without knowing anything else? Answer: simply calculate at two different h values and use the results to eliminate the h n error. For example, calculate at h and h/2 and call a1 the result of f(h) and a2 the result of f(h/2). Then a1 = exact + αh n + · · · a2 = exact + α(h/2) n + · · · = exact + 2 −n αh n We can easily eliminate the h n term and solve for “exact”: exact = 2n a2 − a1 2 n − 1 The updated version of extrap diff uses this with n = 2; i.e., the improved derivative is calculated as: ( 4.*central_diff(h/2.)- central_diff(h))/3. since the central diff error is h 2. You can do likewise using extrap diff to eliminate the h 4 error! b. Follow-up to Session 7: Damping Let’s review the harmonic oscillator (the p = 2 case from Session 6) and the mathematical conditions for underdamped, critically damped, and overdamped motion. At the same time, you should look at the handout showing phase-space plots for these cases. We start with the differential equation for an undriven harmonic oscillator with a damping force proportional to the velocity: or F = Ma = ⇒ d2x dt2 = −ω2 b dx

### unknown title

, 2007

"... “tricks ” or shortcuts to make them more compact. In general, I don’t recommend coding this way (so these codes should be rewritten!). For example, the choice of energy units is exploited so that energies are integers and therefore can be used as array indices. But if we added an external field, thi ..."

Abstract
- Add to MetaCart

“tricks ” or shortcuts to make them more compact. In general, I don’t recommend coding this way (so these codes should be rewritten!). For example, the choice of energy units is exploited so that energies are integers and therefore can be used as array indices. But if we added an external field, this would no longer work, so a different approach should be implemented. Another example is the next configuration function, which uses recursion (i.e., the function calls itself) to count upward in binary. This is clever, but really hard to decipher! • Recap of energy distributions figure. Here is a typical figure you might have obtained from the sampling test program:

### Test of Numerical Derivatives [exp(-x) at x=1]

, 2006

"... In Session 4, we looked at error plots for various ways to calculate numerical derivatives. Here is a plot showing results for forward difference, central difference, and a Richardson extrapolation of the central difference results: 0-2 forward difference fit: a1*x + b1 central difference fit: a2*x ..."

Abstract
- Add to MetaCart

In Session 4, we looked at error plots for various ways to calculate numerical derivatives. Here is a plot showing results for forward difference, central difference, and a Richardson extrapolation of the central difference results: 0-2 forward difference fit: a1*x + b1 central difference fit: a2*x + b2 extrapolated difference fit: a3*x + b3 fit: a4*x + b4

### unknown title

"... Session 16 has a brief look at partial differential equations or PDE’s. We’ll consider three very simple programs to calculate three linear PDE’s with two variables. All are generalizable to more variables and more complicated boundary conditions. We give some brief background here while there is mo ..."

Abstract
- Add to MetaCart

Session 16 has a brief look at partial differential equations or PDE’s. We’ll consider three very simple programs to calculate three linear PDE’s with two variables. All are generalizable to more variables and more complicated boundary conditions. We give some brief background here while there is more detail in the excerpt from Landau/Paez [1]. We also provide notes on the Schrödinger equation in momentum space as an example of solving integral equations with linear algebra and also calling Fortran library routines from C++. a. Laplace’s Equation in Two Dimensions The code laplace.cpp solves for the electric potential U(x) in a two-dimensional region with boundaries at fixed potentials (voltages). For a static potential in a region where the charge density ρc(x) is identically zero, U(x) satisfies Laplace’s equation, ∇ 2 U(x) = 0. In the x–y plane (i.e., assuming it is constant in the z direction), the equation reduces to ∂ 2 U(x,y)

### unknown title

"... • Profiling in Mac OS X. It appears that gprof, which is the program we use to do profiling in Linux and Cygwin (for Cygwin, note that a replacement gprof.exe was provided in session09.zip), is broken in Mac OS X. Possible replacements are DTrace and Shark. Unfortunately, I do not yet have an easy g ..."

Abstract
- Add to MetaCart

• Profiling in Mac OS X. It appears that gprof, which is the program we use to do profiling in Linux and Cygwin (for Cygwin, note that a replacement gprof.exe was provided in session09.zip), is broken in Mac OS X. Possible replacements are DTrace and Shark. Unfortunately, I do not yet have an easy guide to doing profiling with either of these applications. • Comparing Two Files. The diff command is a very convenient way to quickly determine the difference between two files. For example, you have saved the original version of a program and someone gives you a modified version. To find the changes, diff from-file to-file will list just the lines that are different, with < in front of the line as it appears in from-file and> in front of the line as it appears in to-file, with the relevant line numbers given. To find out more, use man diff (there are many options). b. Adaptive Differential Equation Solvers In general, it’s best to adjust the step size h in solving a differential equation because the optimal size will vary for different parts of the function. A routine that varies the step size automatically to keep the local error under control is called “adaptive”. We’ll try out the adaptive routines from

### a. Random Numbers

"... Monte Carlo methods provide powerful techniques for simulating experiments, solving complicated many-body systems, and getting nonperturbative results from quantum field theories. They are the basis for evaluating higher dimensional integrals, including the approximation of path integrals. In this s ..."

Abstract
- Add to MetaCart

Monte Carlo methods provide powerful techniques for simulating experiments, solving complicated many-body systems, and getting nonperturbative results from quantum field theories. They are the basis for evaluating higher dimensional integrals, including the approximation of path integrals. In this session we’ll look at a principal ingredient of Monte Carlo calculations, random numbers, with some basic applications. In the next sessions we’ll simulate a spin system and look at variational Monte Carlo. A sequence of numbers is random if uncorrelated: that is, if you know x1,x2, · · ·,xi, then xi+1 is not predictable. The distribution of random numbers need not be uniform; for example, if the distribution is gaussian, some ranges of numbers will be more or less likely than other ranges. This may not be obvious when looking at a short sequence. However, if we generate a large number of random numbers and plot them in histogram form, we expect that the histogram will approach the shape of the probability distribution function or PDF (e.g., flat if uniform or like a gaussian if a gaussian distribution or...). Computers generate pseudo-random numbers, which are not truly random but simulate them effectively. Some basic features of a good random number generator (abbreviated rng) [2]: 1. Produces a uniform distribution in [0,1]. 2. Correlations between random numbers are negliglible. 3. The period before the pseudo-random sequence repeats is as large as possible (e.g., 10 9 or greater). 4. The algorithm should be fast. The trade-off between the last three features are what distinguishes different rng’s. There are various tests of random numbers. A quick (but not infallible) eyeball check if numbers are random is to plot them (e.g., with gnuplot) by treating them as (x,y) pairs (that is, the first two numbers form the first pair, the next two form the second pair, and so on). Another test is to calculate the average of the k’th power of a set of N numbers: 〈x k 〉 ≡ 1 N N∑ i=1 x k i p(xi) , (12.1) where the PDF p(x) = 1 for 0 ≤ x ≤ 1 for a uniform distribution. For large N, the results should (if the numbers are random) approach the limiting integral 〈x k 〉 N→∞

### 2D Ferromagnetic Ising Model Energy vs. Time using Monte Carlo

, 2006

"... an example of what you might find from running the ising model.cpp code with kT = 1 three times: ..."

Abstract
- Add to MetaCart

an example of what you might find from running the ising model.cpp code with kT = 1 three times:

### unknown title

"... First, a couple of general comments on the 1094 sessions. • Please try to not skip items if you have time; everything is there for a purpose, even though it might not be obvious to you (and might seem pointless or too easy). If you are already quite familiar with a topic, you can make the task more ..."

Abstract
- Add to MetaCart

First, a couple of general comments on the 1094 sessions. • Please try to not skip items if you have time; everything is there for a purpose, even though it might not be obvious to you (and might seem pointless or too easy). If you are already quite familiar with a topic, you can make the task more challenging or ask (and try to answer) a more complicated question (e.g., the “To do ” list in the area.cpp program). • Take the verification of codes very seriously. It’s important! The modified code to calculate the volume is an example of how you have to be careful. A typical modification of the calculation line is: