hardikisharma2 asked . 2020-09-21

How does Simulink perform simulations?

I would like to know how Simulink performs simulations for continuous and discrete systems. I would like to know what the flag ordering of S-function calls is, and when and why the different flags are called during a simulation.

simulink , matlab , simulation

Expert Answer

Prashant Kumar answered . 2024-12-20 18:22:34

There are generally two types of signals that are simulated in Simulink: discrete and continuous. Discrete signals are simulated via difference equations while continuous signals are simulated via various numerical integration algorithms (e.g., Euler). Refer to numerical methods texts for more information regarding integration algorithms.
The simulation may be thought of as a formal conversation between two entities: the system description and the integrator. The system description (block diagram or S-function) is responsible for supplying various information to the integrator, while the integrator is responsible for propagating the system through time.
Let's consider a continuous state. In order to get from time 't' to time 't+delta_t', the system description must supply the integrator with the derivative. The integrator then uses this derivative to obtain the next value of the state. It is the responsibility of the integrator to decide how far in time to step along the current derivative and check the error tolerances to determine if the new state is accurate. In terms of Simulink, the above interaction results in the integrator calling the system with a flag of 1 (i.e., flag 1 = request for current derivative). Similarly, the system description must supply information regarding the outputs of the system. The integrator requests information regarding the current outputs by calling the system with a flag of 3.
Now, let's consider a discrete state. In this case the integrator is not responsible for as much work as it is in the continuous case. The discrete states are propagated through time via difference equations
 x[n+1] = x[n] + .........
The system description includes an expression for calculating x[n+1] for each state, and the integrator is responsible only for taking care of the timing. For example, if the sample time is 1 second and at time t=3 the value of x[n+1] is defined as 10, then the integrator makes sure that at time, t + ts, the value of the state is 10. In order for this timing to work correctly, the integrator forces an integration step at the times of the sample hits. This means that at the time of every discrete event, all states are updated (both continuous and discrete). For times between sample hits, the values of the discrete states are held constant (i.e., zero order hold).
If you are familiar with S-functions (see the Simulink documentation) and the various flag calls, the following is an explanation of when and why S-functions are called with the various flags. First, it will be useful to know the order in which the flags are called (excluding flag zero which is only called at the beginning of each simulation). Assuming that at each time step, the system was called with every flag, the order would be 4,3,2,1. However, as we will soon see, not all flags are used at every time step. The above order, however, still applies to the flags that are being used.
Before we look at specific cases, it will also be useful to discuss flag 2. In general, flag 2 is used to update discrete states. In Simulink, flag 2 is called at every RrealS integration step, where real is defined as steps that correspond to the time vector that is returned by Simulink. Some of the integration algorithms take intermediate steps during which other flags (1 and 3) are called. Flag 2 is called at every time step so that actions such as plotting or data collection could be executed at every time step of the simulation. Two disadvantages of this are that a check must be made in order to execute the discrete update code only at sample hits, and that it is inefficient to make discrete flag calls at every integration hit. For purely discrete blocks, flag 2 is only called at sample hits. This allows simulation for discrete operations to be more efficient.
Below is an explanation of how flags work in Simulink:
Case 1: Continuous System
------------------------
flag 3 => called at every integration step (including intermediate steps)
flag 1 => R......S
flag 2 => called at every real integration step
flag 4 => called at the begining of the simulation and set to arbitrarily large number indicating that no discrete updates are necessary.
Case 2: Discrete System
-----------------------
flag 3 => same as continous system
flag 1 => not called
flag 2 => called every integration step...must check for sample hits
flag 4 => called at every sample hit


Not satisfied with the answer ?? ASK NOW

Frequently Asked Questions

MATLAB offers tools for real-time AI applications, including Simulink for modeling and simulation. It can be used for developing algorithms and control systems for autonomous vehicles, robots, and other real-time AI systems.

MATLAB Online™ provides access to MATLAB® from your web browser. With MATLAB Online, your files are stored on MATLAB Drive™ and are available wherever you go. MATLAB Drive Connector synchronizes your files between your computers and MATLAB Online, providing offline access and eliminating the need to manually upload or download files. You can also run your files from the convenience of your smartphone or tablet by connecting to MathWorks® Cloud through the MATLAB Mobile™ app.

Yes, MATLAB provides tools and frameworks for deep learning, including the Deep Learning Toolbox. You can use MATLAB for tasks like building and training neural networks, image classification, and natural language processing.

MATLAB and Python are both popular choices for AI development. MATLAB is known for its ease of use in mathematical computations and its extensive toolbox for AI and machine learning. Python, on the other hand, has a vast ecosystem of libraries like TensorFlow and PyTorch. The choice depends on your preferences and project requirements.

You can find support, discussion forums, and a community of MATLAB users on the MATLAB website, Matlansolutions forums, and other AI-related online communities. Remember that MATLAB's capabilities in AI and machine learning continue to evolve, so staying updated with the latest features and resources is essential for effective AI development using MATLAB.

Without any hesitation the answer to this question is NO. The service we offer is 100% legal, legitimate and won't make you a cheater. Read and discover exactly what an essay writing service is and how when used correctly, is a valuable teaching aid and no more akin to cheating than a tutor's 'model essay' or the many published essay guides available from your local book shop. You should use the work as a reference and should not hand over the exact copy of it.

Matlabsolutions.com provides guaranteed satisfaction with a commitment to complete the work within time. Combined with our meticulous work ethics and extensive domain experience, We are the ideal partner for all your homework/assignment needs. We pledge to provide 24*7 support to dissolve all your academic doubts. We are composed of 300+ esteemed Matlab and other experts who have been empanelled after extensive research and quality check.

Matlabsolutions.com provides undivided attention to each Matlab assignment order with a methodical approach to solution. Our network span is not restricted to US, UK and Australia rather extends to countries like Singapore, Canada and UAE. Our Matlab assignment help services include Image Processing Assignments, Electrical Engineering Assignments, Matlab homework help, Matlab Research Paper help, Matlab Simulink help. Get your work done at the best price in industry.