Discretization of second order nonlinear ODE using finite difference approximation not correct

1.9k Views Asked by At

I have the differential equation $$y'' + x(y^2)' - 2y^2 = g(x) \Longleftrightarrow y'' + x2yy'-2y^2 = g(x).$$ Using finite-difference approximations $$y''(x_m) \approx \frac{Y_{m-1} - 2Y_m + Y_{m+1}}{\Delta x^2},$$ $$y'(x_m) \approx \frac{Y_{m+1} - Y_{m-1}}{2\Delta x},$$ $$y(x_m) \approx Y_m,$$ I get $$\frac{Y_{m-1} - 2Y_m + Y_{m+1}}{\Delta x^2} + \frac{x_m}{\Delta x}Y_m(Y_{m+1}-Y_{m-1}) - 2Y_m^2 = g(x_m).$$ However, the answer is supposed to be enter image description here

Why is the second term in my answer wrong?

1

There are 1 best solutions below

0
On BEST ANSWER

In the second version they are using a finite difference representation of the term $y^2$:

$$ (y^2)' \approx \frac{y^2_{m + 1} - y^2_{m - 1}}{2\Delta x} \tag{1} $$

While you are using a finite representation of $2y y'$:

$$ 2y y' \approx 2y_m\frac{y_{m + 1} - y_{m - 1}}{2\Delta x} \tag{2} $$

But they are equivalent, if you take (if the solution $y$ is smooth enough you can do approximate the value at a node with the average of its neighbor nodes)

$$ y_m \approx \frac{y_{m + 1} + y_{m - 1}}{2} \tag{3} $$

Then Eq. (2) becomes

$$ 2yy' \approx 2y_m\frac{y_{m + 1} - y_{m - 1}}{2\Delta x} \approx (y_{m + 1} + y_{m - 1})\frac{y_{m + 1} - y_{m - 1}}{2\Delta x} = \frac{y^2_{m + 1} - y^2_{m - 1}}{2\Delta x} \approx (y^2)' $$