solving a 2nd order initial value problem

376 Views Asked by At

I'm trying to solve the IVP $-y''+y=0$ with $y(0)=1$ and $y'(0)=0$ using the 3-difference method to find $y(4\pi).$

Here is my attempt:

Applying the 3-difference method to approximate the second derivative, the problem becomes $-\frac{1}{h^2}(y_{i+1}-2y_{i}+y_{i-1})+y_{i}=0$ for $i=2,\dots,N-1.$ Using the first initial condition $y(0)=1$ I get $y_{0}=1.$ From the second initial condition together with the forward difference formula of the first derivative I have $0=y'(0)\approx\frac{y_{1}-y{0}}{h}$ hence $y_{1}=1.$

The problem becomes for N=10:

\begin{equation} \begin{pmatrix} 1 & 0 & \dots & 0\\ \frac{2}{h^2}+1 & -\frac{1}{h^2} & 0 & \dots & 0 \\ -\frac{1}{h^2} & \frac{2}{h^2}+1 & -\frac{1}{h^2} & 0 & \dots & 0 \\ 0 & -\frac{1}{h^2} & \frac{2}{h^2}+1 & -\frac{1}{h^2} & 0 & \dots & 0 \\ \vdots \\ 0 & \dots & 0 & -\frac{1}{h^2} & \frac{2}{h^2}+1 & -\frac{1}{h^2} \\ \end{pmatrix} \begin{pmatrix} y_{1} \\ y_{2} \\ y_{3} \\ \vdots \\ \vdots \\ y_{10} \end{pmatrix} = \begin{pmatrix} 1 \\ \frac{1}{h^2} \\ 0 \\ \vdots \\ \vdots \\ 0 \end{pmatrix} \end{equation}

Now, as I solve this system I have these results for the values of $y$: 1,8,27,88,... and the values are increasing. However, I know the exact solution and $y(4\pi)=1$ but I don't know where is my mistake...

I appreciate any help :)

1

There are 1 best solutions below

1
On BEST ANSWER

The exact solution to the stated and approximated equation is $y(x)=\cosh(x)$ with $$y(4\pi)=\cosh(4\pi)=143375.65657007025,$$ so a rapid growth of function values and errors is to be expected.

To get the expected solution $y(4\pi)=\cos(4\pi)=1$ you need to solve and approximate $y''(x)+y(x)=0$ or $-y''(x)=y(x)$. Even then, the step size of $h=0.4\pi=1.256637..$ will likely be too large for this second order method, a step size of $h=0.5$ or smaller might be more appropriate.