program in python
Problem 2. Use your program to make numerical tests for the linear system given in Eq. (1.2) on page 3 of our textbook with c, u, and f given in the bottom of page 3. Do tests for n = 10, 20, 50, 100, 500, 1000. Plot the solution errors and discuss numerical results. lone dary 1.1 Discretization of a Differential Equation 3 etc.) 2u; - - - 4+1 12-2 + cu = fi Sisn-1, completed by the two boundary conditions ua, te = B. rential equal alues of this dimension, f boundary 0 0 solution ze 1), when ger the value ne). We denke 0 0 Since the dependence in u, is linear in these equations, we obtain a so-called linear system (see Chapter 5) of size (n-1): Arun) bln) (1.2) where (W) is the vector of entries (1...n-1), while b) is a vector and As a matrix defined by 12+ -1 si + an? -1 2+ fa -1 (n) = : -12+ In-2 0 0 -1 2+ In-1 + Ana The matrix A. is said to be tridiagonal, since it has nonzero entries only on its main diagonal and on its two closest diagonals (the subdiagonal and the superdiagonal). One can prove (see Lemma 5.3.2) that the matrix A., is invertible, so that there exists a unique solution of the linear system (1.2). Even more, it is possible to prove that the solution of the linear system (1.2) is a correct approximation of the exact solution of the boundary value problem (1.1). We said that the previous finite difference method converges as the number of intervals n increases. This is actually a delicate result (see, e.g., [3] for a proof), and we content ourselves in stating it without proof. Theorem 1.1.1. Assume that the solution u(x) of (1.1) is of class C on (0,1). Then the finite difference method converges in the sense that 1 max lum- ur) sup (2) OSIS approximate - (locice 1) algebrak -ch point bination wat (1) + 96n osisi Figure 1.1 shows the exact and approximate in 20) solutions of equation (1.1) on 10,11, where the functions cand are chosen so that the exact solution la, or is u(t) = = sin(2x): (2) = 4, $(x) = 4(x2 + 1)(x) - 4 cos(2x), a = 8 = 0. cial The problem of solving the differential equation (1.1) has thus been reduced to solving a linear system. In practice, these linear systems are very large. Problem 2. Use your program to make numerical tests for the linear system given in Eq. (1.2) on page 3 of our textbook with c, u, and f given in the bottom of page 3. Do tests for n = 10, 20, 50, 100, 500, 1000. Plot the solution errors and discuss numerical results. lone dary 1.1 Discretization of a Differential Equation 3 etc.) 2u; - - - 4+1 12-2 + cu = fi Sisn-1, completed by the two boundary conditions ua, te = B. rential equal alues of this dimension, f boundary 0 0 solution ze 1), when ger the value ne). We denke 0 0 Since the dependence in u, is linear in these equations, we obtain a so-called linear system (see Chapter 5) of size (n-1): Arun) bln) (1.2) where (W) is the vector of entries (1...n-1), while b) is a vector and As a matrix defined by 12+ -1 si + an? -1 2+ fa -1 (n) = : -12+ In-2 0 0 -1 2+ In-1 + Ana The matrix A. is said to be tridiagonal, since it has nonzero entries only on its main diagonal and on its two closest diagonals (the subdiagonal and the superdiagonal). One can prove (see Lemma 5.3.2) that the matrix A., is invertible, so that there exists a unique solution of the linear system (1.2). Even more, it is possible to prove that the solution of the linear system (1.2) is a correct approximation of the exact solution of the boundary value problem (1.1). We said that the previous finite difference method converges as the number of intervals n increases. This is actually a delicate result (see, e.g., [3] for a proof), and we content ourselves in stating it without proof. Theorem 1.1.1. Assume that the solution u(x) of (1.1) is of class C on (0,1). Then the finite difference method converges in the sense that 1 max lum- ur) sup (2) OSIS approximate - (locice 1) algebrak -ch point bination wat (1) + 96n osisi Figure 1.1 shows the exact and approximate in 20) solutions of equation (1.1) on 10,11, where the functions cand are chosen so that the exact solution la, or is u(t) = = sin(2x): (2) = 4, $(x) = 4(x2 + 1)(x) - 4 cos(2x), a = 8 = 0. cial The problem of solving the differential equation (1.1) has thus been reduced to solving a linear system. In practice, these linear systems are very large