Problem 1 a) Given second order equation 𝜕2𝑦 = 𝑦 + sinx 𝜕𝑥 2 From Central Difference formula, we know that 𝜕2𝑦 𝑦𝑖−1 − 2𝑦𝑖 + 𝑦𝑖+1 = 𝜕𝑥 2 ℎ2 Substitute this in the given ODE, 𝑦𝑖−1 − 2𝑦𝑖 + 𝑦𝑖+1 = 𝑦𝑖 + sin (𝑥𝑖 ) ℎ2 By solving, we get 𝑦𝑖−1 − (2 + ℎ2 )𝑦𝑖 + 𝑦𝑖+1 = ℎ2 sin (𝑥𝑖 ) This is then ODE discretized into a finite difference formula with i = 1,2,3 ………. (n-1). b) We have the value of h as 1 Iterate the discretized ODE by varying the ‘i’ values from 1 to n-1 If we do that, we get For i = 1: −3𝑦1 + 𝑦2 = sin(𝑥1 ) For i = 2: 𝑦1 − 3𝑦 + 𝑦3 = sin (𝑥2 ) For i = 3: 𝑦2 − 3𝑦3 + 𝑦4 = sin (𝑥3 ) For i = 4: 𝑦3 − 3𝑦4 + 𝑦5 = sin (𝑥4 ) If we compile these equations into Matrix form, we get, −3 1 0 0 0 0 0 0 [ 0 1 −3 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 −3 1 0 0 1 −3 1 0 0 1 −3 1 0 0 1 −3 0 0 0 1 0 0 0 0 0 0 0 0 𝑦2 0 0 0 𝑦2 0 0 0 𝑦3 0 0 0 𝑦4 0 0 0 𝑦5 = 0 0 0 𝑦6 0 0 0 −3 1 0 𝑦7 1 −3 1 𝑦8 0 1 −3] [𝑦9 ] sin(𝑥1 ) − 𝑦0 sin(𝑥2 ) sin(𝑥3 ) sin(𝑥4 ) sin(𝑥5 ) sin(𝑥6 ) sin(𝑥7 ) sin(𝑥8 ) [sin(𝑥9 ) − 𝑦𝑛−1 ] From the matrix, upper and lower diagonal elements are 1 and main diagonal elements are 3. init = bvpinit(linspace(0,20),[0.2,0.2]); result = bvp4c(@ODE, @BC, init); plot(result.x, result.y(1,:)) title('Boundary Value Problem') xlabel('distance') ylabel('Height of cable') function dydx = ODE(x,yv) dydx = [yv(2); 0.041*sqrt(1+(yv(2))^2)]; end function sol = BC(y_a, y_b) BC_a = 10; BC_b = 15; sol = [y_a(1) - BC_a; y_b(1) - BC_b]; end Published with MATLAB® R2019b 1