linear shooting method and finite differences

2.4k Views Asked by At

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

1

There are 1 best solutions below

3
On BEST ANSWER

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!