An Introduction to Computational Fluid Mechanics By Chuen-Yen Chow
Numerical Solution of Ordinary Differential Equations: Initial-Value Problems
Chapter Numerical Solution of Second-Order ODE Boundary Value Problems
* Linear second order ODE of the form * The approximation by the difference equation * Multiplying the equation by and grouping the terms
* It can be written in a more convenient form
* The preceding coefficients are known constants at any interior point in the specified range of x, applied at i=1,2,….,n * n linear algebraic equations to be solved simultaneously for n unknown For i = 1 and n Since and are known from the boundary conditions and constant * Therefore are moved to the right
* The coefficient matrix on the left-hand side is called a tridiagonal matrix * This matrix can be solved by using the Gaussian elimination method
* According to Gaussian elimination method, we multiply the second equation by and the first by and then take the difference of the two to eliminate * The resulting equation is * If we replace the following
* The same process is repeated for i = 3, 4, ….., n-1 * The remaining coefficients will be as following * Where i = 2,3,….,n-1 * The value of can immediately be found by solving simultaneously the last two equations
* The remaining unknowns can be calculated in a backward order the following formula j = n-1, n-2, ……., 2, 1
Constants declaration TMAX = 1.08; DT = 0.002; NM = (TMAX/DT) + 1; NU = ; DOMAINy = 40.0/1000.0; JM = 41; DY = DOMAINy/(JM-1); U0 = 40.0; D = NU * DT / (DY*DY); U(1) = U0; UO(1) = U0; for J=2:JM % Reset U and UO arrays U(J) = 0.0; UO(J) = 0.0; end
% Solution using LAASONEN Method N = JM - 2; JMM1= JM - 1; for K=1:NM for J=1:JM UO(J) = U(J); UP(J,K) = U(J); end
SPECIFY BOUNDARY CONDITIONS AND MODIFY SOME OF THE COEFFICIENTS for J=1:N C(J,1) = D; C(J,2) = -( *D); C(J,3) = D; C(J,4) = -U(J+1); end C(1,4) = C(1,4) - C(1,1)*U(1); C(1,1) = 0.0; C(N,4) = C(N,4) - C(N,3)*U(JM); C(N,3) = 0.0; % TRIDIGONAL SOLUTION for J = 2:N-1 C(J,2) = C(J,2)*C(J-1,2) - C(J,1)*C(J-1,3); C(J,3) = C(J,3)*C(J-1,2); C(J,4) = C(J,4)*C(J-1,2) - C(J,1)*C(J-1,4); end
COMPUTE PHI AND U AT INTERIOR POINT F(N) = ( C(N,4)*C(N-1,2) - C(N,1)*C(N-1,4) ) / ( C(N,2)*C(N-1,2) - C(N,1)*C(N-1,3) ); for K = 1:(N-1) J = N - K; F(J) = ( C(J,4) - C(J,3)*F(J+1) ) / C(J,2); end for J = 2:JMM1 U(J) = F(J-1); end
END