Part 6 Chapter Boundary-Value Problems PowerPoints organized by Dr. Michael R. Gustafson II, Duke University All images copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Chapter Objectives Understanding the difference between initial-value and boundary-value problems. Knowing how to express an n th order ODE as a system of n first-order ODEs. Knowing how to implement the shooting method for linear ODEs by using linear interpolation to generate accurate shots. Understanding how derivative boundary conditions are incorporated into the shooting method.
Objectives (cont) Knowing how to solve nonlinear ODEs with the shooting method by using root location to generate accurate shots. Knowing how to implement the finite-difference method. Understanding how derivative boundary conditions are incorporated into the finite-difference method. Knowing how to solve nonlinear ODEs with the finite-difference method by using root location methods for systems of nonlinear algebraic equations.
Boundary-Value Problems Boundary-value problems are those where conditions are not known at a single point but rather are given at different values of the independent variable. Boundary conditions may include values for the variable or values for derivatives of the variable. Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Higher Order Systems MATLAB s ODE solvers are based on solving first-order differential equations only. To solve an n th order system (n>1), the system must be written as n first-order equations: dt z dx dz ht dx dt h T T 0 dx T Each first-order equation needs an initial value or boundary value to solve.
The Shooting Method One method for solving boundary-value problems - the shooting method - is based on converting the boundary-value problem into an equivalent initial-value problem. Generally, the equivalent system will not have sufficient initial conditions and so a guess is made for any undefined values. The guesses are changed until the final solution satisfies all the boundary conditions. For linear ODEs, only two shots are required - the proper initial condition can be obtained as a linear interpolation of the two guesses. Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Example Steady-state temperature distribution for a long, thin rod positioned between two constant temperature walls. Solve T a dt h T T 0 dx x=0 L with L=10 m, h =0.05 m -, T =00 K, T(0) = 300 K, and T(10) = 400 K. Assume no radial temperature gradient. First - break into two equations: convection conduction T T b dt z dx dz 0.0500 T dx dt h T T 0 dx
Example Code Code for derivatives: function dy=ex30(x,y) %linear ODE boundary-value problem heat conduction/convection p. 547 Chapra dy=[y();-0.05*(00-y(1))]; Code for 1 st shot try z(0)=z a1 =-5 [x,y]=ode45(@ex30, [0 10], [300-5]); Tb1=y(length(y)) >>ans Tb1 =569.7539 Code for nd shot try z(0)=z a =-0 [x,y]=ode45(@ex30, [0 10], [300-0]); Tb=y(length(y)) >>ans Tb = 59.5131
Interpolation Because it s a linear ODE, use linear interpolation to solve for the exact z(0)=z a ( z z ) ( z z ) ( T T ) z z ( z z ) ( T T ) ( T T ) ( T T ) z a a a1 a a1 b b1 a a1 a a1 b b1 b b1 b b1 (400 569.7539) 5 ( 0 ( 5)) 13.075 K/m (59.5131 569.7539) Now solve for the T(x) distribution: [t,y]=ode45(@ex30,[0 10],[300-13.075]);
Boundary Conditions Dirichlet boundary conditions are those where a fixed value of a variable is known at a particular location. Neumann boundary conditions are those where a derivative is known at a particular location. Shooting methods can be used for either kind of boundary condition.
Example Shooting Method with derivative boundary conditions (p. 549) Same as previous, except convection is on the left side. Solve: dt h T T 0 dx T convection conduction h=1 J/(m K s), k = 00 J/ (s m K) First - break into two equations: dt h T T 0 dx convection T = 00 K x=0 L a b dt z dx dz 0.0500 T dx T b
Boundary condition at a: Solve for gradient =z a : Guess T a1 = 300K: function dy=ex30(x,y) %linear ODE boundary-value problem heat conduction/convection %p. 547 Chapra dy=[y();-0.05*(00-y(1))]; end dt hac( T T (0)) kac (0) dx dt h (0) ( T (0) T ) dx k dt 1 1 K za 1 (0) ( T (0) T ) (300 00) 0.5 dx 00 00 m First guess >> [x,y]=ode45(@ex30,[0 10],[300,0.5]); >> Tb1=y(length(y)) Tb1 = 683.5088 Result is higher than known T b = 400 K, so make a new guess.
nd guess T a = 150 K, z a = -0.5 [x,y]=ode45(@ex30,[0 10],[150,-0.5]); >> Tb=y(length(y)) Tb = -41.7544 First guess : Ta1 = 300K, za1 =0.5K/m Tb1=683.5088 K Second guess: Ta= 150K, za = -0.5 Tb=-41.7544 K So we know that Ta is in between 300 and 150K. Using linear interpolation, ( T T ) ( T T ) ( T T ) T T ( T T ) ( T T ) ( T T ) ( T T ) T a a a1 a a1 a a1 a a1 b b1 b b1 b b1 b b1 150 300 300 (400 683.5088) 41.3643K 41.7544 683.5088 And z a = 0.068 K/m.
Difference between Dirichlet and Nuemann BC problems Difference in the last two problems was that when the derivative B.C. is used, we don t know Ta. Therefore, must guess Ta and solve for za, and then run. In the first problem, Ta is known, so we guess za only.
The Shooting Method for Nonlinear ODEs For nonlinear ODEs, interpolation between two guesses will not necessarily result in an accurate estimate of the required boundary condition. Instead, the boundary condition can be used to write a roots problem with the estimate as a variable.
Example dt dx Solve with =.7x10-9 K -3 m -, L=10 m, h =0.05 m-, T =00 K, T(0) = 300 K, and T(10) = 400 K. d T dx h T T T 4 T 4 0 First - break into two equations: dt z 4 4 dx ht T T T 0 dz 0.05 00.710 1.610 dx 9 9 4 T T
Example Code Code for derivatives: function dy=dydxn(x,y) dy=[y(); -0.05*(00-y(1))-.7e-9*(1.6e9-y(1)^4)]; Code for residual: function r=res(za) [x,y]=ode45(@dydxn, [0 10], [300 za]); r=y(length(x),1)-400; Code for finding root of residual: fzero(@res, -50)%50 is the guess Code for solving system: [x,y]=ode45(@dydxn, [0 10], [300 fzero(@res, -50) ]);
Finite-Difference Methods The most common alternatives to the shooting method are finite-difference approaches. In these techniques, finite differences are substituted for the derivatives in the original equation, transforming a linear differential equation into a set of simultaneous algebraic equations.
Finite-Difference Example Convert: d T dx h T T 0 into n-1 simultaneous equations at each interior point using centered difference equations: dt Ti 1T i Ti 1 dx x Ti 1T i Ti 1 h T Ti 0 x T hx T T hx T i1 i i1 (.16)
Finite-Difference Example (cont) Since T 0 and T n are known, they will be on the right-hand-side of the linear algebra system (in this case, in the first and last entries, respectively): h x 1 1 h x 1 1 h x T 1 T T n1 h x T T 0 h x T h x T T n
Example of finite-difference method for linear ODE Use the finite-difference approach to solve the same problem as before. Use 4 interior nodes with segment length of x = m. For node 1: -T 0 +.T 1 T = 40 Substituting T 0 = 300 gives Assemble all the equations:.t 1 T = 340. 1 0 0 T 340 1 1. 1 0 T 40 0 1. 1 T3 40 0 0 1. T4 440
>> A=[. -1 0 0;-1. -1 0; 0-1. -1; 0 0-1.]; >> b=[340 40 40 440]'; >> T=A\b T = 83.660 83.1853 99.7416 336.46
Derivative Boundary Conditions Neumann boundary conditions are resolved by solving the centered difference equation at the point and rewriting the system equation accordingly. Use Chapra Tables p. 454-457. For example, if there is a Neumann condition at the T 0 point, dt T1 T 1 dt T 1 T1 x dx 0 x dx 0 T hx T T hx T 1 0 1 dt T1 x hx T0 T1 hx T dx 0 dt hx T0 T1 hx T x dx 0 Substitute T -1 into.16 (.18)
Example Incorporating Derivative Boundary Conditions Problem: Generate the finite-difference solution for a 10-m rod with x = m, h = 0.05 m -, T = 00 K, and the boundary conditions: T a = 0 and T b = 400 K. Note that the first condition means that the slope of the solution should approach zero at the rod s left end. Aside from this case, also generate the solution for dt/dx = -0 at x =0. Solution. Eq (.18) can be used to represent node 0 as.t 0 - T 1 = 0.05* *00-0=40
Write Eq.(.16) for the interior nodes. For example, for node 1, -T 0 +.T 1 T = 40 A similar approach can be used for the remaining interior nodes. The final system of equations can be assembled in matrix form as. T 40 0 1. 1 T 1 40 1. 1 T 40 1. 1 T 40 3 1. T 440 4
>> A=[. - 0 0 0;-1. -1 0 0; 0-1. -1 0;0 0-1. -1;0 0 0-1.]; >> b=[40 40 40 40 440] '; T=A\b T = 43.078 47.3306 61.0994 87.088 330.4946
For derivative at x = 0 is set to -0 K/m, the simultaneous equations are Solution: >>T = 38.710 301.0981 94.1448 306.004 339.100. T 10 0 1. 1 T 1 40 1. 1 T 40 1. 1 T 40 3 1. T 440 4
Plot of Soln to Example.6 (derivative boundary conditions)
Finite-Difference Method for Nonlinear ODEs Root location methods for systems of equations may be used to solve nonlinear ODEs. Another method is to adapt a successive substitution algorithm to calculate the values of the interior points. dt h T T T T 4 4 0 dx Ti 1T i Ti 1 0 h T T T T x Collecting terms, 4 4 T ( hx ) T T hx T x T T 4 4 i1 i i1 i
Solve for the left-side T i in terms of the nonlinear T i on the right side: T i hx T x T T T T 4 4 i i1 i1 hx Assume initial values of T i all = 0. Solve for T 1. Substitute this new value of T 1, and solve for T. Continue solving for all T n. This is one iteration. Now use these new values to complete a second iteration. Continue these iterations until tolerance is met for all T i.
Example of Finite-Difference Approach for Nonlinear ODEs Solve the previous convection/radiation problem using finiteelement and successive substitution. with =.7x10-9 K -3 m -, L=10 m, h =0.05 m-, T =00 K, T(0) = 300 K, and T(10) = 400 K. Use four interior nodes with a segment length of x = m. Recall that we solved the same problem with the shooting method in Example.4.
T T T T 9 4 4 0.05() 00.7 x 10 () (00 0 ) 300 0 1 159.43 9 4 4 0.05() 00.7 x 10 () (00 0 ) 159.43 0 9 4 4 0.05() 00.7 x 10 () (00 0 ) 97.9674 0 3 4 0 1 3 4 5 0.05() 0.05() 0.05() 97.9674 70.4461 9 4 4 0.05() 00.7 x 10 () (00 0 ) 70.4461 400 6.8704 0.05() Continue until converging to final result: T T T T T T 300 50.487 36.96 45.7596 86.491 400