title: Do functions always require their own separate files?
body: <p>I am trying to run a script I found on a pdf that requires defining a function <code>tor.m</code></p>
  <p>This is the script for the function:</p>
  <pre><code>function xp=tor(t,x)
  xp=zeros(4,1);
  xp(1)=x(2);
  xp(2)=-(2+cos(x(1)))*sin(x(1))*x(4)^2;
  xp(3)=x(4);
  xp(4)=2*(sin(x(1))/(2+cos(x(1))))*x(2)*x(4);
  </code></pre>
  <p>I tried defining the function within the rest of the script, as I would in R or Python, but it doesn't seem to work.</p>
  <p><strong>Do functions always require their own separate files in Matlab / Octave? Can I include both the function and the rest of the code in one single file?</strong></p>
  <p>Here is the rest of the code:</p>
  <pre><code>[u,v]=meshgrid(linspace(0,2*pi,36),linspace(0,2*pi,36));
  x=(2+cos(u)).*cos(v);
  y=(2+cos(u)).*sin(v);
  z=sin(u);
  
  surf(x,y,z)
  hold on
  [t,X]=ode23s('tor',[0,20*pi] ,[pi/2,.1,-pi/2,.2]);
  u=X(:,1);
  v=X(:,3);
  x=(2+cos(u)).*cos(v);
  y=(2+cos(u)).*sin(v);
  z=sin(u);
  plot3(x,y,z,'-', 'color', 'y', 'MarkerSize', 50)
  </code></pre>
  <hr />
  <p>Error:</p>
  <pre><code>function xp=tor(t,x)
  xp=zeros(4,1);
  xp(1)=x(2);
  xp(2)=-(2+cos(x(1)))*sin(x(1))*x(4)^2;
  xp(3)=x(4);
  xp(4)=2*(sin(x(1))/(2+cos(x(1))))*x(2)*x(4);
  end
  [u,v]=meshgrid(linspace(0,2*pi,36),linspace(0,2*pi,36));
  x=(2+cos(u)).*cos(v);
  y=(2+cos(u)).*sin(v);
  z=sin(u);
  
  surf(x,y,z)
  hold on
  [t,X]=ode23s('tor',[0,20*pi] ,[pi/2,.1,-pi/2,.2]);
  u=X(:,1);
  v=X(:,3);
  x=(2+cos(u)).*cos(v);
  y=(2+cos(u)).*sin(v);
  z=sin(u);
  plot3(x,y,z,'-', 'color', 'y', 'MarkerSize', 50)
  
  &gt;&gt; test
  
  warning: function name 'tor' does not agree with function filename 'C:\Users\ParellaA\Documents\Octave\test.m'
  error: 'x' undefined near line 3, column 7
  error: called from
      test at line 3 column 6
  </code></pre>