title: ode23 in MatLab - using optional arguments as input
body: <p>I am trying to learn MatLab on my own.  I get most of the concepts regarding solving ODEs, but I am a little unsure about the use of optional arguments as input.  I have created the following function:</p>
  
  <pre><code>function xdot = funn(t,x,mu);
  if nargin &lt; 3 | isempty(mu)
      mu = 1;
  end
  xdot = t +mu*x;
  </code></pre>
  
  <p>In addition I have defined:</p>
  
  <pre><code>tspan = [0 2];
  x0 = 0;
  options = odeset('outputfcn','odeplot');
  </code></pre>
  
  <p>What I am unsure about is how to change the variable <code>mu</code> when I use the <code>ode23</code> function.  I understand that this should be possible through the input of optional arguments, but I can't get it to work.  Say if I write:</p>
  
  <pre><code>[t y] = ode23('funn',tspan,x0,options)
  </code></pre>
  
  <p>Then everything computes correctly, and we automatically get <code>mu</code> = 1.</p>
  
  <p>But if I want to change this, how do I proceed?  I tried writing the following to set <code>mu</code> = 4:</p>
  
  <pre><code>[t y] = ode23('funn',tspan,x0,options,4)
  </code></pre>
  
  <p>But then I just get the following: </p>
  
  <pre><code>??? Error using ==&gt; funn
  Too many input arguments.
  
  Error in ==&gt; odearguments at 98
  f0 = feval(ode,t0,y0,args{:});   % ODE15I sets args{1} to yp0.
  
  Error in ==&gt; ode23 at 171
  [neq, tspan, ntspan, next, t0, tfinal, tdir, y0, f0, odeArgs, odeFcn, ...
  </code></pre>
  
  <p>I did this based on how I understood the procedure as it is written in my textbook, but obviously I'm doing something wrong here.  If anyone can explain how I go about changing the parameter <code>mu</code>, and in general how optional arguments <code>p1, p2, ...</code> are used with <code>ode23</code> I would really appreciate it!</p>