Dynamic System Models -Simulink in MATLAB

SIMULINK is part of matlab uses graphical modeling approach. It is an extension of MATLAB that allows engineers and scientists to simulate and model complex systems, including control systems, signal processing systems, and communication systems.

SIMULINK uses a graphical modeling approach, where system components are represented as blocks and connected by lines that represent signals or data flow. Users can create custom blocks or use built-in blocks to build complex systems, and can use MATLAB functions within the blocks to perform calculations and analyze data.

SIMULINK is widely used in industry and academia for designing and testing control systems, developing and testing algorithms, and simulating and analyzing dynamic systems. It is a powerful tool for engineers and scientists working in fields such as aerospace, automotive, communication, and control systems.

The major things comes under Simulink are as follows:-

1. Graphical editor
2. Customizable block libraries
3. Solver for modeling
4. Simulating dynamic system
5. Analyzing multi domain dynamical system

1) Graphical Editor:-

MATLAB provides a variety of graphical editor functions that allow users to create, edit, and modify graphical objects such as plots, charts, and graphs. Some of the commonly used graphical editor functions in MATLAB are:

1. plot(): This function is used to create a 2D plot of data.
2. figure(): This function creates a new figure window for displaying plots.
3. subplot(): This function creates a grid of subplots within a figure window.
4. xlabel(), ylabel(), title(): These functions are used to add labels and a title to the plot.
5. legend(): This function adds a legend to the plot.
6. xlim(), ylim(): These functions are used to set the limits of the x-axis and y-axis, respectively.
7. grid(): This function adds a grid to the plot.
8. hold(): This function is used to maintain the current plot while adding new data to it.
9. plotyy(): This function creates a plot with two y-axes.
10. bar(), pie(): These functions are used to create bar charts and pie charts, respectively.

These are just a few of the many graphical editor functions available in MATLAB. By using these functions, users can create, modify, and customize their graphical outputs to meet their specific needs.

2) Customizable block libraries:-

Yes, MATLAB provides the capability to create and customize block libraries. A block library is a collection of blocks that you can use to build models in Simulink.

To create a custom block library in MATLAB, follow these steps:

1. Create a new Simulink model or open an existing one.
2. Create the blocks that you want to include in the library.
3. Select the blocks that you want to include in the library.
4. Right-click on the selected blocks and choose “Create Block Library”.
5. Give the library a name and save it in a directory of your choice.
6. Open the library file and customize the appearance of the blocks by adding annotations, changing colors, etc.
7. Save the changes to the library file.

Once you have created a custom block library, you can use it in other Simulink models by adding it to the MATLAB path and then opening the library from the Simulink Library Browser.

To learn more about creating and customizing block libraries in MATLAB, you can refer to the MATLAB documentation or the Simulink User’s Guide.

Function of customized block libraries in MATLAB

Customized block libraries in MATLAB provide several benefits, including:

1. Reusability: By creating a custom block library, you can reuse blocks that you frequently use in different models. This saves time and effort and ensures consistency across different models.
2. Standardization: Customized block libraries can help standardize the blocks used in different models within an organization or team. This ensures that models are built with the same building blocks, making it easier to share and collaborate on projects.
3. Efficiency: By creating a library of custom blocks, you can improve the efficiency of modeling and simulation tasks. This is because you can quickly access frequently used blocks and reduce the time it takes to build models.
4. Simplification: Custom block libraries can help simplify the modeling process. You can create high-level blocks that encapsulate complex functionality, making it easier to build models and reducing the chances of errors.
5. Maintenance: Custom block libraries can be maintained and updated over time, making it easier to keep track of changes and ensure consistency across models.

Overall, customized block libraries in MATLAB are a powerful tool that can help streamline the modeling and simulation process and improve the quality and consistency of models.

3) Solver for modeling

Solver in MATLAB refers to the algorithm used to solve mathematical models and equations. Depending on the type of model, MATLAB offers various solvers to choose from. Here are some of the commonly used solvers in MATLAB:

1. ODE Solver: ODE solvers are used to solve ordinary differential equations. MATLAB offers a range of ODE solvers, including ode45, ode23, and ode113, among others. These solvers use various numerical methods to solve the differential equations.
2. PDE Solver: PDE solvers are used to solve partial differential equations. MATLAB offers several PDE solvers, such as pdepe and pdenonlin, which use finite difference, finite element, and spectral methods.
3. Optimization Solver: Optimization solvers are used to find the minimum or maximum of a function. MATLAB offers various optimization solvers, including fmincon, fminunc, and linprog, among others. These solvers use various optimization algorithms such as gradient descent, conjugate gradient, and simplex method.
4. Simulink Solver: Simulink solvers are used to simulate dynamic systems. Simulink offers various solvers, including ode45, ode23t, and ode15s. These solvers use numerical methods to simulate the system dynamics.

To use any solver in MATLAB, you first need to define the problem you want to solve and pass it to the appropriate solver function. The syntax for using a solver in MATLAB varies depending on the solver used. However, most solvers require you to provide the mathematical model, initial conditions, and other parameters.

Here is an example of how to use the ode45 solver in MATLAB to solve an ordinary differential equation

Code example:-

% Define the differential equation

dydt = @(t,y) 2*t + y;

% Define the initial condition

y0 = 1;

% Define the time interval

tspan = [0 5];

% Solve the differential equation using ode45

[t,y] = ode45(dydt, tspan, y0);

% Plot the solution

plot(t,y);

xlabel(‘Time’);

ylabel(‘y(t)’);

title(‘Solution of y” = 2t + y’);

4) Simulating dynamic system in MATLAB

Simulating dynamic systems in MATLAB can be done using the Simulink environment, which is a graphical tool for modeling, simulating, and analyzing dynamic systems. Here are the steps to simulate a dynamic system in MATLAB using Simulink:

1. Create a new Simulink model: Open MATLAB and select Simulink from the Apps tab. Click on New Model to create a new Simulink model.
2. Build the model: Build the dynamic system model by dragging and dropping blocks from the Simulink Library Browser onto the model canvas. Each block represents a component of the system, and their connections represent the flow of data between them.
3. Configure block parameters: Double-click on each block to open its block parameter dialog box and configure its parameters. Each block has a set of parameters that control its behavior, such as its input/output ports, time delays, gain values, and so on.
4. Connect the blocks: Connect the output port of one block to the input port of another block to establish the flow of data between them. You can use signal lines to connect the blocks.
5. Set simulation parameters: Set the simulation parameters, such as the simulation time, step size, solver type, and other options. You can do this by clicking on the Configuration Parameters button on the toolbar or by selecting Simulation > Configuration Parameters from the menu.
6. Run the simulation: Click on the Run button on the toolbar or select Simulation > Run from the menu to run the simulation. The simulation will run and produce the output results, which you can analyze using various MATLAB tools.

Here is an example of simulating a simple dynamic system in Simulink:

Consider a simple mass-spring-damper system, where a mass is connected to a spring and a damper. The displacement of the mass is described by the second-order differential equation:

mx” + cx’ + k*x = F

where m is the mass, c is the damping coefficient, k is the spring constant, F is the applied force, and x is the displacement of the mass.

To simulate this system in Simulink, we can use the following steps:

1. Create a new Simulink model and drag and drop the Mass-Spring-Damper block from the Simulink Library Browser onto the model canvas.
2. Double-click on the block to open its block parameter dialog box and set its mass, damping coefficient, and spring constant parameters.
3. Drag and drop the Constant and Sum blocks from the Simulink Library Browser onto the model canvas.
4. Connect the output of the Constant block to one input of the Sum block and the output of the Mass-Spring-Damper block to the other input of the Sum block.
5. Connect the output of the Sum block to the input of the Mass-Spring-Damper block.
6. Double-click on the Constant block to set its value to the applied force F.
7. Set the simulation parameters, such as the simulation time and step size.
8. Run the simulation and observe the displacement of the mass over time.

Here is the MATLAB code for simulating the mass-spring-damper system in Simulink:

% Create a new Simulink model

model = ‘mass_spring_damper’;

open_system(model);

% Set the system parameters

m = 1;      % mass

c = 0.2;    % damping coefficient

k = 2;      % spring constant

F = 1;      % applied force

% Set the simulation parameters

tend = 10;          % simulation time

dt = 0.01;          % time step

solver = ‘ode45’;   % solver type

% Build the model

5 ) Analyzing multi domain dynamical system

Multi-domain dynamical systems can be analyzed in MATLAB using Simulink, which provides a convenient way to model and simulate such systems. Here are some steps to follow for analyzing multi-domain dynamical systems in MATLAB:

1. Define the system: Define the multi-domain dynamical system you want to analyze. This system may consist of multiple subsystems or domains, such as electrical, mechanical, hydraulic, or thermal domains.
2. Create a Simulink model: Create a Simulink model for the multi-domain dynamical system by dragging and dropping blocks from the Simulink Library Browser onto the model canvas. Each block represents a subsystem or domain, and their connections represent the flow of energy or information between them.
3. Configure block parameters: Double-click on each block to open its block parameter dialog box and configure its parameters. Each block has a set of parameters that control its behavior, such as its input/output ports, time delays, gain values, and so on.
4. Connect the blocks: Connect the output port of one block to the input port of another block to establish the flow of energy or information between them. You can use signal lines to connect the blocks.
5. Set simulation parameters: Set the simulation parameters, such as the simulation time, step size, solver type, and other options. You can do this by clicking on the Configuration Parameters button on the toolbar or by selecting Simulation > Configuration Parameters from the menu.
6. Run the simulation: Click on the Run button on the toolbar or select Simulation > Run from the menu to run the simulation. The simulation will run and produce the output results, which you can analyze using various MATLAB tools.
7. Analyze the results: Analyze the simulation results using MATLAB tools such as plots, scopes, and data analysis functions. You can visualize the behavior of the system over time, as well as its performance metrics such as speed, torque, power, temperature, pressure, and so on.

Here is an example of analyzing a multi-domain dynamical system in Simulink:

Consider a hybrid electric vehicle system, which consists of an electrical subsystem (battery, motor, controller) and a mechanical subsystem (wheels, suspension, chassis). The objective is to optimize the system’s energy efficiency and vehicle performance under various driving conditions.

To analyze this system in Simulink, we can use the following steps:

1. Create a new Simulink model and drag and drop the electrical and mechanical subsystem blocks from the Simulink Library Browser onto the model canvas.
2. Double-click on each block to open its block parameter dialog box and set its parameters such as voltage, current, power, speed, torque, and efficiency.
3. Connect the output port of the electrical subsystem block to the input port of the mechanical subsystem block, and vice versa.
4. Add a driving cycle input block to simulate different driving conditions, such as urban, highway, or aggressive driving.
5. Set the simulation parameters, such as the simulation time, step size, solver type, and other options.
6. Run the simulation and observe the system’s performance metrics such as fuel economy, acceleration, braking, and handling.
7. Analyze the results using MATLAB tools such as plots, scopes, and data analysis functions. You can visualize the energy flow and conversion between the electrical and mechanical subsystems, as well as the system’s overall performance under different driving conditions. You can also perform sensitivity analyses to determine the effects of different parameters on the system’s behavior

Q & A

1)What type of software is MATLAB Simulink?

Ans:-Simulink is a block diagram environment used to design systems with multi domain models, simulate before moving to hardware, and deploy without writing code.

2)What are the components of Simulink?

Ans :- Simulink model components include Subsystem blocks, Model blocks, State flow charts, and Simulink to Sims cape™ converter blocks.

Ans :- The Memory block holds and delays its input by one major integration time step.

In Simulink, memory refers to a block that can store a value or a signal for a certain period of time. The Memory block is used to create a memory element in a Simulink model.

The Memory block has an input port and an output port. When a signal is applied to the input port, the value of the signal is stored in the block’s memory. The stored value can then be accessed and outputted at a later time through the output port.

Memory blocks are often used in Simulink models to store previous states or outputs of a system, which can be used as inputs for subsequent calculations. They are commonly used in feedback control systems, signal processing, and other applications where it is necessary to store and access previous values of a signal.