I am attempting to learn from a textbook that has the following question:
The boundary-value problem $$ y'' = 4(y-x), \qquad 0 \leq x \leq 1, \qquad y(0)=0, \, \, \, y(1)=2 $$ has the solution $y(x) = e^2(e^4 -1)^{-1} (e^{2x}-e^{-2x})+x$. Use the linear shooting method to approximate the solution, and compare the results to the actual solution. Also, $h = \frac{1}{2}$.
This is not mentioned in the question itself, but by looking at the solution, I believe the solution wants us to give the numerical approximation of $y(0.5)$. Thank you.
So I'm mostly just focusing on the "approximate the solution" section. I've read so many textbooks but I just can't get my head around it, so I'm having to ask on here. I see that you make an initial approximation $y'(a) = \lambda$. And then you use a linear equation in the form:
$$\lambda = \frac{\beta - y_o(b)}{z(b)}$$ to determine $\lambda$.
I also think we can use:
$$y_\lambda(x) = y_0(x) + \lambda z(x)$$
I also know you get two equations. I have done it in this manner:
$$y'(x) = z(x)$$ $$z'(x) = 4y(x)-4x$$
And we then want to find $y_0(x)$ and $z(x)$ I think?. Using Euler's or Runge-Kutta or something? Let us use Runge-Kutta 4 for the sake of this post.
Any help is appreciated. I'm also stuck on the non-linear version, but I'm just going to try and get my head around the linear version for now... I also know this isn't the best written question, sorry. I'm just very lost.
Edit: As nobody has gotten the answer yet it seems, I thought I would post it. The textbook answer is: "0.82432432" as the approximation. Anybody know how to get that result? Thank you.
The value of $y'(a)$ depends on the method you use and the step size. However, because your system is linear, solving for $y'(a)$ is just a single step linear interpolation/extrapolation. Alternatively, you can keep track of $y'(a)$ during your iterations (since the DE is linear, every step of the approximate solution is going to look like $y=y_0+y'(a)y_1$) and solve for $y'(a)$ at the end.
First, convert your second-order equation to a first-order equation: $$ \begin{pmatrix}y\\y'\end{pmatrix}' =\begin{pmatrix}y'\\4(y-x)\end{pmatrix} $$
For example, if you use Euler's method with step size $h=1$, using $y(0)=0$ and $y_{approx}'(1)=\lambda$ $$ \begin{pmatrix} y_{approx}(x=1)\\y'_{approx}(x=1) \end{pmatrix}= \begin{pmatrix} 0\\\lambda \end{pmatrix}+ \begin{pmatrix} \lambda\\0 \end{pmatrix} $$ So $\lambda_1=0$ this scheme gives $y_{approx}(1;\lambda_1)=0$ and for $\lambda_2=10$ (say) we have $y_{approx}(1;\lambda_2)=10$. A linear interpolation gives the next candidate $$ \lambda=\frac{y(1)-y_{approx}(1;\lambda_1)}{y_{approx}(1;\lambda_2)-y_{approx}(1;\lambda_1)}=2,$$ and of course you find $y_{approx}(1;\lambda=2)=2$.
As another example, again with Euler's method, this time $h=\frac14$. So \begin{align*} \begin{pmatrix}y_{approx}(1/4)\\y'_{approx}(1/4)\end{pmatrix} &=\begin{pmatrix}0\\\lambda\end{pmatrix} +\frac14\begin{pmatrix}\lambda\\0\end{pmatrix} =\begin{pmatrix}\frac14\lambda\\\lambda\end{pmatrix}\\ \begin{pmatrix}y_{approx}(2/4)\\y'_{approx}(2/4)\end{pmatrix} &= \begin{pmatrix}\frac14\lambda\\\lambda\end{pmatrix}+\frac14 \begin{pmatrix}\lambda\\\lambda-1\end{pmatrix} =\begin{pmatrix}\frac12\lambda\\\frac54\lambda-\frac14\end{pmatrix}\\ \begin{pmatrix}y_{approx}(3/4)\\y'_{approx}(3/4)\end{pmatrix} &= \begin{pmatrix}\frac12\lambda\\\frac54\lambda-\frac14\end{pmatrix}+\frac14 \begin{pmatrix}\frac54\lambda-\frac14\\2\lambda-2\end{pmatrix} =\begin{pmatrix}\frac{13}{16}\lambda-\frac1{16}\\\frac74\lambda-\frac34\end{pmatrix}\\ y_{approx}(1) &=\left(\frac{13}{16}\lambda-\frac1{16}\right)+\frac14\left(\frac74\lambda-\frac34\right)=\frac54\lambda-\frac14 \end{align*} So in the end you find $\lambda=\frac95$.
With RK4 and $h=\frac12$, you get \begin{align*} k_1&=(\frac\lambda2, 0)\\ k_2&=(\frac\lambda2, \frac\lambda2 - \frac12)\\ k_3&=(\frac58\lambda - \frac18, \frac\lambda2 - \frac12)\\ k_4&=(\frac34\lambda - \frac14, \frac54\lambda - \frac54) \end{align*} So $$(y_{approx}(h),y'_{approx}(h))=\left(\frac7{12}\lambda - \frac1{12},\frac{37}{24}\lambda - \frac{13}{24}\right)$$ and a further RK4 step yields $$ y_{approx}(1)=\frac{259}{144}\lambda - \frac{115}{144}. $$ So $\lambda=\frac{403}{259}\approx1.556$, $y_{approx}(h)=\frac{61}{74}\approx 0.8243$.