The ODE
\begin{cases} y'' − Cxy = g(x),\\ y(2) = 1,\\ y'(2) = 0, \end{cases}
where
$ g(x) = \begin{cases} −1 & 2 \leq x \leq 3, \\ −1/3 & 3 \leq x \leq 5, \end{cases} $
should get solved for for $C=0.8$, $1$, and $2$ at the interval $2 \leq x \leq 5$.
I must write a MATLAB program that performs the calculation and draws the $3$ solution curves in the same graph.
I should rewrite the problem as a system of first order:
$ u_1 = y,\\ u_2 = y',\\ u_2' = y''. $
Hence
$ u_2'-Cxu_1=g(x),\\ u_1(2)=1. u_2(0)=2. $
How do I continue?
Update
I used this function file in matlab
function f=func(x,u) global C; if x<3 g=-1; else g=-x/3; end f=[u(2) C*x*u(1)+g];
then I run this program
>> global C; >> for C=[0.05 0.1 0.2] [X, U]=ode45(@func,[2 5],[1;0]); plot(X,U(:,1)); hold on end
and I get this graph, is it correct?