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
 Method, All wheel drive vehicles, xT x1 /xT, Leapfrog method xn

Click to edit the document details