Suppose we want to find approximate values for the solution of the differential equation

Size: px
Start display at page:

Download "Suppose we want to find approximate values for the solution of the differential equation"

Transcription

1 A course in differential equations Chapter 2. Numerical methods of solution We shall discuss the simple numerical method suggested in the last chapter, and explain several more sophisticated ones. We shall also deal with the problem of estimating error in the calculations. We make no attempt to produce the best routines possible, but just to present techniques which are reasonably simple to understand as well as reasonably effective in most circumstances. 1. Euler s method Suppose we want to find approximate values for the solution of the differential equation y 0 = f (t; y) with initial condition y(t 0 )=y 0 : The differential equation tells us that the instantaneous rate of change of y at time t can be calculated in terms of y and t alone. Now if t is any small interval of time we know that as a first order approximation we can write y(t +t) : =y(t)+ty 0 (t) in the sense that the difference between the right and left sides, for a fixed value of t, is essentially of order (t) 2. If y is a solution of the differential equation, this tells us that If t 1 = t 0 +twe know therefore that y(t +t) : =y(t)+tf(t; y(t)) : y(t 1 ) : = y 1 = y(t 0 )+tf(t 0 ;y(t 0 )) = y 0 +tf(t 0 ;y 0 ): We can apply this reasoning once again. If t 2 = t 1 +t=t 0 +2twe obtain a further estimate y(t 2 ) : = y 2 = y 1 +tf(t 1 ;y 1 ): Etc. If t n+1 = t n +t=t 0 +(n+ 1)t we get an estimate y n+1 for y(t n+1 ) from the estimate y n for y(t n ): y n+1 = y n +tf(t n ;y n ): This technique for finding approximate values for the solution of a first order differential equation is the simplest of several similar ones. Each of them proceeds in this stepwise fashion, obtaining an estimate for y(t +t)from that for y(t). This one is called Euler s method. It has some great virtues: It is simple to carry out. Doing it by hand is not impossible (although tedious and hence error prone). It can be easily implemented on a computer, for example with a spread sheet. The step from one estimate to the next is intuitive. 2. Euler s method and slope fields Euler s method has a simple interpretation in terms of slope fields. In the figure below we are looking at the differential equation & initial condition y 0 = y t; y(0) = 0:5 :

2 Numerical methods of solution 2 This is a linear equation and has the explicit solution y =(t+1) 0:5e t : The differential equation tells us how to draw the slope field and the initial condition tells us where the graph starts. y =1 y=0 At the starting point we know that the slope of the graph is equal to f (0; 0:5) = 0:5. This means that the tangent line to the graph at the starting point is the line y (t) =0:5+0:5t. This tangent line and the graph of y(t) will lie very close to each other for small values of t, and we can then use y as an estimate for y(t) for those values of t. After a while, however, it will cease to be a useful approximation. How can we get a better one? We pick some interval t and at t =twe modify the tangent line. We must modify it by using only information available to us in the calculation so far, and in view of this it seems reasonable to use as the new approximation the straight line through (t; y (t)) whose slope agrees with the slope field at that point. y =1 y=0 We then make new breaks in the approximation after every interval of size t. As we take smaller and smaller values of t we get better approximations to the graph of the solution. 3. The error in Euler s method

3 Numerical methods of solution 3 We expect that the error in the approximation we get from Euler s method decreases as we let the step size t get smaller. We can get a good idea of how the error depends on the choice of t by plotting in one picture the approximations we get for different values of t. Here we let t =1, 1=2, 1=4, etc. again with the differential equation y 0 = y t; y(0) = 0:5 : y =1 y=0 It looks very much as though we have the error as we halve the step size. We can verify this in more detail by comparing estimates for y(1) with the true value which we know to be (t +1) 0:5e t at t =1which is equal to 2 0:5 e = 0: N estimated y(1) true y(1) error 2 0: : : : ::: 0: : ::: 0: : ::: 0: : ::: 0: : ::: 0: : ::: 0: : ::: 0: : ::: 0: : : : This example leads to a guess which turns out to be true: The error in Euler s method for estimating y(t) with a given differential equation and initial condition of y at a fixed value of t is proportional to the step size chosen. The effect of this is to make Euler s method extremely inefficient for serious calculation. It requires an enormous amount of calculation to achieve reasonable accuracy. Very roughly speaking, the amount of work it takes to achieve a certain level of accuracy is proportional to the accuracy you want. Thus if it takes N steps to get 1 digit of accuracy (answer within 1=10), it will take 10 N to get an extra valid digit (within 1=100), 100 N to get 3 valid digits, :::, and N to get 6. The reason for the way error and step size interact for Euler s method is not hard to understand at least informally. Euler s method uses the estimate y(t +t) : =y(t)+ty 0 (t)+ terms of order (t) 2 :

4 Numerical methods of solution 4 That means that the error in making each step is essentially of order (t) 2. But for a fixed interval across which we want to calculate, the number of steps necessary is proportional to the inverse of t, which makes it plausible that the overall error is of order (1=t)(t) 2 =t. 4. Illustrating errors graphically We can use this to estimate the error in Euler s method even when we don t know the exact answer! For example, suppose we look at the equation y 0 = xy +1; y(0) = 1 This is a linear equation, but if we were to use the usual formula for the solution we would see it produces an integral we cannot find explicitly. Here is the estimate we get for y(1) with various values of N: N y(1) 4 2: : : : : : : : : And here is a graph of the pairs (;y(1)). 3:5 3:0 y =2:5! Figure 4.1. A plot of y(1) versus step size. What we can see from this plot is that the points (;y(1)) are to a good approximation on a straight line. This is in complete agreement with the principle I stated above, that the error is proportional to. But we can also see that to some extent we can predict what the end of the line is. This is because we can estimate from each successive pair what the slope of the purported straight line is it ought to be about y N y N 1 N N 1 for each N. Of course this is only an approximation, so we don t expect any of these estimates to be exact. Here is what we get in the runs above:

5 Numerical methods of solution 5 N N =1=N y N (1) y N (1) y N 1 (1) estimated slope 4 0: : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : The rough proportionality certainly shows up here, and the last column tells us roughly what the constant of proportion is. One run of Euler s method gives you no idea of the error involved. Two runs with values y 1 and y 2 for step sizes 1 and 2 give you the estimate y1 y for the error with step size. 5. How errors propagate The exact way in which errors propagate as we carry out Euler s method can be rather complicated. But a fairly simple argument can lead to some idea of the worst things can go, at least under mild conditions on the equation. Suppose y(t) is the exact solution to y 0 = f (t; y); y(t 0 )=y 0 : and let y n be the estimate for y(t n ) obtained by Euler s method, where t n = t 0 + nt. Let " n = y(t n ) the error in the method, the difference between the true and the estimated methods. Then y n be " n+1 = y(t n+1 ) y n+1 = y(t n+1 ) [y n +tf(t n ;y n )] =[y(t n ) y n ]+[y(t n+1 ) y(t n ) t f (t n ;y(t n ))]+t[f(t n ;y(t n )) f (t n ;y n )] = " n +[y(t n+1 ) y(t n ) t f (t n ;y(t n ))]+t[f(t n ;y(t n )) f (t n ;y n )] : If we assume that jy 00 j is bounded in the range we are looking at, say by A, then we have The quantity will be bounded by if in the range we are looking at and then we have jy(t n+1 ) y(t n ) t f (t n ;y(t n ))j A(t) 2 : jf (t n ;y(t n )) f (t n ;y n )j B jy(t n ) y n j = B" " n+1 " n + B t" n +A(t) 2 = " n (1 + B t)+a(t) 2 :

6 Numerical methods of solution 6 this leads to " 1 A(t) 2 " 2 (1 + B t)a(t) 2 + A(t) 2 " 3 (1 + B t) 2 A(t) 2 +(1+Bt)A(t) 2 + A(t) 2 ::: " n A(t) 2 [(1 + B t) n 1 + +(1+Bt) 2 +(1+Bt)+1] =A(t) 2 (1 + B t) n (1 + B t) 1 1 = A B t [(1 + B t)n 1] = A B t [ebnt 1] = A B t [eb(t n t 0 ) 1] if t n = t 0 + nt, since (1 + x) e x for all x 0. In other words, we can see that Under very mild restrictions, in Euler s method the error for a fixed t is at worst proportional to t and the constant of proportionality grows at worst exponentially with t. This is really a worst case scenario under the restrictions necessary. Most of the time the constant will behave much better. But for equations whose solutions grow exponentially the estimate will be reasonably close to what happens. The restrictions are mild, but there are cases where they don t hold. For the equation y 0 = y 2 the conditions are not satisfied for the solutions, which all go off to infinity in bounded time. 6. A better method Euler s method is quite inefficient. Because the error is essentially proportional to the step size, if we want to halve our error we must double the number of steps taken across the same interval. So if N steps give us one significant figure, then 10 N give us 2 figures, 100 N give us 3, N give us 6, and 10 n 1 N give us n figures. Not too good, because even a fast computer will think a bit about doing several billion operations. The method can be improved dramatically by a simple modification. Look again at what goes on in one step of Euler s method. Say we are at step n. We know t n and y n and want to calculate t n+1, y n+1. In Euler s method we assuming that the slope across the interval [t n ;t n +t]=[t n ;t n+1 ] is what it is at t n. Of course it is not true, but it is very roughly OK.

7 Numerical methods of solution 7 y =1 y=0 After we have taken one step of Euler s method, we can tell to what extent the assumption on the slope was false, by comparing the slope of the segment coming from the left at (t n+1 ;y n+1 ) with the value f (T n+1 ;y n+1 ) that it ought now to be. The new method will use this idea to get a better estimate for the slope across the interval [t n ;t n+1 ]. One step of the new method goes like this: Start at t n with the estimate y n. Do one step of Euler s method to get an approximate value y = y n +F(t n ;y n ) for y n+1. Calculate what the slope should now be at the point (t n+1 ;y ). It should be f (x n+1 ;y ) We now make a modified guess as to what the slope across [t n ;t n+1 ] should have been by taking the average of these values f (t n ;y n )and f (t n+1 ;y ). In other words In one step of the new method we calculate the sequence This is in contrast with one step of Euler s: s 0 = F (x n ;y n ) y =y n +s 0 x n+1 = x n + s 1 =F(x n+1 ;y ) y n+1 = y n +h s0 +s 1 2 s 0 = F (x n ;y n ) y n+1 = y n +s 0 x n+1 = x n + In the new method, we are doing essentially twice as much work in one step, but it should be a somewhat more accurate. It is, and dramatically so. Let s see, for example, how the new method, which is called the improved Euler s method, does with the simple problem y 0 = y t; y(0) = 0:5 we looked at before. Here is how one run of the new method goes in covering the interval [0; 1] in 4 steps: i

8 Numerical methods of solution 8 t y s 0 y s 1 0:00 0: : : : :25 0: : : : :50 0: : : : :75 0: : : : :00 0: And here is how the estimates for y(1) compare for different step sizes: N estimated y(1) true y(1) error 2 0: : : : ::: 0: : ::: 0: : ::: 0: : ::: 0: : ::: 0: : ::: 0: : ::: 0: : ::: 0: : : : Halving the step size here cuts down the error by a factor of 4. This suggests: The error in the improved Euler s method is proportional to 2. The new method, which is called either the improved Euler s method or the Runge-Kutta method of order 2, is much more efficient than Euler s. If it takes N intervals to get 2 decimal accuracy, it will take 10 N to get 4 decimals, 100 N to get 6 (as opposed to N in Euler s method). Very roughly, to get accuracy of " it takes 1= p " steps. 7. Relations with numerical calculation of integrals If y is a solution of y 0 (t) =f(t; y(t)) then for any interval [t n ;t n+1 ] with t n+1 = t n +twe can integrate to get y(t n+1 ) y(t n )= Z tn+1 tn f (t; y(t)) dt : This does not amount to a formula for y(t n+1 ) in terms of y(t n ) because the right hand side involves the unknown function y(t) throughout the interval [t n ;t n+1 ]. In order to get from it an estimate for y(t n+1 ) we must use some sort of approximation for the integral. In Euler s method we set Z tn+1 tn f (t; y(t)) dt : = f (t n ;y(t n )) t : We then replace y(t n ) by its approximate value y n to see how one step of Euler s method goes. In the special case where f (t; y) =f(t)does not depend on y, the solution of the differential equation & initial condition y 0 = f (t); y(t 0 )=y 0 is given by a definite integral y(t n )=y 0 + Z tn t 0 f(t)dt

9 Numerical methods of solution 9 and Euler s method is equivalent to the rectangle rule for estimating the integral numerically. Recall that the rectangle rule approximates the graph of f (t) by a sequence of horizontal lines, each one agreeing with the value of f (t) at its left end. In this special case it is simple to see geometrically why the overall error is roughly proportional to the step size. In the improved Euler s method we approximate the integral Z tn+1 by the trapezoid rule, which uses the estimate t tn f (t; y(t)) dt 2 [f (t n;y(t n )) + f (t n+1 ;y(t n+1 ))] for it. We don t know the exact values of y(t n ) or y(t n+1 ), but we approximate them by the values y n and y n +tf(t n ;y n ). In the special case f (t; y) =f(t)the improved Euler s method reduces exactly to the trapezoid rule. Again, it is easy to visualize why the error over a fixed interval is proportional to the square of the step size. 8. Runge-Kutta Neither of the two methods discussed so far is used much in practice. The simplest method which is in fact practical is one called Runge-Kutta method of order 4. It involves a more complicated sequence of calculations in each step. Let be the step size. We calculate in succession:

10 Numerical methods of solution 10 y = y n +h i s 2 x = x +h i 2 s = f (x ;y ) y = y n +h i s 2 s = f (x ;y ) x n+1 = x + y = y n +s s = f (x n+1 ;y ) y n+1 = y n +h s +2s +2s + s 6 The purpose of using here is that the numbers like y etc. are not of interest beyond the immediate calculation they are involved in. You wouldn t want to do this by hand, but again it is not too bad for a spread sheet. Here is a table of the calculations for y 0 = y t; y(0) = 0:5 with 4 steps. t y s y s y s y s 0:00 0: : : : : : : : :25 0: : : : : : : : :50 0: : : : : : : : :75 0: : : : : : : : :00 0: And here is how the estimates for y(1) compare for different step sizes. The method is so accurate that we must use nearly all the digits of accuracy possible: N estimated y(1) true y(1) error 2 0: : : : ::: 0: : ::: 0: : ::: 0: : ::: 0: : ::: 0: : ::: 0: : ::: 0: : ::: 0: : : : Here halving the step size reduces the error by a factor of 16. This suggests: The error in RK4 is proportional to 4. i

11 Numerical methods of solution 11 Euler s method and the improved Euler s method arise from using the rectangle rule and the trapezoid rule for estimating the integral Z tn+1 tn f (t; y(t)) dt : RK4 uses a variant of Simpson s Rule for calculating integrals and reduces to it in the special case when f (t; y) doesn t depend on y. 9. Remarks on how to do the calculations When implementing these by hand, which you might have to do every now and then, you should set the calculations out neatly in tables. Here is what it might look like for the improved Euler s method applied to the differential equation y 0 =2xy 1 with step size =0:1. etc. x y s =f(x; y) y = y +s s = f (x +;y ) 0: : : : : : : : : : : : : : : Of course this is redundant and tedious work, and ideally suited to a computer. You can transfer the idea of tables to a spread sheet without much trouble. And here is a simple Pascal program to implement Euler s method for the same differential equation. program euler; var x, y, xf, h: real; i, N : integer; function f(x, y:real): real; begin f := 2*x*y - 1; end; function next_y(x, y, h: real):real; begin next_y := y + h*f(x, y); end; begin x := 0.0; xf := 1.0; y := 1.0; N := 10; h := (xf - x)/n; for i := 1 to N do begin writeln(x:8:6,, y:8:6); y := next_y(x, y, h); x:=x+h; end; writeln(x:8:6,, y:8:6);

12 Numerical methods of solution 12 end. This is very convenient, because to change the differential equation involves very little change in the program (but it does involve recompiling). 10. How to estimate the error When you set out to approximate the solution of a differential equation y 0 = f (x; y) by a numerical method, you are given initial conditions y(x 0 )=y 0 and a range of values [x 0 ;x f ] (f for final ) over which you want to approximate the solution. The particular numerical method you are going to use is usually specified in advance, and your major choice is then to choose the step size the increment by which x changes in each step of the method. The basic idea is that if you choose a small step size your approximation will be closer to the true solution, but at the cost of a larger number of steps. What is the exact relationship between step size and accuracy? We have discussed this already to some extent, but now we shall look at the question again. Some explicit data can give you a feel for how things go. Here is the outcome of several runs of Euler s method for solving the equation over the interval [0; 1]. y 0 =2xy 1; y(0) = 1 Number of steps Step size Estimated value of y(1) This table suggests that if we keep making the step size smaller, then the approximations to y(1) will converge to something, but does not give a good idea, for example, of how many steps we would need to take if we wanted an answer correct to 4 decimals. To get this we need some idea of how rapidly the estimates are converging. The way to do this most easily is to add a column to record the difference between an estimate and the previous one. Number of steps Step size Estimated value of y(1) Difference from previous estimate

13 Numerical methods of solution 13 The pattern in the last column is simple. Eventually, the difference gets cut in half at each line. This means that at least when h is small, the difference is roughly proportional to the step size. Thus we can extrapolate entries in the last column to be 0:000674; 0:000337; 0:000169; 0:000084; :::: But the total error should be the sum of all these differences, which can be written as 0: (1=2+1=4+1=8+1=16 + :::)=0:001348! It is not in fact necessary to look at a whole sequence of runs. We can summarize the discussion more simply: if we make two runs of Euler s method, the error in the second of the two estimates for y(x f ) will be (roughly) the size of the difference between the two estimates. The reason the error can be estimated in this way is because the error in Euler s method is proportional to the step size. Suppose we have made two runs of the method, one with step size h and another with step size h=2. Then because of the proportionality, and the meaning of error, we know that true answer : = estimate h + Ch true answer : = estimate h=2 + C(h=2) for some constant C. Here estimate h means the estimate corresponding to step size h. If we treat the approximate equalities as equalities, we get two equations in the two unknowns true answer and C. We can solve them to get true answer : =2estimate h=2 estimate h = estimate h=2 +(estimate h=2 estimate h ) error in estimate h=2 : = estimate h=2 estimate h In other words, one run of Euler s method will tell us virtually nothing about how accurate the run is, but two runs will allow us to get an idea of the error and an improved estimate for the value of y(x f ) as well. The same is true for any of the other methods, since we know that in each case the error is roughly proportional to some power of h for improved Euler s it is h 2 and for RK4 it is h 4. In general, if the error is proportional to h k and we make two runs of step size h and h=2 we get and subtract getting true answer : = estimate h + Ch k true answer : = estimate h=2 + C(h=2) k 2 k true answer : =2 k estimate h=2 + Ch k and finally: (2 k 1) true answer : =2 k estimate h=2 estimate h true answer = : 2k estimate h=2 estimate h 2 k 1 = estimate h=2 + estimate h=2 estimate h 2 k 1 If you do one run with step size h and another of size h=2 with a method of order k then error in estimate h=2 : = estimate h=2 estimate h 2 k 1 true answer : = estimate h=2 + error in estimate h=2

14 Numerical methods of solution 14 The earlier formula is the special case of this with k = Step size choice When we use one of the numerical methods to approximate the solution of the differential equation, we usually have ahead of time some idea of how accurate we want the approximation to be to within 6 or 7 decimals of accuracy, say. The question is, how can we choose the step size in order to obtain this accuracy? The discussion above suggests the following procedure: Make two runs of the method over the given range, with step size h and then with step size h=2. We get two estimates for y(x f ), estimate h and estimate h=2. If the method has error proportional to h k (i.e. if the error is of order k) then we know that the error in estimate h is approximately error in estimate h : = estimate h estimate h=2 1 2 k : If we multiply the step size by we multiply the error by k, so if we want an error of about : Solve this equation to get the new step size h : h k = h error in estimate h h = h error in estimate h 1=k The procedure looks tedious, but plausible: we choose some initial step size h which we judge (arbitrarily) to be reasonable. We do two runs at step sizes h and h=2 to see how accuracy depends on step size (to get the constant of proportionality). We then calculate the step size h needed to get the accuracy we want, and do a third run at the new size. Example. Here is a typical question: In solving the differential equation y 0 = xy +1; y(0) = 1 by RK4, with step sizes 0:0625 and 0:03125, the estimates 3: and 3: for y(1) were calculated. (a) Make an estimate of the error involved in these calculated values. (b) What step size should be chosen to obtain 16-decimal accuracy? One thing to notice is that we don t need to know at all what the differential equation is, or even the exact method used. The only important thing to know is the order of the method used, which is k =4. We set y 1 =3: y 2 =3: The formula for the error in the second value, say, is simple. We estimate it to be y 2 y 1 2 k 1 = 0: = 0: To figure out what step size to use to get a given accuracy, we must know how the error will depend on step size. It is c 4

15 Numerical methods of solution 15 for some constant c, where is the step size. In the second run the step size is 0:03125, so we estimate 0: c = (0:03125) 4 =0: To get the step size we want we solve 10 c 4 =0: = =4 ; = = : :3017 =0: Summary of the numerical methods introduced so far We have seen three different methods of solving differential equations by numerical approximation. In choosing among them there is a trade-off between simplicity and efficiency. Euler s method is relatively simple to understand and to program, for example, but almost hopelessly inefficient. The third and final method, the order 4 method of Runge-Kutta, is very efficient but rather difficult to understand and even to program. The improved Euler s method lies somewhere in between these two on both grounds. Each one produces a sequence of approximations to the solution over a range of x-values, and proceeds from an approximation of y at one value of x to an approximation at the next in one more or less complicated step. In each method one step goes from x n to x n+1 = x n +. The methods differ in how the step from y n to y n+1 is performed. More efficient single steps come about at the cost of higher complexity for one step. But for a given desired accuracy, the overall savings in time is good. Method The step from (x n ;y n )to (x n+1 ;y n+1 ) Overall error Euler s s = f (x n ;y n ) proportional to y n+1 = y n +s x n+1 = x n + improved Euler s s = f (x n ;y n ) proportional to 2 (RK of order 2) y = y n +s x n+1 = x n + s = f (x n+1 ;y ) y n+1 = y n +h s +s 2 y = y n +h i 2i Runge-Kutta of order 4 s = f (x n ;y n ) proportional to 4 s h x = x + 2 s = f (x ;y ) y = y n +h 2 s = f (x ;y ) x n+1 = x + i s i y = y n +s s = f (x n+1 ;y ) y n+1 = y n +h s +2s +2s + s 6 i

16 Numerical methods of solution 16 In practice, of course, you cannot expect to do several steps of any of these methods except by computer. You should, however, understand how to one step of each of them; how to estimate errors in using them; how to use error estimates to choose efficient step sizes. Numerical methods are often in practice the only way to solve a differential equation. They can be of amazing accuracy, and in fact the methods we have described here are not too different from those used to send space vehicles on incredibly long voyages. But often, too, in practice you want some overall idea about how solutions of a differential equation behave, in addition to precise numerical values. There is no automatic way of obtaining this. In all these methods, one of the main problems is to choose the right step size. The basic principle in doing this is that: Two runs of any method will let you estimate the error in the calculation, as well as decide what step size to use in order to get the accuracy you require. 13. The problem of stability Although we shall not show how to solve it, we want to point out here a problem which, although somewhat technical, does cause some trouble in practice. First consider the equation & initial conditions y 0 = c y=; y(0) = 0 : This is linear with constant coefficients and has the exact solution y = c ce t= = c (1 e t= ) : Assume that > 0. Then this is the sum of two terms. One is the constant c and the other is exponentially decaying. The rate of decay the time it takes to reduce any fixed factor, for example is proportional to. The quantity is called the relaxation time of the equation, and when it is short the function y reaches equilibrium or relaxes quickly. Solve this by Euler s method with step size. We get t 0 =0 y 0 =0 t n+1 = t n + c y n+1 = y n +(c y n = ) = c +y n (1 = ) The problem is that we can get some rather strange behaviour if is not chosen carefully. Here is the graph we get with not quite small enough.

17 Numerical methods of solution 17 Figure The behaviour of Euler s method for a stiff equation with threshold step size. You can see what happens all the solutions move very rapidly towards the equlibrium, and this means that their slopes are very steep not too far from the equilibrium solution. You have to take very small steps in Euler s method to take this into account. Here is what happens when is just a bit smaller. The process does converge, but very slowly. Figure The behaviour of Euler s method for a stiff equation with step size barely below threshold. We can explain more precisely what we see. Let =1 = for convenience. Then y 0 =0 y 1 =c y 2 =c(1 + ) y 3 = c ( ) y n = c ( n 1 ) Now as n!1this is supposed to converge to c, just like the exact solution. This can t possibly happen unless jj < 1 or j1 =j < 1 Since and are both positive, j1 =j < 1 means that 1 = > 1; < 2 If this condition does not hold then 1 = < 1 and the numbers y n will just oscillate back and forth with larger and larger swings. In particular, when the relaxation time is relatively small we must choose the step size small also if Euler s method is to make any sense. This is a paradoxical situation. When is small then the true solution will be just a constant for all large values of t, the simplest possible sort of behaviour. But we must still make very small steps in order to have Euler s method produce reasonable numbers. This means that we will be working very hard to produce a lot of apparently simple data. Unfortunately, this sort of thing is fairly common in real-life situations whenever there are components of a physical system whose change takes place on scales widely different. Here the two components undergo no change and rapid decay. Such systems are said to be stiff. The idea is that in trying to apply Euler s method to the system we have to make small steps in order to keep the rapidly changing part from causing our calculation to vary wildly, even though it is only the slowest changing parts we can actually measure. How can we do better?

18 Numerical methods of solution 18 This is a complicated topic. There is a simple way to take care of the difficulty in the case of Euler s method which does suggest how to proceed in general. We perform something called the backward Euler s method. The forward Euler s method (the one we are familiar with) assumes the slope across a time segment to be what it is at the beginning: y n+1 = y n +f(t n ;y n ) The backward one sets y n+1 = y n +f(t n+1 ;y n+1 ) Of course this doesn t give an immediate expression for y n+1 since it occurs on both sides. The equation has to be solved for y n+1. In the example above we get y n+1 = y n + (1 y n+1 = ) y n+1 = y n + 1+= which will always converge as long since and are positive. Note that when = is small so the new rule and the old one are consistent. 1 1+= : =1 = Each of the other methods we have seen has backwards versions too. 14. Rounding errors Computers can only deal with numbers of limited accuracy, normally about 16 digits of precision. They cannot calculate even the product and sums of numbers exactly, much less calculate the exact values of functions like sin. Errors in computations due to this limited accuracy are called rounding errors. Rounding errors are not usually a problem in the methods we have seen, except in the circumstance where Euler s method is used to obtain extremely high accuracy, in which case it will require enough steps for serious error to build up. But then Euler s method should never be used for high accuracy anyway. There is one circumstance, however, in which there will be a problem. Consider this differential equation: y 0 = cos t y; y(0) = y 0 The general solution is y = (sin t cos t)=2+(y 0 +1=2)e ct Suppose c>0. Then whenever y 0 6= 1=2 the solution will grow exponentially. In the exceptional case y 0 =1=2 it will simply oscillate. Here, however, is the graph of a good numerical aproximation matching initial condition y(0) = 1=2:

19 Numerical methods of solution 19 Figure How rounding errors affect the calculations for a stiff equation. Rounding errors are inevitably made at some point in almost any computer calculation, and as soon as that happens the estimated y(x) will make an almost certainly irreversible move from the graph of the unique bounded solution to one of the nearby ones with exponential growth. From that point on it must grow unbounded, no matter how well it has looked so far. This is not a serious problem in the following sense: in the real world, we can never measure initial conditions exactly, so that we can never be sure to hit the one bounded solution exactly. Nor can nature. Since the bounded solution is unstable in the sense that nearby solution eventually diverge considerably from it, we should not expect to meet with it in physical problems. Unstable solutions do not realistically occur in nature. Rounding errors simulate the approximate nature of our measurements. Another way to say this: Because of rounding errors, the best we can hope to do with machine computations is to find the exact answer to a problem near to the one that is originally posed.

20 Appendix: Euler s method in C 20 Appendix. Euler s method in C Below is a complete program in C to implement Euler s method for the equation y 0 = y. It includes routines to scan the command line to read values of x 0, x f, y 0, N. It also prints out the run data as the run proceeds. In order to change this program to handle another differential equation, only the function f (x; y) has to be changed, and the program recompiled. #include <stdio.h> #include <math.h> /* global variables */ double xinit, xf, yinit; int N; /* function f(x, y) */ double f(x, y) double x, y; { } return(y); /* options */ void usage() { } fprintf(stderr, "usage: exit(1); euler -xi <xinit> -xf <xf> -yi <yinit> -N <N>\n"); #define OPTNO 4 enum {Optxinit, Optxf, Optyinit, OptN}; char opt_string[][16] = {"-xi", "-xf", "-yi", "-N"}; int get_opt(s) char *s; { } int i; for (i=0;i<optno;i++) { if (strcmp(s, opt_string[i]) == 0) return(i); } fprintf(stderr, "Invalid option [%s]\n", s); usage(); double atof();

21 Appendix: Euler s method in C 21 int read_command_line(argc, argv) int argc; char **argv; { int opt; char *a; argv++; argc--; } while (argc > 0) { opt = get_opt(a = *argv++); argc--; switch(opt) { case Optxinit: a = *argv++; argc--; xinit = atof(a); break; case Optxf: a = *argv++; argc--; xf = atof(a); break; case Optyinit: a = *argv++; argc--; yinit = atof(a); break; case OptN: a = *argv++; argc--; N = atof(a); break; default: usage(); } } /* */ main(argc, argv) int argc; char **argv; { int i; double x, y, h; if (argc > 1) {

22 Appendix: Euler s method in C 22 } read_command_line(argc, argv); } else { usage(); } x = xinit; y = yinit; h = (xf - xinit)/((double) N); for (i=0;i<n;i++) { printf("%8.6lf %8.6lf\n", x, y); y=y+h*f(x, y); x=x+h; } printf("%8.6lf %8.6lf\n", x, y); exit(0);

4 Visualization and. Approximation

4 Visualization and. Approximation 4 Visualization and Approximation b A slope field for the differential equation y tan(x + y) tan(x) tan(y). It is not always possible to write down an explicit formula for the solution to a differential

More information

Drawing curves automatically: procedures as arguments

Drawing curves automatically: procedures as arguments CHAPTER 7 Drawing curves automatically: procedures as arguments moveto lineto stroke fill clip The process of drawing curves by programming each one specially is too complicated to be done easily. In this

More information

The Bisection Method versus Newton s Method in Maple (Classic Version for Windows)

The Bisection Method versus Newton s Method in Maple (Classic Version for Windows) The Bisection Method versus (Classic Version for Windows) Author: Barbara Forrest Contact: baforres@uwaterloo.ca Copyrighted/NOT FOR RESALE version 1.1 Contents 1 Objectives for this Lab i 2 Approximate

More information

Euler s Method for Approximating Solution Curves

Euler s Method for Approximating Solution Curves Euler s Method for Approximating Solution Curves As you may have begun to suspect at this point, time constraints will allow us to learn only a few of the many known methods for solving differential equations.

More information

over The idea is to construct an algorithm to solve the IVP ODE (9.1)

over The idea is to construct an algorithm to solve the IVP ODE (9.1) Runge- Ku(a Methods Review of Heun s Method (Deriva:on from Integra:on) The idea is to construct an algorithm to solve the IVP ODE (9.1) over To obtain the solution point we can use the fundamental theorem

More information

Unit 1 Chapter 4 ITERATIVE ALGORITHM DESIGN ISSUES

Unit 1 Chapter 4 ITERATIVE ALGORITHM DESIGN ISSUES DESIGN AND ANALYSIS OF ALGORITHMS Unit 1 Chapter 4 ITERATIVE ALGORITHM DESIGN ISSUES http://milanvachhani.blogspot.in USE OF LOOPS As we break down algorithm into sub-algorithms, sooner or later we shall

More information

Direction Fields; Euler s Method

Direction Fields; Euler s Method Direction Fields; Euler s Method It frequently happens that we cannot solve first order systems dy (, ) dx = f xy or corresponding initial value problems in terms of formulas. Remarkably, however, this

More information

4.7 Approximate Integration

4.7 Approximate Integration 4.7 Approximate Integration Some anti-derivatives are difficult to impossible to find. For example, 1 0 e x2 dx or 1 1 1 + x3 dx We came across this situation back in calculus I when we introduced the

More information

DESIGN AND ANALYSIS OF ALGORITHMS. Unit 1 Chapter 4 ITERATIVE ALGORITHM DESIGN ISSUES

DESIGN AND ANALYSIS OF ALGORITHMS. Unit 1 Chapter 4 ITERATIVE ALGORITHM DESIGN ISSUES DESIGN AND ANALYSIS OF ALGORITHMS Unit 1 Chapter 4 ITERATIVE ALGORITHM DESIGN ISSUES http://milanvachhani.blogspot.in USE OF LOOPS As we break down algorithm into sub-algorithms, sooner or later we shall

More information

COMP 161 Lecture Notes 16 Analyzing Search and Sort

COMP 161 Lecture Notes 16 Analyzing Search and Sort COMP 161 Lecture Notes 16 Analyzing Search and Sort In these notes we analyze search and sort. Counting Operations When we analyze the complexity of procedures we re determine the order of the number of

More information

Computer Science 210 Data Structures Siena College Fall Topic Notes: Searching and Sorting

Computer Science 210 Data Structures Siena College Fall Topic Notes: Searching and Sorting Computer Science 10 Data Structures Siena College Fall 016 Topic Notes: Searching and Sorting Searching We all know what searching is looking for something. In a computer program, the search could be:

More information

Math 182. Assignment #4: Least Squares

Math 182. Assignment #4: Least Squares Introduction Math 182 Assignment #4: Least Squares In any investigation that involves data collection and analysis, it is often the goal to create a mathematical function that fits the data. That is, a

More information

Reals 1. Floating-point numbers and their properties. Pitfalls of numeric computation. Horner's method. Bisection. Newton's method.

Reals 1. Floating-point numbers and their properties. Pitfalls of numeric computation. Horner's method. Bisection. Newton's method. Reals 1 13 Reals Floating-point numbers and their properties. Pitfalls of numeric computation. Horner's method. Bisection. Newton's method. 13.1 Floating-point numbers Real numbers, those declared to be

More information

What Every Programmer Should Know About Floating-Point Arithmetic

What Every Programmer Should Know About Floating-Point Arithmetic What Every Programmer Should Know About Floating-Point Arithmetic Last updated: October 15, 2015 Contents 1 Why don t my numbers add up? 3 2 Basic Answers 3 2.1 Why don t my numbers, like 0.1 + 0.2 add

More information

Basics of Computational Geometry

Basics of Computational Geometry Basics of Computational Geometry Nadeem Mohsin October 12, 2013 1 Contents This handout covers the basic concepts of computational geometry. Rather than exhaustively covering all the algorithms, it deals

More information

Ordinary differential equations solving methods

Ordinary differential equations solving methods Radim Hošek, A07237 radhost@students.zcu.cz Ordinary differential equations solving methods Problem: y = y2 (1) y = x y (2) y = sin ( + y 2 ) (3) Where it is possible we try to solve the equations analytically,

More information

(Refer Slide Time: 00:02:02)

(Refer Slide Time: 00:02:02) Computer Graphics Prof. Sukhendu Das Dept. of Computer Science and Engineering Indian Institute of Technology, Madras Lecture - 20 Clipping: Lines and Polygons Hello and welcome everybody to the lecture

More information

Lesson 6: Manipulating Equations

Lesson 6: Manipulating Equations Lesson 6: Manipulating Equations Manipulating equations is probably one of the most important skills to master in a high school physics course. Although it is based on familiar (and fairly simple) math

More information

Using Excel for Graphical Analysis of Data

Using Excel for Graphical Analysis of Data Using Excel for Graphical Analysis of Data Introduction In several upcoming labs, a primary goal will be to determine the mathematical relationship between two variable physical parameters. Graphs are

More information

Lab 4. Recall, from last lab the commands Table[], ListPlot[], DiscretePlot[], and Limit[]. Go ahead and review them now you'll be using them soon.

Lab 4. Recall, from last lab the commands Table[], ListPlot[], DiscretePlot[], and Limit[]. Go ahead and review them now you'll be using them soon. Calc II Page 1 Lab 4 Wednesday, February 19, 2014 5:01 PM Recall, from last lab the commands Table[], ListPlot[], DiscretePlot[], and Limit[]. Go ahead and review them now you'll be using them soon. Use

More information

Computer Graphics Prof. Sukhendu Das Dept. of Computer Science and Engineering Indian Institute of Technology, Madras Lecture - 14

Computer Graphics Prof. Sukhendu Das Dept. of Computer Science and Engineering Indian Institute of Technology, Madras Lecture - 14 Computer Graphics Prof. Sukhendu Das Dept. of Computer Science and Engineering Indian Institute of Technology, Madras Lecture - 14 Scan Converting Lines, Circles and Ellipses Hello everybody, welcome again

More information

Introduction to Programming, Aug-Dec 2008

Introduction to Programming, Aug-Dec 2008 Introduction to Programming, Aug-Dec 2008 Lecture 1, Monday 4 Aug 2008 Administrative matters Resource material Textbooks and other resource material for the course: The Craft of Functional Programming

More information

Section 1.5 Transformation of Functions

Section 1.5 Transformation of Functions Section 1.5 Transformation of Functions 61 Section 1.5 Transformation of Functions Often when given a problem, we try to model the scenario using mathematics in the form of words, tables, graphs and equations

More information

6.001 Notes: Section 4.1

6.001 Notes: Section 4.1 6.001 Notes: Section 4.1 Slide 4.1.1 In this lecture, we are going to take a careful look at the kinds of procedures we can build. We will first go back to look very carefully at the substitution model,

More information

Graphical Analysis of Data using Microsoft Excel [2016 Version]

Graphical Analysis of Data using Microsoft Excel [2016 Version] Graphical Analysis of Data using Microsoft Excel [2016 Version] Introduction In several upcoming labs, a primary goal will be to determine the mathematical relationship between two variable physical parameters.

More information

MATH2071: LAB 2: Explicit ODE methods

MATH2071: LAB 2: Explicit ODE methods MATH2071: LAB 2: Explicit ODE methods 1 Introduction Introduction Exercise 1 Euler s method review Exercise 2 The Euler Halfstep (RK2) Method Exercise 3 Runge-Kutta Methods Exercise 4 The Midpoint Method

More information

8 Piecewise Polynomial Interpolation

8 Piecewise Polynomial Interpolation Applied Math Notes by R. J. LeVeque 8 Piecewise Polynomial Interpolation 8. Pitfalls of high order interpolation Suppose we know the value of a function at several points on an interval and we wish to

More information

9.1 Solutions, Slope Fields, and Euler s Method

9.1 Solutions, Slope Fields, and Euler s Method Math 181 www.timetodare.com 9.1 Solutions, Slope Fields, and Euler s Method In-class work: Model of Population Growth One model for the growth of a population is based on the assumption that the population

More information

Section 1.5 Transformation of Functions

Section 1.5 Transformation of Functions 6 Chapter 1 Section 1.5 Transformation of Functions Often when given a problem, we try to model the scenario using mathematics in the form of words, tables, graphs and equations in order to explain or

More information

Divisibility Rules and Their Explanations

Divisibility Rules and Their Explanations Divisibility Rules and Their Explanations Increase Your Number Sense These divisibility rules apply to determining the divisibility of a positive integer (1, 2, 3, ) by another positive integer or 0 (although

More information

Math 133A, September 10: Numerical Methods (Euler & Runge-Kutta) Section 1: Numerical Methods

Math 133A, September 10: Numerical Methods (Euler & Runge-Kutta) Section 1: Numerical Methods Math 133A, September 10: Numerical Methods (Euler & Runge-Kutta) Section 1: Numerical Methods We have seen examples of first-order differential equations which can, by one method of another, be solved

More information

MTH 122 Calculus II Essex County College Division of Mathematics and Physics 1 Lecture Notes #11 Sakai Web Project Material

MTH 122 Calculus II Essex County College Division of Mathematics and Physics 1 Lecture Notes #11 Sakai Web Project Material MTH Calculus II Essex County College Division of Mathematics and Physics Lecture Notes # Sakai Web Project Material Introduction - - 0 - Figure : Graph of y sin ( x y ) = x cos (x + y) with red tangent

More information

lecture notes September 2, How to sort?

lecture notes September 2, How to sort? .30 lecture notes September 2, 203 How to sort? Lecturer: Michel Goemans The task of sorting. Setup Suppose we have n objects that we need to sort according to some ordering. These could be integers or

More information

Design and Analysis of Algorithms Prof. Madhavan Mukund Chennai Mathematical Institute. Week 02 Module 06 Lecture - 14 Merge Sort: Analysis

Design and Analysis of Algorithms Prof. Madhavan Mukund Chennai Mathematical Institute. Week 02 Module 06 Lecture - 14 Merge Sort: Analysis Design and Analysis of Algorithms Prof. Madhavan Mukund Chennai Mathematical Institute Week 02 Module 06 Lecture - 14 Merge Sort: Analysis So, we have seen how to use a divide and conquer strategy, we

More information

Computer Science 252 Problem Solving with Java The College of Saint Rose Spring Topic Notes: Searching and Sorting

Computer Science 252 Problem Solving with Java The College of Saint Rose Spring Topic Notes: Searching and Sorting Computer Science 5 Problem Solving with Java The College of Saint Rose Spring 016 Topic Notes: Searching and Sorting Searching We all know what searching is looking for something. In a computer program,

More information

y= sin( x) y= cos( x)

y= sin( x) y= cos( x) . The graphs of sin(x) and cos(x). Now I am going to define the two basic trig functions: sin(x) and cos(x). Study the diagram at the right. The circle has radius. The arm OP starts at the positive horizontal

More information

Mathematics for chemical engineers

Mathematics for chemical engineers Mathematics for chemical engineers Drahoslava Janovská Department of mathematics Winter semester 2013-2014 Numerical solution of ordinary differential equations Initial value problem Outline 1 Introduction

More information

Table of Laplace Transforms

Table of Laplace Transforms Table of Laplace Transforms 1 1 2 3 4, p > -1 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 Heaviside Function 27 28. Dirac Delta Function 29 30. 31 32. 1 33 34. 35 36. 37 Laplace Transforms

More information

Euler s Methods (a family of Runge- Ku9a methods)

Euler s Methods (a family of Runge- Ku9a methods) Euler s Methods (a family of Runge- Ku9a methods) ODE IVP An Ordinary Differential Equation (ODE) is an equation that contains a function having one independent variable: The equation is coupled with an

More information

Objectives. Materials

Objectives. Materials Activity 13 Objectives Understand what a slope field represents in terms of Create a slope field for a given differential equation Materials TI-84 Plus / TI-83 Plus Graph paper Introduction One of the

More information

Week - 04 Lecture - 01 Merge Sort. (Refer Slide Time: 00:02)

Week - 04 Lecture - 01 Merge Sort. (Refer Slide Time: 00:02) Programming, Data Structures and Algorithms in Python Prof. Madhavan Mukund Department of Computer Science and Engineering Indian Institute of Technology, Madras Week - 04 Lecture - 01 Merge Sort (Refer

More information

over The idea is to construct an algorithm to solve the IVP ODE (8.1)

over The idea is to construct an algorithm to solve the IVP ODE (8.1) Runge- Ku(a Methods Review of Heun s Method (Deriva:on from Integra:on) The idea is to construct an algorithm to solve the IVP ODE (8.1) over To obtain the solution point we can use the fundamental theorem

More information

An interesting related problem is Buffon s Needle which was first proposed in the mid-1700 s.

An interesting related problem is Buffon s Needle which was first proposed in the mid-1700 s. Using Monte Carlo to Estimate π using Buffon s Needle Problem An interesting related problem is Buffon s Needle which was first proposed in the mid-1700 s. Here s the problem (in a simplified form). Suppose

More information

Background for Surface Integration

Background for Surface Integration Background for urface Integration 1 urface Integrals We have seen in previous work how to define and compute line integrals in R 2. You should remember the basic surface integrals that we will need to

More information

Lecture 3: Linear Classification

Lecture 3: Linear Classification Lecture 3: Linear Classification Roger Grosse 1 Introduction Last week, we saw an example of a learning task called regression. There, the goal was to predict a scalar-valued target from a set of features.

More information

Design and Analysis of Algorithms Prof. Madhavan Mukund Chennai Mathematical Institute

Design and Analysis of Algorithms Prof. Madhavan Mukund Chennai Mathematical Institute Design and Analysis of Algorithms Prof. Madhavan Mukund Chennai Mathematical Institute Module 07 Lecture - 38 Divide and Conquer: Closest Pair of Points We now look at another divide and conquer algorithm,

More information

Chapter Fourteen Bonus Lessons: Algorithms and Efficiency

Chapter Fourteen Bonus Lessons: Algorithms and Efficiency : Algorithms and Efficiency The following lessons take a deeper look at Chapter 14 topics regarding algorithms, efficiency, and Big O measurements. They can be completed by AP students after Chapter 14.

More information

Linear and quadratic Taylor polynomials for functions of several variables.

Linear and quadratic Taylor polynomials for functions of several variables. ams/econ 11b supplementary notes ucsc Linear quadratic Taylor polynomials for functions of several variables. c 016, Yonatan Katznelson Finding the extreme (minimum or maximum) values of a function, is

More information

Chapter One. Numerical Algorithms

Chapter One. Numerical Algorithms Chapter One Numerical Algorithms The word algorithm derives from the name of the Persian mathematician (Abu Ja far Muhammad ibn Musa) Al- Khwarizmi who lived from about 790 CE to about 840 CE. He wrote

More information

Numerical Integration

Numerical Integration 1 Numerical Integration Jim Van Verth Insomniac Games jim@essentialmath.com Essential mathematics for games and interactive applications Talk Summary Going to talk about: Euler s method subject to errors

More information

Algorithms and Data Structures

Algorithms and Data Structures Algorithms and Data Structures Spring 2019 Alexis Maciel Department of Computer Science Clarkson University Copyright c 2019 Alexis Maciel ii Contents 1 Analysis of Algorithms 1 1.1 Introduction.................................

More information

ODE IVP. An Ordinary Differential Equation (ODE) is an equation that contains a function having one independent variable:

ODE IVP. An Ordinary Differential Equation (ODE) is an equation that contains a function having one independent variable: Euler s Methods ODE IVP An Ordinary Differential Equation (ODE) is an equation that contains a function having one independent variable: The equation is coupled with an initial value/condition (i.e., value

More information

Partial Derivatives (Online)

Partial Derivatives (Online) 7in x 10in Felder c04_online.tex V3 - January 21, 2015 9:44 A.M. Page 1 CHAPTER 4 Partial Derivatives (Online) 4.7 Tangent Plane Approximations and Power Series It is often helpful to use a linear approximation

More information

(Refer Slide Time: 1:27)

(Refer Slide Time: 1:27) Data Structures and Algorithms Dr. Naveen Garg Department of Computer Science and Engineering Indian Institute of Technology, Delhi Lecture 1 Introduction to Data Structures and Algorithms Welcome to data

More information

Generating Functions

Generating Functions 6.04/8.06J Mathematics for Computer Science Srini Devadas and Eric Lehman April 7, 005 Lecture Notes Generating Functions Generating functions are one of the most surprising, useful, and clever inventions

More information

ECE 610: Homework 4 Problems are taken from Kurose and Ross.

ECE 610: Homework 4 Problems are taken from Kurose and Ross. ECE 610: Homework 4 Problems are taken from Kurose and Ross. Problem 1: Host A and B are communicating over a TCP connection, and Host B has already received from A all bytes up through byte 248. Suppose

More information

Intro to Algorithms. Professor Kevin Gold

Intro to Algorithms. Professor Kevin Gold Intro to Algorithms Professor Kevin Gold What is an Algorithm? An algorithm is a procedure for producing outputs from inputs. A chocolate chip cookie recipe technically qualifies. An algorithm taught in

More information

Problem Solving through Programming In C Prof. Anupam Basu Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur

Problem Solving through Programming In C Prof. Anupam Basu Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur Problem Solving through Programming In C Prof. Anupam Basu Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur Lecture 15 Branching : IF ELSE Statement We are looking

More information

Section 1.5 Transformation of Functions

Section 1.5 Transformation of Functions Section.5 Transformation of Functions 6 Section.5 Transformation of Functions Often when given a problem, we try to model the scenario using mathematics in the form of words, tables, graphs and equations

More information

Lecture 1 Contracts : Principles of Imperative Computation (Fall 2018) Frank Pfenning

Lecture 1 Contracts : Principles of Imperative Computation (Fall 2018) Frank Pfenning Lecture 1 Contracts 15-122: Principles of Imperative Computation (Fall 2018) Frank Pfenning In these notes we review contracts, which we use to collectively denote function contracts, loop invariants,

More information

Algorithms. Lecture Notes 5

Algorithms. Lecture Notes 5 Algorithms. Lecture Notes 5 Dynamic Programming for Sequence Comparison The linear structure of the Sequence Comparison problem immediately suggests a dynamic programming approach. Naturally, our sub-instances

More information

Graphical Analysis. Figure 1. Copyright c 1997 by Awi Federgruen. All rights reserved.

Graphical Analysis. Figure 1. Copyright c 1997 by Awi Federgruen. All rights reserved. Graphical Analysis For problems with 2 variables, we can represent each solution as a point in the plane. The Shelby Shelving model (see the readings book or pp.68-69 of the text) is repeated below for

More information

Box It Up (A Graphical Look)

Box It Up (A Graphical Look) . Name Date A c t i v i t y 1 0 Box It Up (A Graphical Look) The Problem Ms. Hawkins, the physical sciences teacher at Hinthe Middle School, needs several open-topped boxes for storing laboratory materials.

More information

Week - 01 Lecture - 03 Euclid's Algorithm for gcd. Let us continue with our running example of gcd to explore more issues involved with program.

Week - 01 Lecture - 03 Euclid's Algorithm for gcd. Let us continue with our running example of gcd to explore more issues involved with program. Programming, Data Structures and Algorithms in Python Prof. Madhavan Mukund Department of Computer Science and Engineering Indian Institute of Technology, Madras Week - 01 Lecture - 03 Euclid's Algorithm

More information

2.9 Linear Approximations and Differentials

2.9 Linear Approximations and Differentials 2.9 Linear Approximations and Differentials 2.9.1 Linear Approximation Consider the following graph, Recall that this is the tangent line at x = a. We had the following definition, f (a) = lim x a f(x)

More information

Note that ALL of these points are Intercepts(along an axis), something you should see often in later work.

Note that ALL of these points are Intercepts(along an axis), something you should see often in later work. SECTION 1.1: Plotting Coordinate Points on the X-Y Graph This should be a review subject, as it was covered in the prerequisite coursework. But as a reminder, and for practice, plot each of the following

More information

Topic C. Communicating the Precision of Measured Numbers

Topic C. Communicating the Precision of Measured Numbers Topic C. Communicating the Precision of Measured Numbers C. page 1 of 14 Topic C. Communicating the Precision of Measured Numbers This topic includes Section 1. Reporting measurements Section 2. Rounding

More information

Table : IEEE Single Format ± a a 2 a 3 :::a 8 b b 2 b 3 :::b 23 If exponent bitstring a :::a 8 is Then numerical value represented is ( ) 2 = (

Table : IEEE Single Format ± a a 2 a 3 :::a 8 b b 2 b 3 :::b 23 If exponent bitstring a :::a 8 is Then numerical value represented is ( ) 2 = ( Floating Point Numbers in Java by Michael L. Overton Virtually all modern computers follow the IEEE 2 floating point standard in their representation of floating point numbers. The Java programming language

More information

CS 137 Part 8. Merge Sort, Quick Sort, Binary Search. November 20th, 2017

CS 137 Part 8. Merge Sort, Quick Sort, Binary Search. November 20th, 2017 CS 137 Part 8 Merge Sort, Quick Sort, Binary Search November 20th, 2017 This Week We re going to see two more complicated sorting algorithms that will be our first introduction to O(n log n) sorting algorithms.

More information

Lecture 1 Contracts. 1 A Mysterious Program : Principles of Imperative Computation (Spring 2018) Frank Pfenning

Lecture 1 Contracts. 1 A Mysterious Program : Principles of Imperative Computation (Spring 2018) Frank Pfenning Lecture 1 Contracts 15-122: Principles of Imperative Computation (Spring 2018) Frank Pfenning In these notes we review contracts, which we use to collectively denote function contracts, loop invariants,

More information

The listing says y(1) = How did the computer know this?

The listing says y(1) = How did the computer know this? 18.03 Class 2, Feb 3, 2010 Numerical Methods [1] How do you know the value of e? [2] Euler's method [3] Sources of error [4] Higher order methods [1] The study of differential equations has three parts:.

More information

DOWNLOAD PDF BIG IDEAS MATH VERTICAL SHRINK OF A PARABOLA

DOWNLOAD PDF BIG IDEAS MATH VERTICAL SHRINK OF A PARABOLA Chapter 1 : BioMath: Transformation of Graphs Use the results in part (a) to identify the vertex of the parabola. c. Find a vertical line on your graph paper so that when you fold the paper, the left portion

More information

Advanced Operations Research Prof. G. Srinivasan Department of Management Studies Indian Institute of Technology, Madras

Advanced Operations Research Prof. G. Srinivasan Department of Management Studies Indian Institute of Technology, Madras Advanced Operations Research Prof. G. Srinivasan Department of Management Studies Indian Institute of Technology, Madras Lecture 16 Cutting Plane Algorithm We shall continue the discussion on integer programming,

More information

Animations involving numbers

Animations involving numbers 136 Chapter 8 Animations involving numbers 8.1 Model and view The examples of Chapter 6 all compute the next picture in the animation from the previous picture. This turns out to be a rather restrictive

More information

FUNCTIONS AND MODELS

FUNCTIONS AND MODELS 1 FUNCTIONS AND MODELS FUNCTIONS AND MODELS 1.5 Exponential Functions In this section, we will learn about: Exponential functions and their applications. EXPONENTIAL FUNCTIONS The function f(x) = 2 x is

More information

Approximating Square Roots

Approximating Square Roots Math 560 Fall 04 Approximating Square Roots Dallas Foster University of Utah u0809485 December 04 The history of approximating square roots is one of the oldest examples of numerical approximations found.

More information

10.4 Linear interpolation method Newton s method

10.4 Linear interpolation method Newton s method 10.4 Linear interpolation method The next best thing one can do is the linear interpolation method, also known as the double false position method. This method works similarly to the bisection method by

More information

CS125 : Introduction to Computer Science. Lecture Notes #38 and #39 Quicksort. c 2005, 2003, 2002, 2000 Jason Zych

CS125 : Introduction to Computer Science. Lecture Notes #38 and #39 Quicksort. c 2005, 2003, 2002, 2000 Jason Zych CS125 : Introduction to Computer Science Lecture Notes #38 and #39 Quicksort c 2005, 2003, 2002, 2000 Jason Zych 1 Lectures 38 and 39 : Quicksort Quicksort is the best sorting algorithm known which is

More information

Exploring Fractals through Geometry and Algebra. Kelly Deckelman Ben Eggleston Laura Mckenzie Patricia Parker-Davis Deanna Voss

Exploring Fractals through Geometry and Algebra. Kelly Deckelman Ben Eggleston Laura Mckenzie Patricia Parker-Davis Deanna Voss Exploring Fractals through Geometry and Algebra Kelly Deckelman Ben Eggleston Laura Mckenzie Patricia Parker-Davis Deanna Voss Learning Objective and skills practiced Students will: Learn the three criteria

More information

Sorting. Bubble Sort. Selection Sort

Sorting. Bubble Sort. Selection Sort Sorting In this class we will consider three sorting algorithms, that is, algorithms that will take as input an array of items, and then rearrange (sort) those items in increasing order within the array.

More information

Not for reproduction

Not for reproduction x=a GRAPHING CALCULATORS AND COMPUTERS (a, d ) y=d (b, d ) (a, c ) y=c (b, c) (a) _, by _, 4 x=b FIGURE 1 The viewing rectangle a, b by c, d _4 4 In this section we assume that you have access to a graphing

More information

Graph Theory. Chapter 4.

Graph Theory. Chapter 4. Graph Theory. Chapter 4. Wandering. Here is an algorithm, due to Tarry, that constructs a walk in a connected graph, starting at any vertex v 0, traversing each edge exactly once in each direction, and

More information

Exercises for a Numerical Methods Course

Exercises for a Numerical Methods Course Exercises for a Numerical Methods Course Brian Heinold Department of Mathematics and Computer Science Mount St. Mary s University November 18, 2017 1 / 73 About the class Mix of Math and CS students, mostly

More information

3.7. Vertex and tangent

3.7. Vertex and tangent 3.7. Vertex and tangent Example 1. At the right we have drawn the graph of the cubic polynomial f(x) = x 2 (3 x). Notice how the structure of the graph matches the form of the algebraic expression. The

More information

1.7 Limit of a Function

1.7 Limit of a Function 1.7 Limit of a Function We will discuss the following in this section: 1. Limit Notation 2. Finding a it numerically 3. Right and Left Hand Limits 4. Infinite Limits Consider the following graph Notation:

More information

Chapter 1. Linear Equations and Straight Lines. 2 of 71. Copyright 2014, 2010, 2007 Pearson Education, Inc.

Chapter 1. Linear Equations and Straight Lines. 2 of 71. Copyright 2014, 2010, 2007 Pearson Education, Inc. Chapter 1 Linear Equations and Straight Lines 2 of 71 Outline 1.1 Coordinate Systems and Graphs 1.4 The Slope of a Straight Line 1.3 The Intersection Point of a Pair of Lines 1.2 Linear Inequalities 1.5

More information

1. Fill in the right hand side of the following equation by taking the derivative: (x sin x) =

1. Fill in the right hand side of the following equation by taking the derivative: (x sin x) = 7.1 What is x cos x? 1. Fill in the right hand side of the following equation by taking the derivative: (x sin x = 2. Integrate both sides of the equation. Instructor: When instructing students to integrate

More information

Computer Simulations

Computer Simulations Computer Simulations A practical approach to simulation Semra Gündüç gunduc@ankara.edu.tr Ankara University Faculty of Engineering, Department of Computer Engineering 2014-2015 Spring Term Ankara University

More information

MAT 003 Brian Killough s Instructor Notes Saint Leo University

MAT 003 Brian Killough s Instructor Notes Saint Leo University MAT 003 Brian Killough s Instructor Notes Saint Leo University Success in online courses requires self-motivation and discipline. It is anticipated that students will read the textbook and complete sample

More information

7.1 INVERSE FUNCTIONS

7.1 INVERSE FUNCTIONS 1 7.1 INVERSE FUNCTIONS One to one functions are important because their equations, f(x) = k, have (at most) a single solution. One to one functions are also important because they are the functions that

More information

Math 1: Solutions to Written Homework 1 Due Friday, October 3, 2008

Math 1: Solutions to Written Homework 1 Due Friday, October 3, 2008 Instructions: You are encouraged to work out solutions to these problems in groups! Discuss the problems with your classmates, the tutors and/or the instructors. After working doing so, please write up

More information

Equations and Functions, Variables and Expressions

Equations and Functions, Variables and Expressions Equations and Functions, Variables and Expressions Equations and functions are ubiquitous components of mathematical language. Success in mathematics beyond basic arithmetic depends on having a solid working

More information

Intermediate Algebra. Gregg Waterman Oregon Institute of Technology

Intermediate Algebra. Gregg Waterman Oregon Institute of Technology Intermediate Algebra Gregg Waterman Oregon Institute of Technology c 2017 Gregg Waterman This work is licensed under the Creative Commons Attribution 4.0 International license. The essence of the license

More information

Simple Graph. General Graph

Simple Graph. General Graph Graph Theory A graph is a collection of points (also called vertices) and lines (also called edges), with each edge ending at a vertex In general, it is allowed for more than one edge to have the same

More information

Lecture 3: Some Strange Properties of Fractal Curves

Lecture 3: Some Strange Properties of Fractal Curves Lecture 3: Some Strange Properties of Fractal Curves I have been a stranger in a strange land. Exodus 2:22 1. Fractal Strangeness Fractals have a look and feel that is very different from ordinary curves.

More information

: Intro Programming for Scientists and Engineers Assignment 1: Turtle Graphics

: Intro Programming for Scientists and Engineers Assignment 1: Turtle Graphics Assignment 1: Turtle Graphics Page 1 600.112: Intro Programming for Scientists and Engineers Assignment 1: Turtle Graphics Peter H. Fröhlich phf@cs.jhu.edu Joanne Selinski joanne@cs.jhu.edu Due Date: Wednesdays

More information

An introduction to plotting data

An introduction to plotting data An introduction to plotting data Eric D. Black California Institute of Technology February 25, 2014 1 Introduction Plotting data is one of the essential skills every scientist must have. We use it on a

More information

(Part - 1) P. Sam Johnson. April 14, Numerical Solution of. Ordinary Differential Equations. (Part - 1) Sam Johnson. NIT Karnataka.

(Part - 1) P. Sam Johnson. April 14, Numerical Solution of. Ordinary Differential Equations. (Part - 1) Sam Johnson. NIT Karnataka. P. April 14, 2015 1/51 Overview We discuss the following important methods of solving ordinary differential equations of first / second order. Picard s method of successive approximations (Method of successive

More information

Math 340 Fall 2014, Victor Matveev. Binary system, round-off errors, loss of significance, and double precision accuracy.

Math 340 Fall 2014, Victor Matveev. Binary system, round-off errors, loss of significance, and double precision accuracy. Math 340 Fall 2014, Victor Matveev Binary system, round-off errors, loss of significance, and double precision accuracy. 1. Bits and the binary number system A bit is one digit in a binary representation

More information

1 Dynamic Memory continued: Memory Leaks

1 Dynamic Memory continued: Memory Leaks CS104: Data Structures and Object-Oriented Design (Fall 2013) September 3, 2013: Dynamic Memory, continued; A Refresher on Recursion Scribes: CS 104 Teaching Team Lecture Summary In this lecture, we continue

More information