<p>I have a Simulink xPC target application that has blocks with discrete states at several different sample rates and some sections using continuous states. My intention on keeping the continuous states is for better numerical integration. </p>

<p>What creates the problem: One block is reading a device at a very fast rate (500 hz). The rest of the application can and should run at a slower rate (say, 25 or 50 Hz) because it would be overkill to run it at the highest rate, and because the processor simply cannot squeeze a full application cycle into the .002 secs of the faster rate. So I need both rates. However, the continuous states run by definition in Simulink at the faster discrete rate of the whole application! This means everywhere I have continuous states now they're forced to run at 500 Hz when 25 Hz would do!</p>

<p>Is there a way to force the continuous states in xPC target to a rate that is not the fastest in the application? Or alternatively, is there a way to allow certain block to run at a faster speed than the rest of the application?</p>

[{'answer_id': 43225, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': "<p>My take on this is that it cannot be done. One way to approach this is to replace the continuous states by discrete ones (perhaps at an intermediate rate, say 100 Hz), and cross my fingers that the loss of precision is bearable.</p>\n\n<p>Maybe it's possible to isolate a block and run it separately at a faster rate somehow, but I don't know.</p>\n"}, {'answer_id': 43228, 'author': 'Adam Davis', 'author_id': 2915, 'author_profile': 'https://Stackoverflow.com/users/2915', 'pm_score': 2, 'selected': False, 'text': '<p>You are thinking about continuous solvers in the wrong way - continuous doesn\'t only mean that it\'s run as fast as possible - it uses a fundamentally different algorithm to solve the equations than discrete.  Due to this, they must be run at least as fast as the discrete solvers.</p>\n\n<p>From <a href="http://www.ece.northwestern.edu/IT/local-apps/matlabhelp/toolbox/simulink/ug/how_simulink_works13.html" rel="nofollow noreferrer">Using Simulink</a>:</p>\n\n<blockquote>\n  <p>Continuous solvers use numerical\n  integration to compute a model\'s\n  continuous states at the current time\n  step from the states at previous time\n  steps and the state derivatives.\n  Continuous solvers rely on the model\'s\n  blocks to compute the values of the\n  model\'s discrete states at each time\n  step.</p>\n  \n  <p>Mathematicians have developed a wide\n  variety of numerical integration\n  techniques for solving the ordinary\n  differential equations (ODEs) that\n  represent the continuous states of\n  dynamic systems. Simulink provides an\n  extensive set of fixed-step and\n  variable-step continuous solvers, each\n  implementing a specific ODE solution\n  method (see Solvers).</p>\n  \n  <p>Discrete solvers exist primarily to\n  solve purely discrete models. They\n  compute the next simulation time step\n  for a model and nothing else. They do\n  not compute continuous states and they\n  rely on the model\'s blocks to update\n  the model\'s discrete states.</p>\n</blockquote>\n\n<p>So the upshot is that <em>no</em> it\'s not good enough to have the continuous run more slowly than the fastest discrete solvers - otherwise they are, by definition, not continuous.  You should reconsider why you are specifying them as continuous.</p>\n\n<p>What are you trying to accomplish by slowing down the continuous solvers?  Is this a simulation time/performance issue?</p>\n\n<p>-Adam</p>\n'}, {'answer_id': 1573947, 'author': 'Emilio M Bumachar', 'author_id': 174365, 'author_profile': 'https://Stackoverflow.com/users/174365', 'pm_score': 0, 'selected': False, 'text': '<p>Truly continuous computation is impossible in a digital processor such as your computer\'s.</p>\n\n<p>What MATLAB/Simulink means by "continuous" is "I will (dynamically) try to guess what discrete step size is small enough so that discretization error is very small in your application".</p>\n\n<p>If you already know, by knowing your application, that 20ms (50Hz) would be small enough, then use discrete - 50Hz. </p>\n'}]
['https://Stackoverflow.com/questions/43223', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']