title: Implementing Euler's Method in GNU Octave
body: <p>I am reading "Numerical Methods for Engineers" by Chapra and Canale. In it, they've provided pseudocode for the implementation of Euler's method (for solving ordinary differential equations). Here is the pseucode:</p>
  
  <p><a href="https://i.stack.imgur.com/FX2zB.png" rel="nofollow noreferrer">Pseucode for implementing Euler's method</a></p>
  
  <p>I tried implementing this code in GNU Octave, but depending on the input values, I am getting one of two errors:</p>
  
  <ol>
  <li>The program doesn't give any output at all. I have to press 'Ctrl + C' in order to break execution.</li>
  <li>The program gives this message:</li>
  </ol>
  
  <pre><code>error: 'ynew' undefined near line 5 column 21
  error: called from
      Integrator at line 5 column 9
      main at line 18 column 7
  </code></pre>
  
  <p>I would be very grateful if you could get this program to work for me. I am actually an amateur in GNU Octave. Thank you. </p>
  
  <p><strong>Edit 1</strong>: Here is my code. For main.m:</p>
  
  <pre><code>%prompt user
  y = input('Initial value of y:');
  xi = input('Initial value of x:');
  xf = input('Final value of x:');
  dx = input('Step size:');
  xout = input('Output interval:');
  
  x = xi;
  m = 0;
  xpm = x;
  ypm = y;
  
  while(1)
      xend = x + xout;
      if xend &gt; xf
        xend = xf;
        h = dx;
        Integrator(x,y,h,xend);
        m = m + 1;
        xpm = x;
        ypm = y;
        if x &gt;= xf
          break;
        endif
      endif  
  end
  </code></pre>
  
  <p>For Integrator.m:</p>
  
  <pre><code>function Integrator(x,y,h,xend)
      while(1)
        if xend - x &lt; h
          h = xend - x;
          Euler(x,y,h,ynew);
          y = ynew;
          if x &gt;= xend
            break;
          endif
        endif    
      end
  endfunction
  </code></pre>
  
  <p>For Euler.m:</p>
  
  <pre><code>function Euler(x,y,h,ynew)
     Derivs(x,y,dydx);
     ynew = y + dydx * h;
     x = x + h;
  endfunction
  </code></pre>
  
  <p>For Derivs.m:</p>
  
  <pre><code>function Derivs(x,y,dydx)
      dydx = -2 * x^3 + 12 * x^2 - 20 * x + 8.5;
  endfunction
  </code></pre>
  
  <p><strong>Edit 2</strong>: I shoud mention that the differential equation which Chapra and Canale have given as an example is:</p>
  
  <blockquote>
    <p>y'(x) = -2 * x^3 + 12 * x^2 - 20 * x + 8.5</p>
  </blockquote>
  
  <p>That is why the 'Derivs.m' script shows dydx to be this particular polynomial. </p>