title: Pass extra variable parameters to ode15s function (MATLAB)
body: <p>I'm trying to solve a system of ordinary differential equations in MATLAB.</p>
  
  <p>I have a simple equation: 
  dy = -k/M *x - c/M *y+ F/M. </p>
  
  <p>This is defined in my ode function test2.m, dependant on the values X and t. I want to trig 'F' with a signal, generated by my custom function squaresignal.m. The output hereof, is the variable u, spanding from 0 to 1, as it is a smooth heaviside function. - Think square wave. The inputs in squaresignal.m, is t and f.   </p>
  
  <pre><code>u=squaresignal(t,f)
  </code></pre>
  
  <p>These values are to be used inside my function test2, in order to enable or disable variable 'F' with the value u==1 (enable). Disable for all other values.</p>
  
  <p>My ode function test2.m reads:</p>
  
  <pre><code>function dX = test2(t ,X, u)
  x = X (1) ;
  y = X (2) ;
  
  M = 10;
  k = 50;
  c = 10;
  F = 300;
  
  if u == 1
      F = F;
  else
      F = 0,
  end
  
  dx = y ;
  dy = -k/M *x - c/M *y+ F/M ;
  
  dX = [ dx dy ]';
  end
  </code></pre>
  
  <p>And my runscript reads:</p>
  
  <pre><code>clc
  clear all
  
  tstart = 0;
  tend = 10;
  tsteps = 0.01;
  
  tspan = [0 10];
  t = [tstart:tsteps:tend];
  f = 2;
  
  u = squaresignal(t,f)
  
  for ii = 1:length(u)
      options=odeset('maxstep',tsteps,'outputfcn',@odeplot);
      [t,X]=ode15s(@(t,X)test2(t,X,u(ii)),[tstart tend],[0 0],u);
  end
  
  
  figure (1);
  plot(t,X(:,1))
  
  figure (2);
  plot(t,X(:,2));
  </code></pre>
  
  <p>However, the for-loop does not seem to do it's magic. I still only get F=0, instead of F=F, at times when u==1. And i know, that u is equal to one at some times, because the output of squaresignal.m is visible to me. </p>
  
  <p>So the real question is this. How do i properly pass my variable u, to my function test2.m, and use it there to trig F? Is it possible that the squaresignal.m should be inside the odefunction test2.m instead?  </p>