You are on page 1of 500
Lomputational MINISTERS Computational Physics Second Edition Nicholas J. Giordano Department of Physics Purdue University Hisao Nakanishi Department of Physics Purdue Uni regrets ilematonl Agencies (rf Lied Memabod chore premag = Tas mcrae snot he Sable way event for cadena cr We cannot emphasize too strongly that the tumerical “solution” obtained in this way is only an apprarmation to the “true,” ‘or exact, solution. Of course, one of our goals is to make the difference between the two negligible. The approach to calculating Ny(t) embodied in (1.6) and (1.7) is known as the Buler method and is « useful general algorithm for solving ordinary differential typical errors amociated with them aze the subject of Appendix A. For now, the reader should realize that while the Buler method arises in a very natural way, it is certainly not the only algorithm for dealing with problems of this sort. We will tee that the different approsches have their own strengths and weaknesses, which make them more or less suitable for different types of problems. 1.3 DESIGN AND CONSTRUCTION OF A WORKING PROGRAM: CODES AND PSEUDOCODES Tn the previous section we introduced the Euler method as the besis for obtaining ‘8 numerical solution to our radioactive decay problem. We now consider how to translate that algorithm into a working computer program. Perhaps the first choice ‘that one must make in writing « program is the choice of programming language. From the authors’ experiences, there are many programming languages that are well suited for the kinds of problems we address in this book, and it is impossible for us to give example programs in all of these languages. However, it is possible to describe the structure of = program in a general way that is useful to users of many different languages. We will do this using » “language” known as pseudocode. This i not a prece programming language, but rather a description of the essential As you might expect, the quality of this extimate, Le. tts accuracy, will depend on the value of Dt. ‘Thin in w very important innoe that we will be discuning ie some detail below and i A ‘that ecrors made each at each time stap, Le, each tine (1.7) i wwed, will accumulate, 4 Chapter 1A First Numerical Problem parts of an algorithm, expressed i “common” language. The ides is to give enough programs for many of the problems in this book are available in Fortran, we will need, Ny, t, 7, and At. Our stated goal was to calculate Ny(t), but since the numerical approssmation (1.7) involves the values of Ny only at times t = 0, t= At, t = 2At, etc., we will actually calculate Ny at just these values of t. We will use an array to store the values of Ny for later use. An array is simply a table element will be the value at t= At, and soon. Our general plan is then to apply (1.7) repetitively to calculate the values of Ny(t). ‘The overall structure of the program consists of four basic tasks: (1) declare ‘the necessary variables, (2) initialize all variables and parameters, (3) do the cal culation, and (4) store the results. EXAMPLE 1.1 Pseudocode for the main program portion of the radioactive Gecay problem © Some comment text to describe the nature of the program. > Declare necessary variables and arrays. ‘> mutiahze variables. > Do the actual calculation > store the results. “We are certainly aot implying that everyone should use Fortran or C, but thane are the autora’ Section 13 Design and Constrection of a Working Program. Codes and Pueudecodes § Note that this is only the main program; tbe individual tasks such as ini- tialization of variables and the actual calculation, will be done ia subroutines or functions, which we will discus below. Pirst we consider how this main program might look in Fortran.* radioactive decay main program ie Fortran, (Our program begins with a few comment statements that identify the program ‘and tell e little about what it is supposed to do. In Fortran, comment lines are indicated by the ‘c’ in the first character in s line. Similar features are present in most languages. The first line program decay gives the name of the main program. The line double precision 2.uraniue(100), t(100) declares the two arrays that will be ‘used to store Ny and ¢. This is done is the main program because the subroutines that do the work will pass the arrays among sch other through the main program. ‘The first array, 2_urasiue(), will contain the calculated values of the number of uranium nuclei, while t() will coatain the corresponding values of the time. Here we have arranged for our arrays nuraniue() and t() to each hold 100 values, as we expect this to be enough for this problem (of course, many languages allow one to resize an array as needed during « calculation). Note that we have used the descriptive name s_uranius to make the program easier to read and understand. It is also tempting to use the name tine for the other array (instead of t), but some languages use time as a “reserved name” (¢.g., the name of the time-of-day function), s0 to be safe we will avoid using it. ‘The rest of the work is done in three subroutines, initialize, calculate, and store which are called in succmmion. The subroutine names describe the function of each; these tasks correspond directly to the general program outline mentioned above. The call statements also include the names of the variables ff i I } | E E f E the variables, calculate uses the Euler method to do the computation, et bn thie chapter, we have chou an old (some may i | i | { ‘A H i i i l t i i i © Cnapters A rips reamencat rrocem and store puts the results into « file for later use (such as « graphical display). We next consider those three routines EXAMPLE 1.2 Psewdocode for subroutine initialize + Prompt for and assign Ny(0), 7, and At. © Set initial value of time, #(0). © Set number of time steps for calculation. A Fortran version of this subroutine could read Fortran version of subroutine initialioe In Fortran all subroutines begin with the subroutine nane statement where ‘name is the subroutine name. As in most other languages, the variables luted in parenthesis after the word initialize are passed into and out of the subrou- tine from/to the calling routine. This variable list must be in correspondence with the list used when the subroutine is called from the main program (or any- where else). Comparing the calling line and the first line of the subroutine, we see that some of the names in the variable list in the “calling” part of the pro- gram, D-arenzus,t,tas,ét,2, and the list in the “receiving” part of the program, nuclei,t,tc,dt,n are quite different. For example, the array names ouraniua and nuclei do not agree. But, as in most languages, the array and variable names declared within a subroutine definition are dummy names, and only the correspond- ing arrays and variables in the calling program are actually used. After getting the calling varisbles organized, the initialize subroutine sets the initial values of the number of muclel and the time. These are just the first values in the arrays muclei(1) and t(1). The print statements prompt the user for input, while the read statements take in the values. The last job is to set the value of n, which is the number of time steps to be performed. The real work of computing the number of remaining nuciei is done in the subroutine calculate. CN A Ae AN OF RG RRA LOU ad PRUOOCOOES 1 EXAMPLE 1.3 Pseudocode for subroutine calculate ‘© For cach time step i (beginning with {= 1), calculate Ny and ¢ at step i +1: > Nultisa) = Nu(ts) ~ (Nu(ts)/r)at (Use the Buler method, (1.7)) D tier ee Ot. > repeat for n ~ 1 time steps In Fortran this can be written as Subroutine calculate in Fortran eubroutine calculate(s erentan,t.tes.¢t.a) « Now use the Euler sethod « variable dimensioning is weet for arrays a cranten() and ¢0 double precision a ureniua(s),t(a) doin tet ‘Rerenieaien) © a serenten(s) (a arenten(s)/tendoee, ein) © 8) # ae returs ont ‘This routine loops through each time step using the do and continue state- ments (other languages have analogous facilities to write simple loops). The key statement is the one in which muraniua(.+t) is calculated. This statement con- tains all of the physics of the program and is closely analogous to (1.7). As men- tioned above, the array a uranius corresponds to the variable y(t), and the value stored in the ith element of a uranius is the number of uranium nucle present at time (2). The final subroutine store writes the result to a fle. It uses « standard Fortran approach to store the results in the file decay.dat. The values of t and Ny ave written as pairs, with a separate line for each value of ¢. The results can then be read from this file, in order to plot the results, or use them in a subsequent calculation. > 2 tormat(tx,tp,2(012.8,200) reture pe ee eeeememe + renee For convenience, our complete Fortran program is listed in one piece below. Fortran version of radmactive decay progam € Simulation of radioactive decay Progran te accompany “Computational Phywice” by ¥ Gierdane/#. akanteht regres decay declare he arrays we will seet double precision auraniwe(s00), (100) ee subroutines te do the werk call initialize(s_aranten,t,ten,¢t.0) call caleaiate(s cranten,t,tes,40,2) call svore(asraniun,t.a) nop eos ubrostine initialise(mecies,t.te,¢,2) Initealine variables Gownie precision muciei(1),0() ubrovtine calculate(s craniun,t,tas,ét.2) « Mow use the Euler methot « Variable dimensioning is weed for arrays surenimn() ant t() double precssion s_cranien(a),t(a) foie hat ‘Rurantun(iet) = a xransem({)~(a_erantem(t)/tendodt tied) = 8G) + at a revere ~ ewbroutine store(s crantun,t.2) doable precision = crantun(s),t() open (1, filer" decay dat oe ite wrate(i,20) £(4) x crentun(t) end to clowe(t) 20 format(ix, 4p,2(012.6,22)) eure Section 13 Uengn and Lonstrecton of a Working Program. Codes and seudocodes 9 ‘We have spent a lot of time discuming a Fortran program for the radioactive decay problem, but the basic ideas — the basic structure of the program — can be implemented in many other languages. Below we give # program written in C that does the same calculation, using the same program structure with the same algorithm. It begins by declaring the necessary variables, then uses subroutines initialize, calculate, and store, as outlined in the pseudocode in Example 1.3. ‘These subroutines are quite similar to those in the Fortran program given at left, ‘and produce ideatical results. Rendanactive decay program in = / daenye datine MAX 100 double suraniweDMAx); /* mumber of uranium avoms */ doubie Dex); (+ were tine valses bere +/ double ot; fs me wep ” double teu; [+ tncay Siam comment of double tnaxy (+ Cine te end simalation +/ pristt("initial suber of seclet -> *); scant ("Eit*e(nvciei (0))); /* begin using arrays st index © +/ pruntt ("tine constant -> *); scant ("RE te); printt(“tine step -> “Di cant ("hit €2); {0} = 0.0; return; (+ calculate the results and store then in the arrays t() aed asO «/ calculate(eocles t.0c.¢t) double eauciei,et,te,@t) t ame 4; forts = 0; 4 < MARL; 400) € maciei{iet) = mucleifi] ~ (aeclei{t] / te) © @t; thier) = eh) + ary Kp out, "Ng sige" .¥ (4) .ewetes (10); We bave given specific example programs in Fortran and C, as these are languages that we (the authors) use in our everyday work.” However, this certainly does not mean that one of these languages is the best choice for you; that is a judgment that you must make. Next we come to an extremely important point, that is a key issue in nearly all the problems we will discuss in this book. Our program decay calculates how Ny varies with time, and puts the results as numbers into a file. However, we still have the job of understanding the results. In this problem, and in most cases, this job of understanding is best done by examining the results in graphical form. While there will be times when the result of a calculation can be expressed or conveyed ‘a5 ope Or two sumbers, it will usually happens thet our calculations produce lot of numbers. Making sense of such results is almost always simplest when the results are displayed graphically. In our decay problem we will want to make a graph of Ny as « function of t. Methods for producing a graphical display, either on @ video display or on paper, can vary « lot from one computer platform and language to another, and there is no way that we can possibly give a full discussion of bow you should go about it on your particular system. Some languages bave very powerful graphics capabilities “built-in” (e.g., Matlab and Mathematica), while in ‘other cases you may need to use separate graphics programs to display the results im the file decay.dat. ‘The ability to easily display results in graphical form is absolutely essential for ‘work in computational physics Fortunately, virtually all computer systems have ‘the programs you will need (so you will not have to write your own!). Before you go ‘much further in this book we urge you to learn bow to use the graphics capabilities of your particular system. Figure 1.1 shows an example of the output produced by our radioactive decay program, along with the exact result, Equatioe (1.2). Here we have used the initial ‘values 2 uraniun(1) = 100 and t(1) = 0, along with a time constant of 1s and a time step of 0.05 s. We will consider the choice of time step later. For now we note only that our calculated values compare well with the exact result. "The may also give you sume iden of when we fret learned to program. Section 14 Testing Your Program 11 ‘Number of Nucie: FIGURE 1.1: Circles indicate the numerical sokution to the radioactive decay problem. The solid fine is the exact solution Equaten (1.2). 14 TESTING YOUR PROGRAM The title of Section 13 was « little misleading. It was concerned with producing ‘® program that runs without any errors im the syntax, etc., such as undeclared arrays, spelling errors, or variables omitted when calling a subroutine. However, ‘we should not really consider it to be a working program until we are convinced thet its output is correct! Checking « program is not always a trivial task, but there are some general guidelines. After « program has been debugged so that it can be run without any complaints about the syntax, there are several things you should do to verify that the results of the program are correct. Does the output look reasonable? Before you perform any calculation you should always bave at lesst « rough ides of what the result should be ‘The first thing you should do when considering the results from any program is ask whether or ‘not they are consistent with your intuition and instincts. This exercise can also improve your overall understanding of the problem. When you show your result to someone else, you sbould always be able to convince them that it makes sense.” Does your program agree with ony exact results that are available? Since we knew tthe analytic solution for our radiosctive decay problem, we were able to compare ‘our gumerical values with the exact result. While such s comparison will not be possible for most of the numerical calculations you will encounter, exact results are "One definition of « physicist le “s person who can calculate anything to within an onder of maguituda” This ls pechage « bit overstated, bat you should ually be able to anticipate an ‘answer with this sort of accuracy. 12° Chapter A First Numerical Problem sometimes available in certain limits, that is, for special values of the parameters, ‘You should always rua your program in those limits to check that it gives the correct answer. This is a necessary (but not sufficient) test that « program is correct in the general case. Always check that your program gives the same answer for different “step sizes.” Our decay program involved a time-step variable, ¢t, and most other numerical calculations involve similar step- or grid-size parameters. Your final answer should be independent of the values of such parameters. This is another necessary (but correcting) a program as it takes writing it. After all, « result is not (good if you don't trust it to be correct. 1.3, NUMERICAL CONSIDERATIONS ‘The issue of numerical errors is central to the computational solution of any prob- Jem. Indeed, this is such an important topic that there are many books devoted to this ares. Questions such as bow to design or choose the best algorithm for a particular problem, and how to estimate the numerical errors associated with an Algorithm, are central topics in many computer science and applied mathematics courses. We could easily spend ¢ lot of space discuming the Euler method and all ‘the other algorithms we will be using in this book. However, while this would cer- tainly be an instructive thing to do, it would leave us with very little time to explore the physics that can be done with these algorithms. In this book our emphasis will be on the physics, rather than the numerical methods. This does not mean that ‘we view numerical methods as unimportant, but just that there is only so much ‘that we can do in one book Nevertheless, we will be making some comments about ‘the choice of algorithms, their sumerical uncertainties, and their stability. We will attempt to blend these discussions with the physics as we go, particularly when they are closely related to the physics of the problem. The Appendices contain more detailed and systematic discussions of maay of the numerical methods we use im this book. ‘With our radioactive decay program, errors were introduced by the approzi- ‘mation used to estimate the solution of the differential equation (1.7). Errors are also produced by the finite numerical precision in any programming language, in- cluding Fortran and C. These are known as round-off errors, and are almost always preseat ben oumbers are represented by « finite number of digits. Fortunately, this is not usually a severe problem, as most modern computer language systems ‘employ & large number of significant digits. In order to be as safe as possible you should always use double precision variables in Fortran, C, and other languages where this is an option However, this is no guarantee thet these errors will be negligible, as the numerical solutions to certain types of problems are inherently sensitive to round-off errors. It is bard to give any general rules about what to watch for, but we will discuss such difficulties when they arise in several problems later in this book. Section 15 Numerical Considerations 13 Number of Nuciei FIGURE 1.2: Numerical solution of the radioactive decay problem using the Euler method for different ‘values of the time sep The time constant was I a, and the time steps were: filed orces, 0.5 », open circles, 0.2, squares, 0.05 # The solid carve & the exact sation Ip attacking the radioactive decay problem we were led to treat time as a discrete variable; that is, we converted the differential equation (1-1) into a differ- ence equation (1.7), which enabled us to compute estimates for Ny at the discrete times nAt, where n is an integer. Such » “discretization” of time, or space, or both, is « common practice in sumerical calculations, and brings up two related questions: (1) How do we know that the errors introduced by this discreteness are negligible, and (2) How do we choase the value of such a step size for a calculation? Again, there are no general answers to these questions. All we can do is give some uidelines, which can be illustrated using our radioactive decay problem. ‘The first guideline is that « calculation should aleays be repeated using several different values of the step size. Figure 1.2 shows the results from our radioactive decay calculation using three different values of the time step. The time constant 7 was taken to be 1 6, and the symbols show the numerical results for time steps of 0.5, 0.2, and 0.05.8. Also shown is the exact solution (the solid line). Because of the ‘ponzero step size, our program only yields results at discrete values of t, which is why the calculated points become more dense as te time step is reduced. We see that as the time step is made smaller, the calculated values converge quickly to the exact solution. This is not surprising, since intuition tells us that our approximations should become better as At is reduced. Being more quantitative, we already noted that the terms dropped in our derivation of (1.6) are of order (At)?. In order to understand the accuracy of the calculated result at a specific value of f, we note that it takes ¢/At time steps to reach this point (starting from t = 0). The total 14 Chapter 1A First Numerical Problem error (often termed the global error) is proportional to the product of the number of the te (tt) and he error per tap (~ (4), and on of order. Hence, we expect the difference between the sumerical (Buler) aad exact results to be cut in half for each factor of 2 reduction of St. It is clear from Figure 1.2 that the numerical results become extremely close (on the scale of this figure) to the exact ‘solution for time steps below about 0.05 s. For our decay problem we have the exact solution, which makes it easy to evaluate the accuracy of our sumerical results. However, we will not usually be this fortunate, so it is important to consider how to evaluate our results when the exact result is not available. In such cases you should always check that the calculated result converges to fixed value (or curve) as the step size is made smaller. A closely related matter concerns the choice of step size in the first place; that is, what is a reasonable value? Here, yet again, there are no hard and fast rules. Ideally, you should use a step size that is small compared to any characteristic time scales in the problem. In our decay problem this time scale is r, since its value determines how fast Ny varies. Our recommendation is that you pick the time step Yo be a small fraction of r. We see from Pigure 1.2 that a time step that is a few percent (or less) of this characteristic scale is « good choice. ‘One more important issue concerning numerical precision will be encountered later in this book. There are situations in which what appears to be a very reason ‘able numerical approach can be inherently unstable. For example, we will find in ‘Chapter 3 that the Buler method, which we have found to work well for the radioac- tive decay problem, fails miserably when applied to problems involving oscillatory motion. The message here is that there is no one best method for solving ordinary differential equations or any other particular class of problems. You must apply your understanding of the theory behind an algorithm (as discussed, for example, in a numerical methods book such as Press et al. (1986]) and your ingenuity (and ‘so this book!) to choose the appropriate method for any particular problem. 1.6 PROGRAMMING GUIDELINES AND PHILOSOPHY In our constroction of the radioactive decay program we noted that writing a pro- gram is necessarily an individualistic endeavor. Nevertheless, there are certain ‘guidelines that are generally recommended, some of which were touched on above. Al of these guidelines bave essentially the same purpose: to make the program as easy to understand as posible © Program structure Use subroutines to organize the major tasks and make the program more readable and understandable. The sain program for the decay problem was basically an outline of the program; we recommend this style for all programs. Use subroutines and functions to perform any jobs thst take more than a few lines of code, or that are required repeatedly. © Use descroptive names. Choose the names of variables and subroutines ac- cording to the problem at hand. Descriptive names make a program easier to understand, as they act as built-in comment statements. Section 16 Programming Guidelines and Philosophy 15 © Use comment statements. Include comment statements to explain program logic and describe variables A short subroutine that uses descriptive variable names should not need « large aumber of comment statements. © Sacrifice (almost) everything for clarity. It is often tempting to write a crit- ical piece of code in a very compact or terse manner in the misguided belief ‘that this will make the program run faster While » compact code may occa- sionally run faster, this is not a reliable indication of ‘Moreover, such compact code will nearly always have a cost in terms of clarity ‘and readability; there are many famous plecesyof code in Fortran and C that come to mind bere. It is almost always better to take « few more lines, or a few more variables, to do « job, if it makes the code more understandable.” Tt is also & good ides to make the code look as much as possible like the ‘associated physics equation. This will save time later when you are checking your program ‘The execution speed becomes an important programming issue only when the overall computer tume requirements become substantial (say, over several minutes). Eves then. significant savings can usually be made only by algo rithmic improvements and it is rare to see a noticeable gain in efficiency due to fiddling with a line of code here or there. In this book we will generally write our programs without worrying much about program efficiency. If you ‘want to “tuneup” program to make it run faster, this should be done only after it is known to be correct. Moreover, modern language compilers often do & good job of optimazing code without the programmer even knowing it! © Take time to make graphical owtpst os clear os possible. Think carefully Note: Throughout thie book, exercises labeled with an * are more challenging than others in that section LL. The velocity of « freely falling object near Earth's surface is described by the equation, $= -s. as) where v is the velocity and ¢ = 9.8 m/s” is the acceleration due to gravity. Write ‘s program that employs the Buler method to compute the solution to (1.8); that is t= 0 tot = 108 Repeat the calculation for several different values of the time step, and compare the results with the exact solution to (1.8). It turns out "in very largeacale projects, there may perhaps come time when clarity begins to compete with computational eficiency Hf so, some compromians may seed to be made however, in all ‘cana, clarity should recnive as exireceely high priority. Sometimes, plotting either or both axm logarithmically may be more appropriate than using linear scales, see Chapter 3 for some examples. 16 Chapter A First Numerical Problem that for this case the Buler method gives the exact result. Verify thie with your ‘numerical results and prove it analytically. 1.2. The position of an object moving horizontally with » constant velocity, v, is described by the equation $-- (9) ‘Assuming that the velocity is constant, say © = 40 m/s, use the Buler method to solve (1.9) for x as function of time. Compare your result with the exact ‘solution. type B nuckel, which then also Se areraiag to the Afbrental eyetions interpret the short and loog time bebsrices for different values of this ratio. “LS. Consider again a decay problem with two types of nuclei A and B, but now suppose that nuclei of type A decay into ones of type B, while nuclei of type B decay into ones of type A. Strictly speaking, this is not a “decay” process, since it is possible for the type B nucle! to turn back into type A nuclel. A better analogy would be» resonance in which « system can tunnel or move back and forth between two states A and B which have equal energies. The corresponding conditions, such as N4 = 100, Np = 0, etc.pand taker = 18 Show that your numerical results are consistent with the ides that the system reaches & Mendy state in which V4 and Ng are constant. In such « steady state, the time derivatives dN 4/dt aad Np /dt should vanish 1.6. Population growth problems often give rise to rate equations that are first-order. For example, the equation o = on -oy, (as) might describe how the number of individuals in a population, N, varies with ‘values of « and 6 depend on the initial population N For small N(0) and 6 ood choice, while for N(0) = 1000 « good choice is a = [1] B. W. Kernighan and P. J. Plauger, 1978, The Blements of Style, 2d ed, McGraw-Hill, New York A very nice discussion of how to write clear, readable, and efficient programs in any language [2] W. H. Press, B. P. Flannery, S. A. Teukolsiy, and W. T. Vetterling, 1986, Mumerical Recipes, Cambridge University Press, Cambridge. An excellent all- Purpose reference on numerical methods and why they work. CHAPTER 2 Realistic Projectile Motion In this chapter we consider several problems involving the motion of objects through the atmosphere. The problems are all described by ordinary differential equations in which initial values are given and all can be solved using the Euler method, which was introduced in the last chapter. These problems are good examples of interesting physics involving the mechanics of macroscopic objects, which can't be solved analytically, but can be easily tackled with a computer. ‘We begin with a discussion of the motion of « bicycle traveling on flat terrain. We will Sind that air resistance must be included if we are to obtain a realistic description of the problem, and this leads us to simple but fairly accurate model of the drag force due to the atmosphere. Next we treat projectile motion in two page herring, frisbee er ote oie a ‘of & batted ball and the motion of thrown balis (curve balis and knuckleballs). To model a batted ball we are led to consider air resistance a little more realistically than in the earlier problems, while for a thrown ball we must also include spin- forces These themes are developed further in our discussion of the motion of golf balls, where we answer the eternal question: "Why do golf balls have dimples?” 2.1 BICYCLE RACING: THE EFFECT OF AIR RESISTANCE The bicycle is an extremely efficient form of transportation, a fact that is well known to anyone who rides one. Our goal in this section is to understand the factors that determine the ultimate speed of a bicycle and to estimate this speed for a realistic case. We will begin by ignoring friction; we'll have to add it eventually, of course, but let us first understand how to deal with the simpler case without friction.’ Our ‘equation of motion is Newton's second law, which can be written in the form #_F an’ where v is the velocity, m is the mass of the bicycie-rider combination, ¢ is the time, and F is the force on the bicycle that comes from the effort of the rider (here we ‘will assume that the bicycle is moving on Sat terrain). Dealing properly with F +The astute reader might now ask “Dut could 6 bucychet really propel s bucycls yf there were no frcton?”, and you are right if your own anewer is No. Without friction betwers the tires and the road, the wheels would exmply ship. and the becycle would go sowhere Priction is thus essential (2.4) Gasipation This dissipation along with deformations of the tires snd lowe iotersal to the bicycle. 18 Ok OE Ne FE COLA OF A MenEaNCR AY is complicated by the mechanics of a bicycle, since the force exerted by the rider 4s transmitted to the wheels by way of the chainring, gears, etc. This makes it very difficult to derive an accurate expression for F. However, there is another way to attack this problem that avoids the need to know the force. This alternative are able to produce & power output of approximately 400 watts over extended periods of time (~ 1 h). Using work-energy ideas we can rewrite (2.1) as e 7? (22) where £ is the total energy of the bicycle-rider combination, and P is the ‘output of the rider. For « fist road the energy is all kinetic, s0 B= jmo*, and dE /dt = mv(dv/dt). Inserting this into (2.2) yields? & _ P =m (2.3) If P ws constant, (2.3) can be solved analytically. Rearranging gives [vw - [ie. (24) where ty i the velocity of the bicycle at ¢ = 0. Integrating both sides and solving for v then leads to v= v@ + 2Pt/m. (2.5) ‘While this is the correct solution of the equation of motion (2.2), it cannot bbe the whole story, since it predicts that the velocity will increase without bound ‘at long times. We will correct this “unphysical” result in » moment, when we generalize our model to include the effect of air resistance. The new term we will ‘add to the equation of motion will require us to develop » numerical solution, so with that in mind we consider « numerical treatment of (23). We begin with the finite difference form for the derivative of the velocity ae Sn -s 5°. (26) where we have assumed small, discrete time steps of size At, and taken % to be the velocity at time t; = i At, where i is an integer (this should be familiar from Chapter 1). Inserting this into (2.3) we obtain, after little rearranging P = ae. (2. Sa = at a (27) Wi the approcination made (2.6), the lending earection arms are proportional to (At)? ‘*This assumes implicitly that very Bitle energy is lost to friction in the bicycle itesif; we'll include other sources of energy lose in © moment. 20 nape eM. HU wenn Given tbe velocity at time step i (Le, %), we can use (2.7) to calculate an apprommate value of the velocity at the next step, ti4i. Hence, if we know the Initial velocity, up, we can obtain ;, then wp, and so oa, and thereby estimate the velocity at all future times. This is just the Buler method, which we encountered in Chapter 1. There are more sophisticated methods for numerically solving differen- tial equations of this form, and a few of them are described in Appendix A. In this book we will only rarely encounter problems for which the Euler method, or simple variants, are not adequate. However, you should be aware that: (1) methods that tare more powerful? than the Euler method do indeed exist; (2) these more powerful methods can certainly be used to solve all of the problems in this book where we use the Euler method; and (3) if you are going to do this sort of thing for « living it is worth your while to learn about these other methods. In taking what some purists might consider a quick-and-dirty approsch (by our use of the Euler method), we are ‘not trying to minimize the importance of other algorithms. Our intent is merely to use the simplest numerical method (which wil give the correct solution, of course) ‘appropriate for the job, so that we can emphasize the physics of our problems and not let the numertcal techniques get in the way. You are encouraged to follow their own taste here, and with all of the other problems discussed in this book, and use the methods with which you feel most comfortable. The outline of a program that performs this calculation is shown below. The general program structure is similar to the nuclear decay program in Chapter 1, in which variables and arrays are frst declared and initialized, the actual calculation is performed using the Buler approximation, and the results are then stored. Here wwe only sketch the main program and the calculation subroutine, and leave the rest for the reader. EXAMPLE 2.1 Pseudocode for bicycle calculation «main progran > Declare necemary variables, including arrays ¢() and v() to store time and velocity. > Set values for the power P, mass m, and time step At, and total number of time steps NY, along with the initial value for the velocity (vy). > Do the actual calculation. > Store the results. © calculate subroutine > For each time i calculate w and ¢ at step i+ 1: wa=a+(Z)ae tar + > Repeat for NV time steps. By “more powerful” we mean thet they yield more accurate solutions for s given amount of ‘computer time, or that they are more stable in & sumerical sees. ‘Section 21 Bicycle Racing The Effect of Alr Resistance 22 ‘We are now ready to compute a numerical solution. We assume that the bicycle starts with « velocity of w = 4 m/s (about 10 mph) and take P = 400 W, ‘the value obtained from physiological measurements of well-trained athletes, as mentioned above. The last point to consider is the choice of At. Roughly speaking, At should be sufficiently small that the velocity changes only a little during such ‘an interval. What it means to be “suificiently” small is hard to say, in general. A useful rule of thumb is to begin with « time step that is about | percent of any time ‘scales un the problem, and then repeat the calculation with several smaller values.‘ ‘Smaller time steps will give smaller correction terms fe.g., in (2.7)] and thus more ‘accurate results, but the calculation will take « computational time proportional to (At)-", so there is s trade-off here. For our bicycle problem it will turn out that time steps smaller than about 1 s are adequate. It is usually instructive to repeat a calculation using different values of the time step so as to observe bow the solution converges to the correct one as At is reduced. ‘The results for our “frictionless” bicycle are shown in Pigure 2.1, where we have used a mass of 70 kg for the bicycle-rider combination (elite bicycle racers tend to be rather slender). We see immedistely that, as anticipated above, our model has a serious problema; the velocity reaches 45 m/s (about 100 mph) in less than 3 min, While this performance would not be particularly impressive for # car, it is certainly not within reach of any known bicycles (or bicyclists). We also see that v appears to grow indefinitely, and this makes the origin of our problem clear. We have not included any sources of dissipation, so given our assumption of constant power exerted by the rider, the kinetic energy will increase without limit. If we want to have a realistic model, we must add some mechanism for energy loss. For a well-tuned bicycle traveling at more than about 5 or 10 mph, the energy problem. In general, this force can be written im the fairly innocent form Fang © - Biv — Bav?. (28) ‘You will 20 doubt notice that (2.8) bears a strong resemblance to a Taylor expan- sion, At extremely low velocities the first term dominates, and its coefficient By can be calculated for objects with simple shapes. This is known as Stokes’ law and is considered in most elementary mechanics texts. However, at any reasonable velocity the e term in (2.8) dominates for most objects. Moreover, B, cannot be calculated exactly for objects even as simple as a baseball, and certainly not for a ‘sir in front of it out of the way. The mass of air moved in time dt is mus ~ pAvdt, “While the “characsarstic” time acale le often not « unique or preci quantity, la some cases lt ie eagy to extimate. For example, in the radioactive decay problem ia Chapter 1 it was the time ‘constant + of the Gecay. In the present problem. exe satural choice is tbe time it tale to attain a velocity of the order of terminal velocity (see Pigure 22). - - FIGURE 2.1: Velocity 28 + function of time for our bicycle problem, sstuming 0 ar remstance, The ase of the bicycie-rider combination was 70 kg. the intoal velocity was 4 m/s, and the time step was 0.1, Here and in the other figures im this chapter, the rests at each time step are connected to obtain dn ennemally wooed carve. where p is the density of air and A the frontal area of the object. This air is given & velocity of order v, and hence its kinetic energy is Ex ~ Ma? /2. This is also the work done by the drag force (the force on the object due to air resistance) in the dt, 80 Fangudt = Ey,. Putting this all together we find® Fang * i 0par. (29) C is known as the drag coefficient, and our simple argument predicts that it is ‘equal to 1. However, we caution that our calculation was only approximate; while we expect it to give the correct functional dependence of Fing on A and v, we certainly do not expect the precise value it predicts for C to be correct. Indeed, we should expect that C will depend on the “serodynamics” of an object. The best way to determine the drag coefficient of any particular object is via wind tunnel ‘measurements, or similar experiments. It is easy to inclade thie drag force in our calculation; Equation (2.9) con- tributes another term to the right-hand side of (2.7), which becomes wor = n+ Zar SA as, (2.10) ‘and we can use the Euler method to obtain as « function of t as before. The Slee tas thin xpranion ites bye tcter of } bum the eorepending xprenion fr Fane 4m the first edition of this book. Tis change is made to confurm better to the standard definition ‘of the drag cosficiest, and does ot change any of the actual renaitn.

You might also like