Övningsexempel och labuppgifter, Lab 5-2D242 Uppgifter markerade med Lab skall redovisas med skriftlig rapport, övriga uppgifter behöver ej redovisas. Flera av uppgifterna kommer att diskuteras på övningarna.. Ange den allmänna lösningen till differensekvationen y n+2 + y n+ 2y n =, Bestäm den lösning som svarar mot begynnelsevillkoren y =,y =. 2. Lös differensekvation y n+2 +2y n+ +5y n =, y =,y = 3. Lab Bestäm den analytiska lösningen till differensekvationen y n+2 5.2y n+ + y n = y = y =.2 Använd därefter dator för att utföra 2-4 steg i beräkningarna y n+2 =5.2y n+ y n y = y =.2 Åskådliggör talföljden som funktion av n och jämför med den analytiska lösningen. Det kan vara intressant att beräkna och skriva ut skillnaden mellan lösningarna med många siffror. Förklara resultaten! Ledning: Avrundningsfelen har stor betydelse. 4. Eigensolutions of a tridiagonal matrix Given a real, symmetric tridiagonal N N matrix B =trid(c, b, c), i.e. bc cbc B = cbc cb a. Show that we can get the eigenvalues of B from the eigenvalues λ(t ) of a a T = a a What is the relation between λ(t ) and λ(b), and between a, b, c? 34
b. Show that the components x i of an eigenvector x of T satisfies a linear difference equation. Then use that difference equation to show that the eigenvalues and eigenvectors of B are given by λ k (B) = b +2c cos ϕ k ϕ k = kπ N + x k = (sinϕ k, sin 2ϕ k,...,sin Nϕ k ) T k =, 2,...,N c. Use b. to show that for T =trid( /h 2, 2/h 2, /h 2 ) λ k (T ) = 2 h 2 2 h cos ϕ 2 k = 4 ϕ h 2 sin2 k 2 x k = (sinϕ k, sin 2ϕ k,...,sin Nϕ k ) T = I(e ϕ k,e 2ϕ k,...,e Nϕ k ) T k =, 2,...,N ϕ k = kπ N + Background: In Dq sec. 8.5 p 367-372 the solution of a single linear difference equation is discussed. We assume here that you are familiar with such solutions. 5. Bestäm stabilitetsområdet för Eulers metod, Baklänges Eulers metod och trapetsregeln. 6. Lab Differentialekvationen y = y + e t, y() =. löstes approximativt med Eulers metod med steglängden h =., dvs{y n } beräknades enligt y =. y n+ = y n + h( y n + e tn ), n =,, 2,... Följande resultat erhölls på en dator med avkortningsenheten.5 8 (unit roundoff, machine epsilon, Heath sec.3.5): 35
t y t y..e 2..73E +5. 9.E 3.2.559E +6.2 8.584E 3.3.49E +7.3 3.76E 3.4.29E +8.4 3.986E 2.5.75E +9.5 2.957E.6.69E +.6 2.75E +.7 9.73E +.7 2.498E +.8 8.854E +.8 2.274E +2.9 8.57E +2.9 2.69E +3 2. 7.332E +3..883E +4 2. 6.672E +4 Förklara! I förklaringen bör du beräkna hur fel i begynnelsevärdet fortplantas till t =2såväl i differentialekvation som differensekvation. OBS: Detärlämpligtattstuderaskillnaden mellan två lösningar med olika begynnelsevärden för både differentialekvation och differensekvation. För vilka steglängder h kommer Eulers metod att ge rimliga lösningar till problemet. 7. We shall study the system y = Ay, y() = c. We assume that A has linearly independent eigenvectors. a. Formulate the solution y(t) using eigenvalues and eigenvectors of A. b. Formulate the solution y(t) using the matrix exponential. 8. We shall study the backward Euler method y n+ = y n + hf(t n+, y n+ ) on the system y = Ay, y() = c. We assume that A is diagonalizable. a. Formulate the solution y n. b. Express the solution y n using eigenvalues and eigenvectors of A. c. Examine the stability of the method. 9. Define the five-point operator 2 5 used to approximate the Laplace operator 2.Draw the computational molecule. Derive an expression for the error 2 5 u ij 2 u(x i,y j ).. Lab Consider the problem 2 u x + 2 u = f(x, y)(x, y) Ω 2 y2 u = g(x, y) Ω u x = Ω 2 An approximate solution is calculated. The region is discretized using the steps x and y in x and y-directions. 36
Omega 2 y x Omega : boundary marked Omega 2: boundary marked 2 The differentialequation and boundary conditions are discretized with suitable formulas. We then obtain a set of linear equations for the approximate solution.introduce the notation U(x, y, x, y) for the solution obtained with the discretization steps x, y. Th discretization error is assumed to satisfy U(x, y, x, y) =u(x, y)+c (x, y)( x) 2 + c 2 (x, y)( y) 2 + O(( x) 4, ( y) 4 ) Olle and Nisse each develop a program, based on slightly different discretization formulas and experiment with different stepsizes to convince themselves that their programs work properly. For some different points and some different discretization steps they obtain the following results Olle: x y x y U(x, y, x, y).5.5...4.5.5.5.5..5.5.25.25.25.4.2...87.4.2.5..825.4.2..5.8625.4.2.25..838.4.2..25.866 x y x y U(x, y, x, y).5.5...9.5.5.5.5.35.5.5.25.25.5 Nisse:.4.2...8.4.2.5..85.4.2..5.835.4.2.25..83.4.2..25.86 Are the results consistent with the assumed error expansion formula? Motivate your answers. Simple arithmetical calculations with calculator or Matlab should be in- 37
cluded in your motivation. One of the programs seems to contain an error; which program? Make a qualified guess of where to seek for the error. Use the tabulated results to find an even better approximation to the solution at the points (.5,.5) och (.4,.2).. Lab Poissons ekvation på oregelbundet område, Helmholtz ekvation Studera häftet Glesa matriser från randvärdesproblem, speciellt programmet randv2dgles.m och modifiera detta program så att följande två problem löses (två olika modifikationer). a. b. 2 u = in an annulus with outer radius one and inner radius.5, the center is in the origin. (like the cross section of a pipe with a thick wall). On both inner and outer boundary u(x, y) is prescribed. Choose a testproblem with known solution, eg u(x, y) =x 5 x 3 y 2 +5xy 4 2 u + p(x, y)u = f(x, y) on square x, y with p(x, y) = 6(x 2 + y 2 ) +.5(x 4 + y 4 ) f(x, y) = 2(x2 + y 2 )((x 2 )2 +(y 2 )2 ) +.5(x 4 + y 4 ) 8 On the boundary u(x, y) =2((x 2 )2 +(y 2 )2 ) 2. Lab Use Taylor expansions (operator calculus) to analyze the scheme u n+ k u n k = r(u n k+ 2u n k + u n k ), r = α t x 2 for the heat equation u t = αu xx. We introduce the notation R n k = u(x k,t n+ ) u(x k,t n ) r(u(x k+,t n ) 2u(x k,t n )+u(x k,t n )) t for the local truncation error of the method. Here u(x, t) is the exact solution of the PDE. Show that the local truncation error can be written c u tt + c 2 u xxxx +... What are the values of c and c 2? Show that if r =/6 then the scheme is more accurate than for any other value of r. 38
3. Lab Numerical experiments with the heat equation Study the heat equation u t = u xx with initial values and boundary conditions u(x, ) = { *x, x.5 *(-x),.5 x u(,t)=u(,t)= a. Discretize in space using equidistant step x and central differences to obtain a system of ordinary differential equations du dt = Au Write down u and A. b. Solve the system in a. with the Euler method with timestep t. Write your method in the form U ij+ =... Do you recognize the method? To make the calculations reasonably efficient you should use a sparse representation for the matrix A, soa timestep can be taken as a matrix-vector product. Store the whole approximate solution in a large matrix and use e.g. surf to draw a 3D-plot of the solution u(x, t). Experiment with different values for the discretization steps x and t and study stability and convergence for your method. Explain your findings. c. Solve the system in a. with the Backward Euler method using timestep t. Make exeperiments similar to the ones in b. Explain your results. d. Modify your program to study the heat equation backwards u t = u xx with initial values and boundary conditions u(x, ) = cos(πx/2) u(,t)=u(,t)= Experiment and explain your results. d. (not compulsory ) Solve the system in a. using one of MATLABs routines for stiff problems and constant Jacobian (e.g. ode23s). You should present your solutions as e.g. the solutions to quite another problem on the next page. 39
.5.5.5..5 2 4 6 8 n=4, k=.4.5.5.5..5 2 2 n=9, k=.4.5.5.5..5 2 4 6 8 n=9, k=.2 4