Engineering Mathematics | CHEN30101 solutions to sheet 3 1. Consider the initial value problem: find y(t) such that y ′ = y 2 t, y(0) = 1. Take a step size h = 0.1 and verify that the forward Euler approximation to y(0.1) is y1 = 1.0 and that the approximations to subsequent points are y2 = 1.01, y3 = 1.0304 and y4 = 1.0623. Compare these estimates with the exact values y(0.1), y(0.2), y(0.3) and y(0.4) obtained by solving the ODE algebraically. Running the forward Euler (f e) process the estimates yj ≈ y(tj ) are tabulated below. The results are rounded to four decimal places. h tj yj f (yj , tj ) y(tj ) 0.1 0.1 0.1 0.1 0.1 0 0.1 0.2 0.3 0.4 1.0000 1.0000 1.0100 1.0304 1.0623 0.0000 0.1000 0.2040 0.3185 0.4514 1.0000 1.0050 1.0204 1.0471 1.0870 Note that the exact solution is the function y(t) = 2 . 2 − t2 2. By taking a step size of h = 0.5, compute the forward Euler approximation of z(5), where z(t) satisfies the initial value problem: z′ = 1 z, 50(1 + t) z(0) = 1. Running (f e) the approximate solution zj is tabulated below. The results are rounded to four decimal places. h tj zj f (zj , tj ) z(tj ) 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0.5 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 1.0000 1.0100 1.0167 1.0218 1.0259 1.0293 1.0323 1.0348 1.0371 1.0392 1.0411 0.0200 0.0135 0.0102 0.0082 0.0068 0.0059 0.0052 0.0046 0.0041 0.0038 0.0035 1.0000 1.0081 1.0140 1.0185 1.0222 1.0254 1.0281 1.0305 1.0327 1.0347 1.0365 Note that the exact solution is the function z(t) = (1 + t)1/50 . 1 3. Consider the initial value problem: find y(t) such that p y ′ = π 1 − y 2 , y(0) = 0. Take a step size h = 0.1 and show that computing the forward Euler approximation to y(1) is problematic. Running the forward Euler process gives ... If y = 1.0207, y ′ = π p h tj yj f (yj , tj ) 0.1 0.1 0.1 0.1 0.1 0 0.1 0.2 0.3 0.4 0.0000 0.3142 0.6124 0.8608 1.0207 3.1416 2.9825 2.4835 1.5991 1 − y 2 cannot be calculated and the method stops. 4. Consider the initial value problem: find y(x) such that 1 x−y e , y(0) = 0. 2 Compute the forward Euler approximation of y(1) using (a) a single step of size h = 1, (b) two steps each of size h = 0.5, (c) four steps each of size h = 0.25, and (d) ten steps each of size h = 0.1. Compare your estimates with the exact value. y′ = (a) Running (f e) for h = 1 gives h xj 1 1 0 1 yj f (yj , xj ) 0.0000 0.5000 0.5000 0.8244 so y(1) ≈ 0.5. (b) Running (f e) for h = 0.5 gives h xj yj 0.5 0 0.0000 0.5 0.5 0.2500 0.5 1 0.5710 f (yj , xj ) 0.5000 0.6420 0.7679 so y(1) ≈ 0.5710. (c) Running (f e) for h = 0.25 gives h xj yj 0.25 0 0.0000 0.25 0.25 0.1250 0.25 0.5 0.2666 0.25 0.75 0.4245 0.25 1 0.5976 so y(1) ≈ 0.5976. 2 f (yj , xj ) 0.5000 0.5666 0.6314 0.6924 0.7477 (d) Running (f e) for h = 0.1 gives h xj yj f (yj , xj ) 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 0.0000 0.0500 0.1026 0.1577 0.2153 0.2755 0.3381 0.4030 0.4703 0.5398 0.6115 0.5000 0.5256 0.5512 0.5765 0.6014 0.6259 0.6497 0.6729 0.6953 0.7168 0.7374 so y(1) ≈ 0.6115. x The solution is y(x) = ln 1+e so y(1) = 0.6201 to four decimal places. 2 The accuracy of the forward Euler approximation improves when the step size h is reduced. 5. By taking a step size of h = 0.5, compute the modified Euler approximation of z(2), where z(t) satisfies the initial value problem: z′ = 1 z, 50(1 + t) z(0) = 1. Running the modified Euler (me) process the approximate solution yj is tabulated below. Note that tm = tj + h2 and zm = zj + h2 f (zj , tj ). h tj zj 0.5 0 1.0000 0.5 0.5 1.0080 0.5 1 1.0138 0.5 1.5 1.0183 0.5 2 1.0220 f (zj , tj ) tm zm f (zm , tm ) z(tj ) 0.0200 0.0134 0.0101 0.0081 0.0068 0.2500 0.7500 1.2500 1.7500 2.2500 1.0050 1.0114 1.0164 1.0204 1.0238 0.0161 0.0116 0.0090 0.0074 0.0063 1.0000 1.0081 1.0140 1.0185 1.0222 These results are clearly much more accurate than those obtained for the forward Euler approximation scheme (cf. question 2). 6. Consider the initial value problem: find y(x) such that y ′ = 17 − 12x − 3y, y(0) = 9. Using four steps of size h = 0.25, estimate y(1) using (i) the forward Euler method, (ii) the modified Euler method. Compare your estimates with the exact value. 3 The exact solution is the function y(x) = 2e−3x + 7 − 4x. Running the forward Euler process gives ... h xj yj f (yj , xj ) 0.25 0 9.0000 −10.0000 0.25 0.25 6.5000 −5.5000 0.25 0.5 5.1250 −4.3750 0.25 0.75 4.0313 −4.0938 0.25 1 3.0078 Running the modified Euler process gives ... h xj yj f (yj , xj ) xm ym 0.25 0 9.0000 −10.0000 0.1250 7.7500 0.25 0.25 7.0625 −7.1875 0.3750 6.1641 0.25 0.5 5.5645 −5.6934 0.6250 4.8528 0.25 0.75 4.2999 −4.8996 0.8750 3.6874 0.25 1 3.1593 −4.4779 1.1250 2.5996 f (ym , xm ) y(xj ) −7.7500 −5.9922 −5.0583 −4.5622 −4.2987 9.0000 6.9447 5.4463 4.2108 3.0996 Neither solution is particularly accurate but the modified Euler method gives more accurate results than the forward Euler method. 7. Heun’s method for approximating the solution of an initial value problem is given by K1 = f (xn , yn ), K2 = f (xn + h, yn + hK1 ) h yn+1 = yn + (K1 + K2 ). 2 Carry out two steps of the method (with step size h = 0.5) to compute an estimate of the solution y(x) of the problem y ′ = y − x, y(0) = 20. Running the process with x∗ = xn + h and y∗ = yn + hK1 gives ... h xn yn K1 x∗ y∗ K2 y(tn ) 0.5 0.0 20.0000 20.0000 0.5 30.0000 29.5000 20.0000 0.5 0.5 32.3750 31.8750 1.0 48.3125 47.3125 32.3257 0.5 1.0 52.1719 51.1719 1.5 77.7578 76.2578 52.6474 8. Consider the initial value problem: find y(t) such that y ′ = 1 + ln y, y(0) = 1. Carry out a step of the 4th-order Runge–Kutta method (with step size h = 0.1) and verify that K1 = 1, K2 = 1.048790, K3 = 1.051111 and K4 = 1.099946 so that the approximation to y(0.1) is given by y1 = 1.104996. 4 For the next step of the method, show that K1 = 1.099842, K2 = 1.148410, K3 = 1.150501 and K4 = 1.198888 so that y2 = 1.219938. Continue for one more step and verify that y3 = 1.344702. Running the Runge–Kutta (rk4) process gives ... h = 0.1 first temporary point second temporary point third temporary point new point t = 0.00 y0 = 1.000000 t = 0.05 ym = 1.050000 t = 0.05 ym = 1.052440 t = 0.10 y∗ = 1.105111 t = 0.10 y1 = 1.104996 K1 K2 K3 K4 = 1.000000 = 1.048790 = 1.051111 = 1.099946 h = 0.1 first temporary point second temporary point third temporary point new point t = 0.10 y1 = 1.104996 t = 0.15 ym = 1.159988 t = 0.15 ym = 1.162416 t = 0.20 y∗ = 1.220046 t = 0.20 y2 = 1.219938 K1 K2 K3 K4 = 1.099842 = 1.148410 = 1.150501 = 1.198888 h = 0.1 first temporary point second temporary point third temporary point new point t = 0.20 y2 = 1.219938 t = 0.25 ym = 1.279878 t = 0.25 ym = 1.282277 t = 0.30 y∗ = 1.344802 t = 0.30 y3 = 1.344702 K1 K2 K3 K4 = 1.198800 = 1.246765 = 1.248637 = 1.296247 √ 9. Consider fluid draining out of a tank according to the equation y ′ = −k y with k = 0.1 and y = 20 at t = 0. Use the 4th-order Runge–Kutta method with step size h = 10 to estimate the values of y(t) (the height, in metres, of fluid in the tank) for t = 10, 20 and 30 measured in seconds. Running the (rk4) process gives ... first step h = 10 t = 0 y0 = 20.0000 first temporary point t = 5 ym = 17.7639 second temporary point t = 5 ym = 17.8926 third temporary point t = 10 y∗ = 15.7700 new point t = 10 y1 = 15.7779 K1 K2 K3 K4 = −0.4472 = −0.4215 = −0.4230 = −0.3971 h = 10 first temporary point second temporary point third temporary point new point t = 10 y1 = 15.7779 t = 15 ym = 13.7918 t = 15 ym = 13.9210 t = 20 y∗ = 12.0468 t = 20 y2 = 12.0558 K1 K2 K3 K4 = −0.3972 = −0.3714 = −0.3731 = −0.3471 h = 10 first temporary point second temporary point third temporary point new point t = 20 y2 = 12.0558 t = 25 ym = 10.3197 t = 25 ym = 10.4496 t = 30 y∗ = 8.8232 t = 30 y3 = 8.8337 K1 K2 K3 K4 = −0.3472 = −0.3212 = −0.3233 = −0.2970 5 10. Consider the initial value problem: find y(x) such that y ′ = −2xy 2 y(0) = 1. Carry out two steps of each of the following methods for solving the equation. (a) forward Euler with h = 1 (b) forward Euler with h = 0.5 (c) modified Euler with h = 1 (d) modified Euler with h = 0.5 (e) Runge– Kutta with h = 1 (f) Runge–Kutta with h = 0.5. Compare your results with the exact solution. (a) Running (f e) with h = 1 ... h xj yj f (yj , xj ) y(xj ) 1 0.0 1.0000 0.0000 1.0000 1 1.0 1.0000 −2.0000 0.5000 1 2.0 −1.0000 0.2000 Unrealistic results. (b) Running (f e) with h = 0.5 ... h xj yj f (yj , xj ) y(xj ) 0.5 0.0 1.0000 0.0000 1.0000 0.5 0.5 1.0000 −1.0000 0.8000 0.5 1.0 0.5000 0.5000 The final value is correct (by coincidence!). (c) Running (me) with h = 1 ... h xj yj f (yj , xj ) xm ym f (ym , xm ) y(xj ) 1 0 1.0000 0.0000 0.5000 1.0000 −1.0000 1.0000 1 1 0.0000 0.0000 1.5000 0.0000 0.0000 0.5000 1 2 0.0000 0.0000 0.2000 All subsequent values will be zero. Not a realistic solution. (d) Running (me) with h = 0.5 ... h xj yj f (yj , xj ) xm ym f (ym , xm ) y(xj ) 0.5 0.0 1.0000 0.0000 0.2500 1.0000 −0.5000 1.0000 0.5 0.5 0.7500 −0.5625 0.7500 0.6094 −0.5570 0.8000 0.5 1.0 0.4715 −0.4446 1.2500 0.3603 −0.3246 0.5000 These values are not particularly accurate but are pointing in the right direction. 6 (e) Running (rk4) with h = 1 ... h = 1.0 first temporary point second temporary point third temporary point new point x = 0.00 y0 x = 0.50 ym x = 0.50 ym x = 1.00 y∗ x = 1.00 y1 = 1.0000 K1 = 0.0000 = 1.0000 K2 = −1.0000 = 0.5000 K3 = −0.2500 = 0.7500 K4 = −1.1250 = 0.3958 h = 1.0 first temporary point second temporary point third temporary point new point x = 1.00 y1 x = 1.50 ym x = 1.50 ym x = 2.00 y∗ x = 2.00 y = 0.3958 = 0.2391 = 0.3100 = 0.1075 = 0.1826 K1 K2 K3 K4 = −0.3134 = −0.1716 = −0.2884 = −0.0462 These values are not particularly accurate but are again pointing in the correct direction. (f) Running (rk4) with h = 0.5 ... h = 0.5 first temporary point second temporary point third temporary point new point x = 0.00 y0 x = 0.25 ym x = 0.25 ym x = 0.50 y∗ x = 0.50 y1 = 1.0000 K1 = 0.0000 = 1.0000 K2 = −0.5000 = 0.8750 K3 = −0.3828 = 0.8086 K4 = −0.6538 = 0.7984 h = 0.5 first temporary point second temporary point third temporary point new point x = 0.50 y1 x = 0.75 ym x = 0.75 ym x = 1.00 y∗ x = 1.00 y2 = 0.7984 = 0.6390 = 0.6452 = 0.4861 = 0.4997 K1 K2 K3 K4 = −0.6374 = −0.6125 = −0.6245 = −0.4726 These values are much more accurate. 11. Express the following high-order equations as systems of first-order equations. (a) (b) (c) (d) (e) dy d2 y + 12y = 0; y(0) = 1, (0) = 0. 2 dx dx d2 y dy dy +2 − 4y = x; y(0) = 0, (0) = 0. dx2 dx dx dy dy d2 y d3 y 3 − + y = x , y(0) = 1, (0) = 0, (0) = 0. dx3 dx dx dx2 d2 p dp 1 dp = ; p(0) = 1, (0) = 2. 2 dt (p + t) dt dt the coupled system dz d2 y −2 = y + z; 2 dt dt d2 z dy +2 = y − z; 2 dt dt 7 y(t0 ) = y0 , z(t0 ) = z0 , dy (t0 ) = vA , dt dz (t0 ) = vB . dt (a) Introducing z = dy dz d2 y so = 2 gives the following coupled system. dx dx dx dy = z, y(0) = 1, dx dz • = −12y, z(0) = 0. dx dz d2 y dy so = 2 gives the following coupled system. Introducing z = dx dx dx dy • = z, y(0) = 0, dx dz = x + 4y − 2z, z(0) = 0. • dx dy dz d2 y Introducing z = and w = = 2 gives the following system. dx dx dx dy • = z, y(0) = 1, dx dz = w, z(0) = 0, • dx dw • = x3 + z − y, w(0) = 0. dx dp dq d2 p Introducing q = so = 2 gives the following system. dt dt dt dp = q, p(0) = 1, • dt q dq = , q(0) = 2. • dt p+t dy dz Finally, introducing x = and w = gives the following system dt dt of four equations with associated initial conditions. dy • = x, y(t0 ) = y0 , dt dx = y + z + 2w, x(t0 ) = vA , • dt dz • = w, z(t0 ) = z0 , dt dw • = y − z − 2x, w(t0 ) = vB . dt • (b) (c) (d) (e) 8 12. Consider the coupled initial value problem dx = −3y, dt dy = 3x, dt x(0) = 1, y(0) = 0. Approximate the solution of this system using the Runge–Kutta method with step size h = 0.1. Show that at the first step, the K values are (0, 3), (−0.45, 3), (−0.45, 2.9325), (−0.87975, 2.865) giving new values x1 and y1 of 0.955338 and 0.2955. Show that the second step gives values x2 and y2 of 0.825349 and 0.564604. Compare these results with the exact values given by x = cos 3t, y = sin 3t. Running (rk4) with h = 0.1 ... h = 0.1 first temporary point second temporary point third temporary point new point t t t t t = = = = = 0.00 0.05 0.05 0.10 0.10 x0 xm xm x∗ x1 = = = = = 1.000000 1.000000 0.977500 0.955000 0.955338 y0 ym ym y∗ y1 = = = = = 0.000000 0.150000 0.150000 0.293250 0.295500 Kf 1 = 0.000000 Kf 2 = -0.450000 Kf 3 = -0.450000 Kf 4 = -0.879750 h = 0.1 first temporary point second temporary point third temporary point new point t t t t t = = = = = 0.10 0.15 0.15 0.20 0.20 x1 xm xm x∗ x2 = = = = = 0.955338 0.911013 0.889517 0.825692 0.825349 y1 ym ym y∗ y2 = = = = = 0.295500 0.438801 0.432152 0.562355 0.564604 Kf 1 Kf 2 Kf 3 Kf 4 = = = = -0.886500 -1.316402 -1.296456 -1.687066 The exact solutions are the functions x(t) = cos 3t, y(t) = sin 3t. Thus when when t = 0.1, we have x = 0.955336 and y = 0.295520 and when t = 0.2 we have x = 0.825336 and y = 0.564642. We see that the numerical approximations are correct to 4 but not 5 decimal places. 13. Consider the coupled initial value problem dx 1 = y, dt 3 dy = 6x3 , dt x(0) = 1; y(0) = −3. Compute an approximation to the solution vector (x, y) at the final time t = 0.5 using the Runge–Kutta method with step size h = 0.1. Then repeat the calculation for h = 0.05. Compare the numerical results with the exact values given by x = 1/(t + 1), y = −3/(t + 1)2 . Editing rhs and running rk4 gives the following output: >> [time, zzrk4, nfeval] = rk4([1;-3],0.5,5); RK4 iteration in 2 dimensions ... t x y 0.00 1.000000 -3.000000 0.00 1.000000 -3.000000 0.10 0.909095 -2.479325 0.20 0.833340 -2.083307 0.30 0.769239 -1.775110 0.40 0.714296 -1.530563 0.50 0.666680 -1.333273 all done 9 Kg1 Kg2 Kg3 Kg4 = = = = 3.000000 3.000000 2.932500 2.865000 Kg1 Kg2 Kg3 Kg4 = = = = 2.866013 2.733038 2.668552 2.477076 >> [time, zzrk4, nfeval] = rk4([1;-3],0.5,10); RK4 iteration in 2 dimensions ... t x y 0.00 1.000000 -3.000000 0.00 1.000000 -3.000000 0.05 0.952381 -2.721088 0.10 0.909091 -2.479338 0.15 0.869566 -2.268430 0.20 0.833334 -2.083332 0.25 0.800000 -1.919998 0.30 0.769231 -1.775146 0.35 0.740741 -1.646088 0.40 0.714286 -1.530609 0.45 0.689656 -1.426869 0.50 0.666667 -1.333330 all done The exact values are x(0.5) = 32 ≈ 0.666667 and y(0.5) = − 34 ≈ −1.333333. The approximation errors for h = 0.1 are |x(0.5) − x5 | = 0.000013 and |y(0.5) − y5 | = 0.000060. For the smaller value h = 0.05, we have |x(0.5) − x10 | = 0.000000 and |y(0.5) − y10 | = 0.000003. The numerical results are much more accurate for the smaller value of h. 14. Consider the second-order initial value problem d2 y + y + ǫy 3 = 0; dt2 y(0) = 1, dy (0) = 0 dt with the value ǫ = 0.1. (This is an example of a Duffing oscillator.) Compute three steps of Runge–Kutta with a step size h = 0.1. The first step is to express the second-order problem as a coupled firstorder system. dy = v; y(0) = 1, dt dv = −y − 0.1y 3 ; v(0) = 0. • dt • Editing rhs and running rk4 gives the following output: >> [time, zzrk4, nfeval] = rk4([1;0],0.3,3); RK4 iteration in 2 dimensions ... t x y 0.00 1.000000 0.000000 0.10 0.994506 -0.109762 0.20 0.978095 -0.218104 0.30 0.950979 -0.323645 all done 10 15. A sphere floating in water (in the absence of friction and with its centre y above the water level) experiences a force due to gravity of − 34 πr 3 ρg and a force due to buoyancy of 13 ρwater π 2r 3 + y(y 2 − 3r 2 ) g. It’s motion is determined by the ODE ρwater y y3 d2 y = −g + g 2+ 3 −3 dt2 4ρ r r A 0.4 metre radius sphere with density 0.7 of that of water is initially at rest with its centre 25 cm below the level of the water. You may assume that g = 10 ms−2 . (a) Express the equation of motion as a system of two first-order equations and state the appropriate initial conditions. (b) Take a step size of h = 0.1 and compute two steps of Runge–Kutta to estimate the position of the centre of the sphere when t = 0.1 and when t = 0.2. The first step is to express the second-order problem as a coupled firstorder system: dy = v with y(0) = −0.25 dt ρwater y y3 dv = −g + g 2+ 3 −3 with v(0) = 0 • dt 4ρ r r • Next, we substitute the given values for the parameters to give dy = v with y(0) = −0.25 dt 25 20 3125 3 375 dv = −10 + y − y 2 + 15.625y 3 − 7.5y = − + • dt 7 7 56 14 with v(0) = 0 • Finally, editing rhs and running rk4 gives the following output: >> [time, zzrk4, nfeval] = rk4([-0.25;0],0.2,2); RK4 iteration in 2 dimensions ... t x y 0.00 -0.250000 0.000000 0.10 -0.235369 0.288436 0.20 -0.194009 0.525712 all done The sphere is quickly floating back to the surface! Running rk4 for longer times suggests that the sphere tends to bob up and down in the water. This is illustrated by the following output. 11 >> [time, zzrk4, nfeval] = rk4([-0.25;0],10,100); RK4 iteration in 2 dimensions ... t x y 0.00 -0.250000 0.000000 0.00 -0.250000 0.000000 0.10 -0.235369 0.288436 0.20 -0.194009 0.525712 0.30 -0.133823 0.656006 0.40 -0.067990 0.633737 0.50 -0.012547 0.451335 0.60 0.018247 0.151392 0.70 0.016357 -0.188037 0.80 -0.017715 -0.478234 0.90 -0.075068 -0.643951 1.00 -0.140999 -0.647951 1.10 -0.199604 -0.503193 1.20 -0.238239 -0.257729 1.30 -0.249634 0.032871 1.40 -0.231837 0.317951 1.50 -0.187943 0.545862 1.60 -0.126467 0.660830 1.70 -0.061066 0.620233 1.80 -0.007808 0.422030 1.90 0.019567 0.113801 2.00 0.013912 -0.224085 2.10 -0.023284 -0.503314 . . . 9.80 -0.009216 -0.422804 9.90 -0.062376 -0.617180 10.00 -0.127317 -0.654832 all done >> plot(time,zzrk4(1,:),’-kx’), axis square 16. Compute a centered difference approximation to the BVP x2 dy d2 y − 4x + 4y = x3 , 2 dx dx x ∈ (1, 2); y(1) = 1, y(2) = 6, using a grid of size h = 0.25. Compare your result with the exact solution values y(1.25) = 4.771, y(1.5) = 5.9834, y(1.75) = 6.1867. We start by dividing the interval into 4 pieces so that x0 = 1, x1 = 1.25, x2 = 1.5, x3 = 1.75, x4 = 2, and then we define the grid values y0 = y(x0 ) = 1; y1 ≈ y(x1 ), y2 ≈ y(x2 ), 12 y3 ≈ y(x3 ), y4 = y(x4 ) = 6. We also define the two finite difference approximations 1 1 (yj−1 − 2yj + yj+1 ), y ′ (xj ) = (yj+1 − yj−1 ). 2 h 2h To simplify notation define y1 = A, y2 = B and y3 = C. • y ′′ (xj ) = The difference approximations at the point x1 = 1.25 are y ′ (xj ) ≈ B−1 0.5 = = −32A + 16B + 16. Substituting these 2B − 2 and y ′′ (xj ) ≈ B−2A+1 0.252 expressions into the ODE gives 1.252 (−32A + 16B + 16) + 4 × 1.25 (2B − 2) + 4A = 1.253 that is, −46A + 35B = −13.046875. The difference approximations at the point x2 = 1.5 are y ′ (xj ) ≈ C−A 0.5 = = 16A − 32B + 16C. Substituting these 2C − 2A and y ′′ (xj ) ≈ C−2B+A 0.252 expressions into the ODE gives 1.52 (16A − 32B + 16C) + 4 × 1.5 (2C − 2A) + 4B = 1.53 that is, 24A − 68B + 48C = 3.375. The difference approximations at the point x3 = 1.75 are y ′ (xj ) ≈ 6−B 0.5 = 12 − 2B and y ′′ (xj ) ≈ 6−2C+B = 96 − 32C + 16B. Substituting these 0.252 expressions into the ODE gives 1.752 (96 − 32C + 16B) + 4 × 1.75 (12 − 2B) + 4C = 1.753 that is 35B − 94C = −372.640625. Solving the 3 linear equations gives the results A = 4.90892(= y1 ), B = 6.07895(= y2 ) and C = 6.2277(= y3 ). Comparing with the exact values we see that the errors are of order of 0.1. 17. Compute a centered difference approximation to the BVP π2 d2 y + y = ǫy 3 , x ∈ (0, 1); y(0) = 1, y(1) = 0, dx2 4 for the value ǫ = 0.1, using a grid of size h = 0.5. Compare your computed result with the exact solution at the interior grid point. Dividing the interval into 2 pieces we introduce the unknown grid point value y1 ≈ y(0.5). To simplify notation we let A = y1 . 0−1 The difference approximations at the point x1 = 0.5 are y ′ (xj ) ≈ 2×0.5 = 0−2A+1 −1 and y ′′ (xj ) ≈ 0.52 = 4 − 8A. Substituting these expressions into the ODE gives 4 − 8A + (π 2 /4)A = 0.1A3 . This is a nonlinear equation. To solve it we set up a Newton iteration with f (A) = 4 + (π 2 /4 − 8)A − 0.1A3 so that f ′ (A) = π 2 /4 − 8 − 0.3A2 . The iteration converges to the solution A = 0.7163 (= y1 ). A |f (A)| f ′ (A) 0.0000 4.0000 −5.5326 0.7230 0.0377 −5.6894 0.7163 0.0000 −5.6865 13 The exact solution solution to the BVP when ǫ = 0 is the function y(x) = cos( πx 2 ) so that y(0.5) = 0.7071. The difference approximation is surprisingly accurate. 18. An iron bar is kept at temperatures T0 and T1 at its two ends. The radiation of heat at point x is proportional its temperature −AT (x) and 2 this effect is balanced by thermal diffusion, that is, −κ ddxT2 . Thus, when the temperature T (x) has reached equilibrium, it satisfies the BVP −κ d2 T = −AT, dx2 x ∈ (0, 1); T (0) = T0 , T (1) = T1 . Write down a centered difference approximation to T (x) for values of x of 0.25, 0.5 and 0.75 and solve the resulting linear system in the case where A = 1, κ = 1, T0 = 1 and T1 = 2. Multiplying by minus one and substituting parameter values gives d2 T −T =0 dx2 with T (0) = 1 and T (1) = 2. Let’s define grid values so that T (0.25) ≈ P , T (0.5) ≈ Q and T (0.75) ≈ R. +1 = The difference approximation at the point x1 = 0.25 is T ′′ (xj ) ≈ Q−2P 0.252 16Q − 32P + 16. Substituting this expression into the ODE gives 16Q − 33P + 16 = 0. (a) The difference approximation at the point x2 = 0.5 is T ′′ (xj ) ≈ R−2Q+P = 0.252 16R − 32Q + 16P . Substituting this expression into the ODE gives 16P − 33Q + 16R = 0. (b) The difference approximation at the point x3 = 0.75 is T ′′ (xj ) ≈ 2−2R+Q = 0.252 32 − 32R + 16Q. Substituting this expression into the ODE gives 16Q − 33R + 32 = 0. (c) Solving the 3 linear equations (a)–(c) gives the results P = 1.13019, Q = 1.33102 and R = 1.61504. Note that the exact solution to the BVP is T = 2e − 1 x e2 − 2e −x e + 2 e . e2 − 1 e −1 Thus the exact values are T (0.25) = 1.12963, T (0.5) = 1.33023, T (0.75) = 1.61440 so the numerical values are in good agreement. 14 19. Imagine two metal bars, one with ends maintained at temperature T = 600 and the other with a temperature maintained at T = 400. As well as thermal diffusion and general radiation, there is heat transferred from one bar to the other. The bars thus satisfy a coupled system of ODEs d2 T1 + 0.01 T1 + 0.005 (T1 − T2 ) = 0, dx2 d2 T2 −0.01 + 0.01 T2 + 0.005 (T2 − T1 ) = 0, dx2 −0.01 subject to T1 (0) = T1 (1) = 600 and T2 (0) = T2 (1) = 400. Take a grid with points x0 = 0, x1 = 0.25, x2 = 0.5, x3 = 0.75 and x4 = 1 and compute a centered difference approximation to T1 and T2 . First we introduce new functions y = 0.01T1 and z = 0.01T2 and substitute into the ODEs. This gives the rescaled equations: y ′′ − 1.5y + 0.5z = 0 z ′′ + 0.5y − 1.5z = 0 subject to y(0) = y(1) = 6 and z(0) = z(1) = 4. Let’s define grid values so that A ≈ y(0.25), B ≈ y(0.5), C ≈ y(0.75), D ≈ z(0.25), E ≈ z(0.5) and F ≈ z(0.75). Substituting the second derivative difference approximation into the ODEs evaluated at the grid points gives a system of 6 algebraic equations: 6 − 2A + B 0.252 C − 2B + A 0.252 B − 2C + 6 0.252 4 − 2D + E 0.252 D − 2E + F 0.252 E − 2F + 4 0.252 − 1.5A + 0.5D = 0 ⇐⇒ −67A + 32B + D + 192 = 0 − 1.5B + 0.5E = 0 ⇐⇒ 32A − 67B + 32C + E = 0 − 1.5C + 0.5F = 0 ⇐⇒ 32B − 67C + F + 192 = 0 − 1.5D + 0.5A = 0 ⇐⇒ A − 67D + 32E + 128 = 0 − 1.5E + 0.5B = 0 ⇐⇒ B + 32D − 67E + 32F = 0 − 1.5F + 0.5C = 0 ⇐⇒ C + 32E − 67F + 128 = 0 Solving these equations gives A = 5.42, B = 5.23, C = 5.42, D = 3.73, E = 3.64, F = 3.73. The corresponding temperature estimates are x = 0 x = 0.25 x = 0.5 x = 0.75 x = 1 Bar 1 600 542 523 542 600 Bar 2 400 373 364 373 400 15
© Copyright 2026 Paperzz