Take the 2-minute tour ×
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.

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

share|improve this question
1  
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. –  Niklas rtz Sep 21 '12 at 12:15

1 Answer 1

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|improve this answer

Your Answer

 
discard

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.