title: Matlab Fucntion Debug (Error: File: sodifficult.m Line: 1 Column: 28 Function definition is misplaced or improperly nested.)
body: <p>Question: A photon moving at speed 1 in the x–y plane starts at t = 0 at (x, y) = (0.5, 0.1) heading due east. Around every integer lattice point (i, j) in the plane, a circular mirror of radius 1/3 has been erected. How far from the origin is the photon at t = 10?</p>
  
  <p>error: 
  Error: File: sodifficult.m Line: 1 Column: 28
  Function definition is misplaced or improperly nested.</p>
  
  <pre><code>function [ output_args ] = function( input_args )
  C=[1,-1,0,0,-1,0,-1,0,0,-1,0,-1,-1,-1;0,1,2,1,2,0,0,1,0,0,-1,-1,0,-1]
  lx=zeros(1,15);
  ly=zeros(1,15);
  x=zeros(1,15);
  y=zeros(1,15);
  t=zeros(1,15);
  ttotal=zeros(1,15);
  ux=zeros(1,14);
  uy=zeros(1,14);
  vx=zeros(1,14);
  vy=zeros(1,14);
  x0=0.5;
  y0=0.1;
  lx(1)=1;
  ly(1)=0;
  x(1)=1-sqrt(0.91)/3;
  y(1)=0.1;
  t(1)=x(1)-x0;
  ttotal=t(1);
  
  for k=1:14
      ux(k)=3*(x(k)-C(1,k))
      uy(k)=3*(y(k)-C(2,k))
      vx(k)=-uy(k)
      vy(k)=ux(k)
      i=k+1
      lx(i) = -(lx(k)*ux(k)+ly(k)*uy(k))*ux(k)+(lx(k)*vx(k)+ly(k)*vy(k))*vx(k)
      ly(i) = -(lx(k)*ux(k)+ly(k)*uy(k))*uy(k)+(lx(k)*vx(k)+ly(k)*vy(k))*vy(k)
      if k&lt;14
          b = lx(i)*(x(k)-C(1,i)) + ly(i)*(y(k)-C(2,i))
          c = (x(k)-C(1,i))^2 + (y(k)-C(2,i))^2 - 1/9
          t(i) = -b-sqrt(b*b-c)
          ttotal = ttotal + t(i)
      else
          t(i)=1-ttotal
          ttotal=1
      end
          x(i)=x(k)+t(i)*lx(i)
          y(i)=y(k)+t(i)*ly(i)
  end
  
  d = sqrt(x(15)^2+y(15)^2)
  end
  </code></pre>