0
$\begingroup$

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? enter image description here

  • 0
    @RichieCotton thank you for the comment. I've now made an extensive effort and nearly solved the entire problem if you want to have a look and comment my code that I tried to write. I'm not sure whether my solution is correct.2012-09-21

1 Answers 1

2

Try using ode45, ode23 in matlab. These are commands to solve differential equations numerically. try help in matlab for more information about these commands