# Solve Boundary Value Problem for $y''+ y' + e^xy = f(x)$

Consider to solve Boundary Value Problem :

$y''+ y' + e^xy = f(x)$ with $0 < x < 1$

and $y(0)=y(1)=0$ with exact solution $y(x) = \sin \pi x$

$f(x)=(e^x- \pi^2)\sin \pi x + \pi \cos \pi x$.

How to plot two curves for exact solution and numerical solution by MATLAB?

Please check finite difference methods, like forward finite difference.

https://en.wikipedia.org/wiki/Finite_difference

For instance, you can use central difference to approximate the second order derivative, it is as

$y^{''}=\frac{y_{n-1}-2y_n+y_{n+1}}{h^2}$

You also can use central difference to approximate first order derivative, it is as

$y^{'}=\frac{y_{n+1}-y_{n-1}}{2h}$

Then your ODE could be changed as

$\frac{y_{n-1}-2y_n+y_{n+1}}{h^2}+\frac{y_{n+1}-y_{n-1}}{2h}+e^{x_n}y_n=f(x_n)$

Where $x_n=x_0+nh$

From here you would be able to solve the ODE from a very simple MATLAB code.

• I have the same problem, how to create the MATLAB code to plot the curves ? – user326307 Dec 5 '16 at 1:32