Simulink common module library (Switch/Logical/Relational Operator)

Table of contents

    Commonly Used Blocks——Switch、Logical Operator、Relational Operator

     1. Switch

 Zero-crossing detection

    二. Logical Operator

    3. Relational Operator

     Relational Logical Operators

    ​Reference Article


Commonly Used Blocks——Switch、Logical Operator、Relational Operator

Figure 1 Location of Switch, Logical Operator, and Relational Operator

 1. Switch

Chinese translation: switch

Icon means:

Figure 2 Switch Block

Module parameters:

Figure 3 Module parameters: Switch

  • At the first input condition, you can choose the judgment condition: u2>=threshold, u2>threshold and u2~=threshold;

>= : greater than or equal to   > : greater than   ~= not equal to

For the input of Boolean signals (true 1, false 0), the threshold value is 0 by default, and the threshold value can be modified to change the size;

  • If the judgment condition determined by the second port is true, the output port outputs the signal of the first port; otherwise, it outputs the signal of the third port.
  • The Switch block supports bus inputs, all buses must be identical (all elements have the same hierarchy and have the same name and properties), and all signals in non-virtual bus inputs must have the same sample time.

Figure 4 Switch module demo

 Zero-crossing detection

  • The variable step size calculation method will dynamically evaluate the step size used for calculation at the next sampling moment. When the values ​​​​of the previous and subsequent sampling points change greatly, the sampling step size will be reduced; otherwise, the values ​​of the current and subsequent sampling points will change. Hours increase the step size.
  • This practice causes the solver to use a smaller step size when computing discontinuity neighborhoods because the values ​​of discontinuity neighborhoods vary widely. This approach can ensure the accuracy of the calculation, but it may lead to too dense sampling and too small step size, which will cause the simulation time to be too long.
  • Simulink uses zero-detection technology to precisely locate the discontinuity point, so as to avoid the simulation time being too long due to too small step size during simulation. In general, it can improve the simulation speed, but it may cause the simulation to stop before reaching the specified time length.
  • When using the variable step size solution method for simulation, if the step size automatically becomes too small and the simulation time is very long or there is basically no progress, you can consider checking to enable the zero-crossing detection function. Simply put, a variable-step solver can simulate a discontinuous dynamical system by adding time steps at discontinuity points. Zero-crossing detection is set for these discontinuities.

二. Logical Operator

Chinese translation: logical operator

Icon means:

图5 Logical Operator Block

Module parameters:

Figure 6 Module parameters: Switch

 There are 7 types of operators: AND, OR, NAND, NOR, XOR, NXOR, NOT

  • AND: AND—all true is true, one false is false
Figure 7 Operator AND demo
  • OR: or - all false is false, one true is true
Figure 8 Demonstration of operator OR

 NAND: NOT - True if at least one input is false

Figure 9 Operator NAND Demo
  •  NOR: or not - true if all inputs are not true
Figure 10 Demonstration of operator NOR
  • XOR: Exclusive OR - true if an odd number of inputs are true 
Figure 11 Demonstration of operator XOR
  •  NXOR: Exclusive OR Not - true if an even number of inputs are true
Figure 12 Demonstration of operator NXOR
  •  NOT: not - if the input is false, then it is true
Figure 13 Operator NOT demo

 Appearances include 'rectangular' and 'different':

  • When a rectangle is selected, the shape of the module remains unchanged, but the currently selected logical operation is displayed in the center of the block diagram;
  • When distinctive is selected, the module will be displayed in the form specified by the IEEE image symbology standard.
Figure 14 Various appearances of logical operation modules

3. Relational Operator

Chinese translation: relational operator

Icon means:

图15 Relational Operator Block

Module parameters:

Figure 16 Module parameters: Relational Operator

Contains 9 relational operators as shown in the figure:

  • ==: The first input is equal to the second input, True, returns 1;
  • ~=: The first input is not equal to the second input, True, returns 1;
  • <: The first input is less than the second input, True, returns 1;
  • <=: The first input is less than or equal to the second input, True, returns 1;
  • >=: The first input is greater than or equal to the second input, True, returns 1;
  • >: The first input is greater than the second input, True, returns 1;
  • isInf: the input value is infinite, True, returns 1;
  • isNaN: The input is a non-numeric value (usually 0/0 or ∞/∞), True, returns 1;
  • isFinite: The input is a finite value, True, returns 1.
Figure 17 Demo of relational operators

 A combination of relational operator inputs:

  • input scalar, return scalar;
  • Input array, returns an array of the same dimension, where each element is the result of an element-by-element comparison of the input array;
  • Input a scalar and an array, and return an array where each element is the result of comparing the scalar with the corresponding input array element;
Figure 18 Combination of inputs

 Relational Logical Operators

 reference article

① Simulink Simulation Section 7 Relational Operators and Logical Operator Modules

②Zero-crossing detection and algebraic loop in MATLAB Simulink

③Usage of ~ and ~= in matlab

Guess you like

Origin blog.csdn.net/m0_64651092/article/details/129711265