Table of contents
Commonly Used Blocks——Switch、Logical Operator、Relational Operator
Commonly Used Blocks——Switch、Logical Operator、Relational Operator
1. Switch
Chinese translation: switch
Icon means:
Module parameters:
- 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.
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:
Module parameters:
There are 7 types of operators: AND, OR, NAND, NOR, XOR, NXOR, NOT
- AND: AND—all true is true, one false is false
- OR: or - all false is false, one true is true
NAND: NOT - True if at least one input is false
- NOR: or not - true if all inputs are not true
- XOR: Exclusive OR - true if an odd number of inputs are true
- NXOR: Exclusive OR Not - true if an even number of inputs are true
- NOT: not - if the input is false, then it is true
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.
3. Relational Operator
Chinese translation: relational operator
Icon means:
Module parameters:
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.
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;
Relational Logical Operators
reference article
① Simulink Simulation Section 7 Relational Operators and Logical Operator Modules
②Zero-crossing detection and algebraic loop in MATLAB Simulink