This preview shows pages 1–3. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: Spring 2009 MAT260 BEREGNINGSALGORITMER 2 Suggested solution Obligatory Exercise 2 Problem 1 Given x ( t ) = x (1 x ) f ( t, x ) , Put x = 0 . 5. Step 1 is an Euler step, while step 2 , 3 , and 4 are Leapfrog a) steps. Use h = 1 / 2 in all steps. The Leapfrog method x n = x n 2 + 2 hf n 1 , n = 2 , 3 , . . ., giving x 1 = x + h f = 0 . 625 x 2 = x + 2 h f 1 = 0 . 734375 x 3 = x 1 + 2 h f 2 = 0 . 820068359375 x 4 = x 2 + 2 h f 3 = 0 . 881931245326996 The approximation with stepsize h in 2 is x h (2) . 88193 . Using eight b) steps gives x h/ 2 (2) . 88110. The method is second order implying that x h (2) exact C h 2 and x h/ 2 (2) exact C ( h/ 2) 2 . Taking the diffe rence we get x h (2) x h/ 2 (2) 3 C ( h/ 2) 2 implying that the error in the best approximation is C ( h/ 2) 2 ( x h (2) x h/ 2 (2)) / 3 . 00083 / 3 3 10 4 which turns out to be a quite good estimate of this error. The analysis is based on the assumption that h is small enough such that the second order approximation is valid. 1 Solution Problem 1c): function [t,x]=Leap_frog(f,ts,te,xs,N) %define the steplength h=(tets)/N; x(1)=xs; t=linspace(ts,te,N+1); %Evaluate f(t,x) fs=feval(f,ts,xs); %Take an Eulerstep x(2)=xs+h*fs; %Then N1 LeapFrog steps for i=2:N ft=feval(f,t(i),x(i)); x(i+1)=x(i1)+2*h*ft; end The method d) x n (1 + ) x n 1 + x n 2 = h ( 3 2 f n 1 1 + 2 f n 2 ) , n = 2 , 3 , . . . . is explicit and twostep. Two polynomials are associated with this method: p ( z ) = z 2 (1 + ) z + and q ( z ) = 3 2 z 1+ 2 . Consistency implies that p (1) = 0 which is obviously satisfied. Furthermore we need to have(1) = 0 which is obviously satisfied....
View
Full
Document
 Spring '10
 Berntsen

Click to edit the document details