title: Matlab - Implict and Explict Euler Method on Linear Differential Eqn
body: <p>As you can see on the heading, I would like to ask something about ODE's. Our teacher has uploaded some examples on internet but they just consist of the solutions. </p>
  
  <p>Here is one of them, which about to solution of following equations.  </p>
  
  <pre><code>m_1 l^2 ϕ''_1 + m_1glϕ_1 + cl(ϕ_1 - ϕ_2) = 0
  m_2 l^2 ϕ''_2 + m_2glϕ_2 + cl(ϕ_2 - ϕ_1) = 0
  </code></pre>
  
  <p>The point that I want to ask, as you can see on the solution there is a D matrix has defined. So, first row of this D matrix generally consist of 1 and 0s and the rest of it consists the constants which occured after the leaving dy/dt alone. What is this D matrix based on ? How I have to define that?</p>
  
  <p><i></p>
  
  <pre><code>%m1=100*m2
  % Parametres
  m_2=1;             
  m_1=100*m_2;        
  l=1;                
  c=1;
  g=10; 
  % Initial Conditions
  phi_1=1;
  phi_2=-0.5;
  dphi_1=0;
  dphi_2=0;
  
  % Iteration Parameters
  dt=0.01;            
  t_end=10;           
  
  % Time Vector
  t=0:dt:t_end;       
  n_max=t_end/dt;
  
  y(:,1)=[phi_1;phi_2;dphi_1;dphi_2];                                               
  D=[0 0 1 0;0 0 0 1;-g/l-c/(m_1*l) c/(m_1*l) 0 0;c/(m_2*l) -g/l-c/m_2/l 0 0];      
  
  y_exp=y;       
  for n = 1:n_max
      y_exp(:,n+1)=dt*D*y_exp(:,n)+y_exp(:,n);         
  end
  
  y_imp=y;
  for n = 1:n_max
      y_imp(:,n+1)=inv(eye(4)-D*dt)*y_imp(:,n);
  end
  </code></pre>
  
  <p></i></p>