Step 1: Understanding the differential equation.
The given differential equation is:
\[
\frac{d^2 y}{dx^2} + y = 0
\]
This is a second-order linear homogeneous differential equation with constant coefficients. The general form of the solution to this equation is:
\[
y(x) = C_1 \cos x + C_2 \sin x
\]
This solution comes from the fact that the characteristic equation for this differential equation is \( r^2 + 1 = 0 \), which has the roots \( r = \pm i \), leading to a solution involving sine and cosine functions.
Step 2: Applying the initial conditions.
We are given the initial conditions:
1. \( y(0) = 1 \)
2. \( y\left( \frac{\pi}{2} \right) = 2 \)
Let’s first apply the initial condition \( y(0) = 1 \):
Substitute \( x = 0 \) into the general solution:
\[
y(0) = C_1 \cos 0 + C_2 \sin 0 = C_1
\]
Since \( y(0) = 1 \), we get:
\[
C_1 = 1
\]
Now, apply the second initial condition \( y\left( \frac{\pi}{2} \right) = 2 \):
Substitute \( x = \frac{\pi}{2} \) into the general solution:
\[
y\left( \frac{\pi}{2} \right) = C_1 \cos \frac{\pi}{2} + C_2 \sin \frac{\pi}{2}
\]
Since \( \cos \frac{\pi}{2} = 0 \) and \( \sin \frac{\pi}{2} = 1 \), this simplifies to:
\[
y\left( \frac{\pi}{2} \right) = C_2
\]
Since \( y\left( \frac{\pi}{2} \right) = 2 \), we have:
\[
C_2 = 2
\]
Step 3: Final solution.
Substitute the values of \( C_1 \) and \( C_2 \) into the general solution:
\[
y(x) = 1 \cdot \cos x + 2 \cdot \sin x = \cos x + 2 \sin x
\]
Thus, the solution is:
\[
y(x) = 2 (\cos x + \sin x)
\]