title: Solving ODEs inside a Subsystem in Simulink
body: <p>I'm trying to figure out how to solve a system of ODEs inside a subsystem in a Simulink model. Basically, each call to this subsystem, which happens at each tick of the simulation clock (fixed-step), entails solving the ODEs. So there's like a different "clock" for the subsystem.</p>
  
  <p>I have an M-file that implements the function for the system of ODEs. Currently, I have a MATLAB Function block for that. It needs a lot of parameters that I can get from the base workspace (via <code>evalin</code> and using <code>coder.extrinsic('evalin')</code> at the beginning). But I'm not allowed to define function_handle objects or inner functions to parameterize the function that is used by ode*. I think that if I'm able to solve the ODEs in this block, I'll have solved my problem. But those restrictions are "ruining" it.</p>
  
  <p>I'd appreciate if you have any ideas of how to accomplish this. I welcome different approaches.</p>
  
  <p>Thank you.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>A simple example is given below. It attempts to solve the van der Pol equation by changing the <code>mu</code> parameter randomly. This is the main idea I have at the moment, which doesn't work because of the problems mentioned above.</p>
  
  <p>This is the main model with the subsystem:</p>
  
  <p><a href="https://i.stack.imgur.com/NOZFB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NOZFB.png" alt="enter image description here"></a></p>
  
  <p>This is the subsystem:</p>
  
  <p><a href="https://i.stack.imgur.com/SsDcP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SsDcP.png" alt="enter image description here"></a></p>
  
  <p>This is the MATLAB Function block implementation (note that there's an error in the @ symbol, since defining function_handle objects isn't allowed):</p>
  
  <p><a href="https://i.stack.imgur.com/SyR16.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SyR16.png" alt="enter image description here"></a></p>