Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top


\begin{cases} y'' − Cxy = g(x),\\ y(2) = 1,\\ y'(2) = 0, \end{cases}


$$ 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''. $


$ u_2'-Cxu_1=g(x),\\ u_1(2)=1. u_2(0)=2. $

How do I continue?


I used this function file in matlab

function f=func(x,u)
global C;
if x<3

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

and I get this graph, is it correct? enter image description here

share|cite|improve this question
Have you written any code yet? Especially since this is a homework question, it is good to demonstrate that you've tried something before you ask for help. – Richie Cotton Sep 21 '12 at 9:44
@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. – Programmer 400 Sep 21 '12 at 12:15

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

share|cite|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.