I have problem with plotting an differential equation that is as following:
$$ \frac{d^2y}{dx^2} + \pi y e^{x/3}\big(2\frac{dy}{dx} \sin(\pi x) + \pi y\cos(\pi x)\big)=\frac{y}{9} $$
where the beginning values are $y(0)=1$ and $\frac{dy}{dx}(0)=-\frac{1}{3}$.
What I have done first is to re-write this differential equation (a second order differential equation) in two 1st order differential equations using $u_1=y$ and $u_2=\frac{dy}{dx}$ as following:
$$ \frac{du_1}{dx}=u_2 $$ $$ \frac{du_2}{dx}=\frac{u_1}{9}-\pi u_1 e^{x/3}\big(2 u_2\sin(\pi x)+\pi u_1\cos(\pi x)\big) $$
If the equations are unclear, can someone please format them so they look better for better understanding. Thanks in advance.
I wanted to solve the equation by the help of RK4 (Runge-Kutta 4th order) and plot the solution in MATLAB. My MATLAB codes are as follows:
xend = 2.6; %The endpoint
h = 0.2; %Stage between two consecutive x-points
x = 0; %The startpoint
u = [1 -1/3]; %The beginning values for the 1st order equations
X = x; %Matrix in which I save all my x-values
U = u; %Matix in which I save all my y-values
while x<xend-h/2
f1 = RK4(x,u);
f2 = RK4(x+h/2,u+h*f1/2);
f3 = RK4(x+h/2,u+h*f2/2);
f4 = RK4(x+h,u+h*f3);
u = u + h*(f1+f2/2+f3/2+f4)/6;
x = x + h;
X = [X;x];
U = [U;u];
end
plot(X,U); %Plot the solution
And here follows the codes for RK4:
function fp = RK4(x,u)
fp = [u(2) u(1)/9-pi*u(1)*exp(x/3)*(2*u(2)*sin(pi*x)+pi*u(1)*cos(pi*x))];
end
And the plot that I get by this equation is on the link below:

Can somebody please explain why I get a bad graph? I tried so much that I could, but I couldn't find anything.
Thanks in advance for helping me figure out with this!