Step 1: Rearranging the Differential Equation The provided differential equation is \( (1 + \sin x) \frac{dy}{dx} + \cos x = 0 \). We can write this as \( (1 + \sin x) dy = -\cos x dx \). To solve for \( y \), we separate the variables such that all terms involving \( y \) are on one side and those involving \( x \) are on the other: \( dy = -\frac{\cos x}{1 + \sin x} dx \).
Step 2: Integration using Substitution We integrate both sides: \( \int dy = -\int \frac{\cos x}{1 + \sin x} dx \). Let us substitute \( u = 1 + \sin x \). Then, differentiating with respect to \( x \) gives \( \frac{du}{dx} = \cos x \), or \( du = \cos x dx \). Substituting these into the integral, we get \( y = -\int \frac{1}{u} du \), which evaluates to \( y = -\ln|u| + C \). Substituting back for \( u \), we obtain the general solution: \( y = -\ln|1 + \sin x| + C \).
Step 3: Applying Initial Conditions We are given that when \( x = 0 \), \( y = 0 \). Substituting these values: \( 0 = -\ln|1 + \sin 0| + C \). Since \( \sin 0 = 0 \) and \( \ln 1 = 0 \), we find that \( C = 0 \). Thus, the particular solution is \( f(x) = -\ln(1 + \sin x) \).
Step 4: Evaluating the final value To find \( f\left(\frac{\pi}{2}\right) \), we substitute \( x = \frac{\pi}{2} \) into our particular solution: \( f\left(\frac{\pi}{2}\right) = -\ln\left(1 + \sin\frac{\pi}{2}\right) \). Knowing that \( \sin\frac{\pi}{2} = 1 \), we get \( -\ln(1 + 1) = -\ln 2 \).