USING MATLAB - Problem statement
24.7 Develop an M-file to implement the finite-difference approach for solving a linear second-order ODE with Dirichlet boundary conditions. Test it by duplicating Example 24.5.
Example 24.5: Finite-Difference Approximation of Boundary Value Problems
Problem Statement: Use the finite-difference approach to solve the same problem as in Examples 24.1 and 24.2. Use four interior nodes with a segment length of x = 2 m.
Solution: Employing the parameters in Example 24.1 and x = 2 m, we can write Eq. (24.16) for each of the rod's interior nodes. For example, for node 1:
T' + 2.2T = 40
Substituting the boundary condition T = 300 gives:
2.2T' - T = 340
After writing Eq. (24.16) for the other interior nodes, the equations can be represented as a tridiagonal and diagonally dominant matrix. MATLAB can be used to generate the solution:
> A = [2.2 -1 0 0; -1 2.2 -1 0; 0 -1 2.2 -1; 0 0 -1 2.2]
> b = [340; 40; 40; 40]
> T = A\b
The solution for T is approximately 83.2660.