# linear shooting method and finite differences

how can we use the linear shooting method to approximate this solution below:

$$y'' + 4y = \cos(x), 0 \le x \le4, y(0) = 0, y(pi/4) = 0, h = \frac{\pi}{20}$$

My concern is with the RK-4 and setting this up so I can do some iterations can someone please provide a setup and possibly solve this so I can understand it well?

Thanks

• Do you understand how shooting works, conceptually? – Emily Apr 13 '13 at 2:54
• Were you given another BV y(b) = c, something like $y(\pi) = \beta$? – Amzoti Apr 13 '13 at 3:23
• @Amzoti, I went ahead and provided it. Thanks for noticing the typo – mary Apr 13 '13 at 4:46

We are given:

$\tag 1 \displaystyle y'' + 4y = \cos(x), 0 \le x \le4, y(0) = 0, y\left(\frac{pi}{4}\right) = 0, h = \frac{\pi}{20}$

We know that if the linear boundary-value problem:

$y'' = p(x)y' + q(x)y+r(x), a \le x \le b, y(a) = \alpha, y(b) = \beta$, satisfies:

(i) $p(x), q(x)$, and $r(x)$ are continuous on $[a, b]$

(ii) $q(x) \gt 0$ on $[a, b].$

We can get a unique solution.

For this problem, we have:

$y_1(x): y'' = p(x) y' + q(x) y + r(x)$, and

$y_2(x): y'' = p(x) y' + q(x) y$

So,

$p(x) = 0$

$q(x) = 4$

$r(x) = \cos x$

With the same BCs given in $(1)$.

For comparison purposes, $(1)$ has the exact solution:

$$\tag 2 \displaystyle y(x) = \frac{1}{3} (\sin^2 x - \cos^2 x + \cos x - \sqrt 2 \sin x \cos x).$$

To apply the Linear Shooting Algorithm, we just do some setup, calculate the fourth order Runge-Kutta values over N and then output the approximations to our linearized functions.

Step 1:

$\displaystyle h = \frac{b-a}{N} = \frac{\frac{\pi}{4} - 0}{5} = \frac{\pi}{20}$ (this implies $N = 5$)

$u_{1,0} = \alpha = 0$

$u_{2,0} = 0$

$v_{1,0} = 0$

$v_{2,0} = 1$

Step 2: For $i = 0, \ldots, N-1 = 5 - 1 = 4$, do Steps 3 and 4 (Runge - Kutta Method)

Step 3 Set $\displaystyle x = a + i h = a + i\left(\frac{\pi}{20}\right)$

Step 4:

$\displaystyle k_{1,1} = hu_{2,1} = \frac{\pi}{20}u_{2,1}$

$\displaystyle k_{1,2} = h[p(x)u_{2,i}+q(x)u_{1,i} + r(x)$

$\displaystyle k_{2,1} = h[u_{2,i} + \frac{1}{2}k_{1,2}]$

$\displaystyle k_{2,2} = h[p(x+ h/2)(u_{2,i} + \frac{1}{2}k_{1,2}) + q(x + h/2)(u_{1,i} + \frac{1}{2}k_{1,1}) + r(x + h/2)]$

$\ldots$

(You can now continue this as this is more an algorithms problem than a math problem - and you can find this algorithm on the web or any numerical analysis book).

Step 5

Set $w{1,0} = \alpha$

$\displaystyle w_{2,0} = \frac{\beta - u_{1, N}}{v_{1,N}} = \frac{0 - u_{1,5}}{v_{1,5}}$ (you calculated these above)

output($a, w_{1,0}, w_{2,0}$)

Step 6 For $i = 1, \ldots, N = 5$, set

$W1 = u_{1,i} + w_{2,0}v_{1,i}$

$W2 = u_{2,i} + w_{2,0}v_{2,i}$

$x = a + i h = a + i \frac{\pi}{20}$

output($x, W1, W2$), which are the $x_i, w_{i,1}, w_{2,i}$

STEP 7: Stop

Of course, you should see similar results that converge to the values of the exact $y(x)$ starting at $x = 0$ and ending at $x = 4$, and you know the exact result to compare to from $(2)$.

Hope that all makes sense!

• could you please list out the RK-4 steps? This cant be coded – mary Apr 13 '13 at 5:54
• @mary: I added more details about the functions and the algorithm, but this is no longer a math problem, but an algorithms problem. You can find it in any numerical analysis book or the web. I provided the approach, the closed form solution, the intermediate linear functions and some details on how to do the algorithm. There should be more than enough now for you to continue. Regards – Amzoti Apr 13 '13 at 6:08
• Nice work, Amzoti! So detailed! +1 – Namaste Apr 14 '13 at 0:33