three exercises using Matlab and handwritten work. attached is the full lab with examples and background info as well as Matlab files that can be adju
three exercises using Matlab and handwritten work. attached is the full lab with examples and background info as well as Matlab files that can be adjusted for the exercises
HW4-LAB: Explicit RK Solvers (Due Feb 25)??Construction of RK Solvers and Error Discussion ??Icon:Item:Comments:Commands entered in MATLAB & resultingoutput You should copy relevant input and output from MATLAB and paste it into your Word document. You need only include commands that worked.Plots & graphs Include all graphs generated in an exercise unless the problem specifically tells you which/how many to include.Full sentence responseExercise contains a question that you need to use at least one or two complete sentences to answer. Even if you’re stuck, write down any reasoning orideas you’ve had.Requires work by hand Do scratch work by hand. Leave space in your Word document and write your scratch work directly on the assignment to turn in.In this lab we discuss the construction and error in Euler’s method as a means for developing more accurate DE solvers. We will limit our development to Runge-Kutta methods which are widely used. There aremany such methods, many of which can be quite accurate. We keep the discussion of error at an introductory level and do not present general theorems in this area.Euler’s MethodIn a previous lab we discussed Euler’s method and illustrated how to use it as a DE solver. Here we review some aspects from that lab and focus on the errors occurred when using Euler’s method.EulerÕs method is an example of a fixed-step solver. This means that we choose the discrete set of values of the independent variable so that they divide the interval of interest into N equal subintervals. We do thisby setting the step size h = (b??a)/N. Then we set t0 = a, t1 = t0 + h = a + h, and, in general, tj = t j -1 + h = a + jh. The last point of the discretization is tN = a + Nh = b. For the initial value problemwe seek an approximate discrete solution. The computational steps of Euler’s method are expressed in terms of computer pseudo code as follows.Notice that yk depends only on tk-1 and yk-1 so the Euler’s method is called a single-step solver. We want to emphasize that the numerical values yk are an approximation to y(tk) the true or exactsolution values at t = tk. Thus some error may be encountered in the Euler computation.Example 3 in the previous lab on Euler’s method gave us some idea of the effectiveness of EulerÕs method. From what we see in Figure 4 in that lab, it seems that as the step size decreases, the error made in theapproximation decreases as well, and tends to zero as the step size does. This is indeed true, if certain minimal assumptions are valid. To understand this more fully, we need to examine the error made in EulerÕsmethod.There are two different types of error involved. Truncation error is part of the approximation process, and round-off error occurs when any numerical computation is done on a computer or a calculator.The key to understanding the truncation error in any numerical method for solving ODEs is TaylorÕs formula. If y is a function with two continuous derivatives, TaylorÕs formula of order 1 saysThe term R(h) is the Taylor remainder, and all we need to know about it is that it satisfies the inequalitywhere M is a constant that depends on the second derivative of y.Suppose that y(t) is the solution to the initial value problem . LetÕs substitute the initial condition y(t0) = y0 and the formula for the derivative y ‘(t0) = f (t0, y(t0)) = f (t0, y0) into Eqn (1),getting Then we can use the definition of the first approximation in EulerÕs method, y1 = y0 +f(t0,y0)h, to make this Thus the error made at the first step is simply the remainder in TaylorÕs formula. Putting this together with Eqn (2), we getOf course, a similar error is made at every step. This error is called the local truncation error. It is illustrated in Figure 1, and again in Figure 2, which shows two steps of EulerÕs method. The formula in Eqn (5)tells us that the local truncation error in EulerÕs method is bounded by a constant times the square of the step size. Since the step size is h = (b??a)/N, there are N = (b??a)/h steps involved in covering the entireinterval [a, b]. From the fact that at each step there is a truncation error bounded by Mh2 (from Eqn (2)) and that there are N = (b ?? a)/h steps, a naive computation seems to show that the maximum or accumulatederror after N steps can be no larger thanHowever, this analysis is faulty. It assumes that the truncation error made at each step stays fixed. In fact, it propagates and can get exponentially larger as it does so. To see what this means, notice that each stepin the Euler algorithm is exactly the same. The solution with initial condition y(tk-1) = yk-1 is approximated by the tangent line to the solution curve at the point (tk-1, yk-1). This is illustrated by Figure 2, which showstwo steps in EulerÕs method. Notice that the second step begins at the point (t1, y1) and uses the tangent line to the solution curve corresponding to the solution with initial value y(t1) = y1. This solution is indicatedby the dashed curve in Figure 2. It is clear that this is a different solution from the one we started out to approximate. The total error at the second step has two parts. The first is the truncation error made inapproximating the dashed solution, and the second is the error made at the first step, but now propagated along the solution curves. We will call this propagated truncation error. Figure 2 shows that thepropagated truncation error can be much larger than the original truncation error.Figure 1.Figure 2.In class we analyzed the total error in Euler’s method. In fact we found an upper bound on the error and it is proportional to h. (The error is .) That result basically shows that there is exponential propagation oftruncation error and it has a real effect on the accuracy of the method. The error bound contains a term involving (b – a) on the exponent and the step size h. The good news is that as h decreases we can inprinciple, be sure that the maximum error also decreases. We can make the error as small as we wish by using suitably small step sizes. The bad news is that as the term (b – a), the length of the interval over whichwe want to find the solution gets large, the error bound grows. This means that over large intervals, EulerÕs method could become useless. Unfortunately, this is a feature you need to be carefull with numericalsolvers.All solution methods can be easily applied to systems of differential equations. So Euler’s method can be applied to systems of first order DEs.Higher Order MethodsEuler’s method is based on TaylorÕs formula of order 1. The most natural approach to develop a more accurate scheme than Euler’s method is to follow the derivation of Euler’s method, but to assume the truesolution has more continuous derivatives and, accordingly, to retain more terms in the Taylor expansion. While retaining more terms in the Taylor series provides a more accurate representation of the solution, italso produces numerical methods which require more work per time step. With initial value problems, as with root finding problems the standard measure of work is the number of function evaluations.Next we will develop a class of higher order one-step methods which use values of f exclusively. These techniques, collectively, are called Runge-Kutta methods. The fundamental idea behind the development ofRunge-Kutta methods is to approximate the higher order terms of the Taylor expansion using only evaluations of f(t,y). Derivatives of f are not to be included.Runge-Kutta methods use evaluations of the f(t,y) at Òalternative pairsÓ (t,y) that are not restricted to discrete points with t = t0, t1 = t0+h, t2 = t0 + 2h, É etc. The determination of these Òalternative pairsÓ requirescertain parameters to be selected so that we match the Taylor expressions and maintain the same power of stepsize h in the error expression. The development of R-K methods expresses the difference betweeny(tn+1) and y(tn) as a linear combination of function evaluations of f(t,y(t)). Then coefficients in such linear combinations are determined so that terms of Taylor expansions are matched. This maintains the order ofapproximation of the Taylor polynomial.Example 1. Construct a R-K method of the formWe use Taylor expansions for the corresponding expression involving the exact solution y(t), which looks likeWe choose parameters a1, a2, α, and β to match terms of the expansionThe term is a short hand notation saying the error term contains a factor h3. In the lecture we did get three equations in four unknowns. The system of equations is nonlinear. Hence there may be many solutions.When these equations are satisfied then R-K methodhas a local trancation error term which is also . The numerical method has global truncation error which is hence it is second order (because is consistent and zero stable).One choice for parameters a1, a2, α, and β is a1 = a2 = ?, α = β = 1.The resulting R-K method is called the Improved Euler’s Method. It has the general formIf you inspect the last term it is an average of slopes of tangent lines at (tn, yn) and (tn+1, yn+1).Exercise 1. The improved Euler’s method is a result of one solution to the nonlinear systemIf a2 ?? 0, then the solution of the system will yield coefficients so that the resulting R-K method will be second order. Find two other solutions to the nonlinear system so that you generate second order R-K methods. Record your choices of the parameters and show that they are solutions to the system. (It is advantageous if your solutions have rational values)Example 2. Use the improved Euler’s method to compute the first four steps in the second-order Runge-Kutta approximation to the solution of , using the step size h = 0.1. Compare the results with the actual solution to the initial value problem.The R-K expression is cumbersome to use for hand calculations so we will break it down into easy computational steps that make it appear that we areusing an average of slopes s1 and s2 of tangent lines at successive points. We haveWe have t0 = 1 and y0 = 1. The first iteration computesThe second iteration computesContinue in this manner to produce the next two terms, y3 and y4. The exact solution is y(t) = 1 + t ?? et??1. When we compute the solution at all of the time steps, we get the Table 1 below. For comparison, Table 2displays the Euler computations for this IVP. Comparing the results of Table 1 with those in Table 2, we notice that the errors for the second order R-K method in the fourth column have decreased significantly.Table 1.Table 2.Exercise 2. When computing a solution using the second order R-K method by hand, it is beneficial to arrange your work in a table like that shown below. In the table we show the first step of thesolution to IVP using a step size h = 0.1. Compute the second and third steps of the approximation. Show the detailed steps of the calculations as well as the completed table.There are many R-K methods of various orders. Next we provide a fourth order R-K method. This is the one that most people think of as “the Runge-Kutta method”. It is probably the most commonly used DE solver.For most equations and systems it is suitably fast and accurate. For this method we use four slopes. Starting with the initial point (t0, y0), we computeWith these slopes we define the next value of the dependent variable:We compute the rest of the values of the independent variable iteratively, as we did before.The fourth-order Runge-Kutta method is more costly, since it requires us to compute the right-hand side f (t, y) four times. We are compensated for this, however, by an improvement in the truncation error. A verydifficult analysis using TaylorÕs theorem and argument on the bound of the maximum error shows the global truncation error which is . Using this fourth order R-K method on the IVP in Example 2 we obtainthe results shown in Table 3. Compare the fourth column with those in Tables 1 and 2 to see the significant improvement in accuracy.Table 3.Exercise 3. Drawing a circle. The unit circle centered at the origin is given by. Then we have and differentiating we obtainTo get a system of DEs we introduce parameter t and writeNext let x1(t) = x and x2(t) = y so we have the system of DEsLet x1(0) = 1 and x2(0) = 0 so we have an IVP. If we approximate this system over interval [0, 2π] with h = 0.1 using a DE solver we ÒhopeÓ to have a set of points that lie on the unit circle. (Operationalnote: when using any of the three mfiles cited below you will need to name the output file which is a matrix of 3 rows and 64 columns. An easy way to do this is to assign the output file a name when youinitiate the solver. For example in part (a) use edata=eulersys. This assigns the output file to matrix edata which can be used to obtain the required graph.)(a)Use MATLAB routine eulersys to approximate the system by Euler’s method. For directions type help eulersys. After you execute eulersys choose the option to see the entire solution. Youroutput should start with the values shown below. Note that row 1 is values of t, row 2 is values of x1 and row 3 is values of x2.For your solution include the output from the DE solver. In addition, in MATLAB graph the unit circle centered at the origin and apply the commands axis([-1.5,1.5,-1.5,1.5]), addaxes,axis(‘square’). Next superimpose the graph of the data points x1 and x2 using red asterisks. Print the graph with your name in a box on the graph. (The plot of x1 vs x2 is called a parametric plot. It isan example of an approximate solution of the system of DEs in the phase plane. It is interesting to plot t vs x1 and also t vs x2.)(b)Repeat part (a), but use rk2nd and use blue asterisks in the graph of the data. (This routine has 3 versions of a R-K second order solver. Use the Improved Euler Method.)(c)Repeat part (a) but use rk4th and green asterisks in the graph of the data.(d)Write a comparison of parts (a), (b), and (c).Last updated 02/17/2022(t)=f(t,y(t)),y(a)=.y??y0.for k = 1 to N =+ f (,)h ykyk??1tk??1yk??1=+ htk tk??1y(+h)=y()+()h+R(h).Eqn(1)t0t0y??t0|R(h)|??MEqn(2)h2=f(t,y)withy()=y??t0y0y(+ h) = y()+ f (,)h+ R(h).Eqn(3)t0t0t0y0y()=+ R(h),or y()??= R(h).Eqn(4)t1 y1t1 y1|y()??| ??.Eqn(5)t1 y1 Mh2N × = = M(b – a)h.Eqn(6) Mh2b – ahMh2O(h)=++=+hf(,)+hf(+αh,+β).yn+1yna1k1a2k2yna1tnyna2tnynk1y(t+h)=y(t)+hf(t,y(t))+hf(t+αh,y(t)+βhf(t,y(t)).a1a2y(t+h)=y(t)+h(t)+(t)+O().y??12h2y??h3O()h3+=1,α=,β=a1a2a212a212=++=+hf(,)+hf(+αh,+β).yn+1yna1k1a2k2yna1tnyna2tnynk1O()h3O()h2+h()).yn+1=yn12f(tn+1,yn+hf(tn,yn))+f(tn,yn+=1,α=,β=.a1a2a212a212=f(t,y)=y??t,withy(1)=1y??=+h(f(,+hf(,))+f(,))yn+1yn12tn+1yntnyntnyn)s1 = f (tk – 1, yk – 1 + h)s2 = f (tk – 1 + h, yk – 1 s1 + h yk = yk – 1s1 + s22 = 1 – 1 = 0s1 = f (t0, y0) = y0 – t0 + h) = 1 – 1.1 = – 0.1s2 = f (t0 + h, y0 + hs1) = (y0 + hs1) – (t0 + h= 1 + 0.1() = 0.995y1 = y0s1 + s220 – 0.12 + h = 1 + 0.1 = 1.1.then t1 = t0) = 0.995 – 1.1 = – 0.105,s1 = f (t1, y1) = (0.995 – 0.0105) – 1.2 = – 0.2155,s2 = f (t1 + h, y1 + hs1 + h = 0.995 + 0.1() = 0.978975,y2 = y1s1 + s22-0.105 – 0.21552 + h = 1.1 + 0.1 = 1.2then t2 = t1z’ = 5 – z, z(0) = 0),s1 = f (t0, y0 = f( + + ),s2t0h2, y0h2s1 = f( + + ),s3t0h2, y0h2s2).s4 = f (t0 + h, y0 + h s3 + h .y1 = y0s1 + 2s2 + 2s3 + s46O()h4+=1x2y2=1??y2x2()=(1??)??2y=??2x??==.ddxy2ddxx2dydxdydx??2x2y??xy==??=??xand=y.dydxdy/dtdx/dt??xydydtdxdt(t)=x??1×2(t)=??x??2×1
Collepals.com Plagiarism Free Papers
Are you looking for custom essay writing service or even dissertation writing services? Just request for our write my paper service, and we'll match you with the best essay writer in your subject! With an exceptional team of professional academic experts in a wide range of subjects, we can guarantee you an unrivaled quality of custom-written papers.
Get ZERO PLAGIARISM, HUMAN WRITTEN ESSAYS
Why Hire Collepals.com writers to do your paper?
Quality- We are experienced and have access to ample research materials.
We write plagiarism Free Content
Confidential- We never share or sell your personal information to third parties.
Support-Chat with us today! We are always waiting to answer all your questions.