Control Tutorials for MATLAB and Simulink (2024)

The first step in the control design process is to develop appropriate mathematical models of the system to be controlled. These models may be derived either from physical laws or experimental data. In this section, we introduce the state-space and transfer function representations of dynamic systems. We then review some basic approaches to modeling mechanical and electrical systems and show how to generate these models in MATLAB for further analysis.

Key MATLAB commands used in this tutorial are: ss , tf

Run Live Script Version in MATLAB Online

Related Tutorial Links

  • MATLAB Basics
  • RC Circuit Activity
  • Pendulum Activity

Related External Links

Contents

  • Dynamic Systems
  • State-Space Representation
  • Transfer Function Representation
  • Mechanical Systems
  • Example: Mass-Spring-Damper System
  • Entering State-Space Models into MATLAB
  • Entering Transfer Function Models into MATLAB
  • Electrical Systems
  • Example: RLC Circuit
  • System Identification
  • System Conversions

Dynamic Systems

Dynamic systems are systems that change or evolve in time according to a fixed rule. For many physical systems, this rule can be stated as a set of first-order differential equations:

(1)Control Tutorials for MATLAB and Simulink (1)

In the above equation, Control Tutorials for MATLAB and Simulink (2) is the state vector, a set of variables representing the configuration of the system at time Control Tutorials for MATLAB and Simulink (3). For instance, in a simple mechanical mass-spring-damper system, the two state variables could be the position and velocity of the mass. Control Tutorials for MATLAB and Simulink (4) is the vector of external inputs to the system at time Control Tutorials for MATLAB and Simulink (5), and Control Tutorials for MATLAB and Simulink (6) is a (possibly nonlinear) function producing the time derivative (rate of change) of the state vector, Control Tutorials for MATLAB and Simulink (7), for a particular instant of time.

The state at any future time, Control Tutorials for MATLAB and Simulink (8), may be determined exactly given knowledge of the initial state, Control Tutorials for MATLAB and Simulink (9), and the time history of the inputs, Control Tutorials for MATLAB and Simulink (10), between Control Tutorials for MATLAB and Simulink (11) and Control Tutorials for MATLAB and Simulink (12) by integrating Equation (1). Though the state variables themselves are not unique, there is a minimum number of state variables, Control Tutorials for MATLAB and Simulink (13), required in order to capture the "state" of a given system and to be able to predict the system's future behavior (solve the state equations). Control Tutorials for MATLAB and Simulink (14) is referred to as the system order and determines the dimensionality of the state-space. The system order usually corresponds to the number of independent energy storage elements in the system.

The relationship given in Equation (1) is very general and can be used to describe a wide variety of different systems; unfortunately, it may be very difficult to analyze. There are two common simplifications which make the problem more tractable. First, if the function Control Tutorials for MATLAB and Simulink (15) does not depend explicitly on time, i.e. Control Tutorials for MATLAB and Simulink (16), then the system is said to be time invariant. This is often a very reasonable assumption because the underlying physical laws themselves do not typically depend on time. For time-invariant systems, the parameters or coefficients of the function Control Tutorials for MATLAB and Simulink (17) are constant. The state variables, Control Tutorials for MATLAB and Simulink (18), and control inputs, Control Tutorials for MATLAB and Simulink (19), however, may still be time dependent.

The second common assumption concerns the linearity of the system. In reality, nearly every physical system is nonlinear. In other words, Control Tutorials for MATLAB and Simulink (20) is typically some complicated function of the state and inputs. These nonlinearities arise in many different ways, one of the most common in control systems being "saturation" in which an element of the system reaches a hard physical limit to its operation. Fortunately, over a sufficiently small operating range (think tangent line near a curve), the dynamics of most systems are approximately linear. In this case, the system of first-order differential equations can be represented as a matrix equation, that is, Control Tutorials for MATLAB and Simulink (21).

Until the advent of digital computers (and to a large extent thereafter), it was only practical to analyze linear time-invariant (LTI) systems. Consequently, most of the results of control theory are based on these assumptions. Fortunately, as we shall see, these results have proven to be remarkably effective and many significant engineering challenges have been solved using LTI techniques. In fact, the true power of feedback control systems are that they work (are robust) in the presence of the unavoidable modeling uncertainty.

State-Space Representation

For continuous linear time-invariant (LTI) systems, the standard state-space representation is given below:

(2)Control Tutorials for MATLAB and Simulink (22)

(3)Control Tutorials for MATLAB and Simulink (23)

where Control Tutorials for MATLAB and Simulink (24) is the vector of state variables (nx1), Control Tutorials for MATLAB and Simulink (25) is the time derivative of the state vector (nx1), Control Tutorials for MATLAB and Simulink (26) is the input or control vector (px1), Control Tutorials for MATLAB and Simulink (27) is the output vector (qx1), Control Tutorials for MATLAB and Simulink (28) is the system matrix (nxn), Control Tutorials for MATLAB and Simulink (29) is the input matrix (nxp), Control Tutorials for MATLAB and Simulink (30) is the output matrix (qxn), and Control Tutorials for MATLAB and Simulink (31) is the feedforward matrix (qxp).

The output equation, Equation (3), is necessary because often there are state variables which are not directly observed or are otherwise not of interest. The output matrix, Control Tutorials for MATLAB and Simulink (32), is used to specify which state variables (or combinations thereof) are available for use by the controller. Also, it is often the case that the outputs do not directly depend on the inputs (only through the state variables), in which case Control Tutorials for MATLAB and Simulink (33) is the zero matrix.

The state-space representation, also referred to as the time-domain representation, can easily handle multi-input/multi-output (MIMO) systems, systems with non-zero initial conditions, and nonlinear systems via Equation (1). Consequently, the state-space representation is used extensively in "modern" control theory.

Transfer Function Representation

LTI systems have the extremely important property that if the input to the system is sinusoidal, then the output will also be sinusoidal with the same frequency as the input, but with possibly different magnitude and phase. These magnitude and phase differences are a function of frequency and capture what is known as the frequency response of the system.

Using the Laplace transform, it is possible to convert a system's time-domain representation into a frequency-domain input/output representation, known as the transfer function. In so doing, it also transforms the governing differential equation into an algebraic equation which is often easier to analyze.

The Laplace transform of a time domain function, Control Tutorials for MATLAB and Simulink (34), is defined below:

(4)Control Tutorials for MATLAB and Simulink (35)

where the parameter Control Tutorials for MATLAB and Simulink (36) is a complex frequency variable. It is very rare in practice that you will have to directly evaluate a Laplace transform (though you should certainly know how to). It is much more common to look up the transform of a time function in a table such as the one found here: Laplace Transform Table

The Laplace transform of the nth derivative of a function is particularly important:

(5)Control Tutorials for MATLAB and Simulink (37)

Frequency-domain methods are most often used for analyzing LTI single-input/single-output (SISO) systems, e.g. those governed by a constant coefficient differential equation, as shown below:

(6)Control Tutorials for MATLAB and Simulink (38)

The Laplace transform of this equation is given below:

(7)Control Tutorials for MATLAB and Simulink (39)

where Control Tutorials for MATLAB and Simulink (40) and Control Tutorials for MATLAB and Simulink (41) are the Laplace Transforms of Control Tutorials for MATLAB and Simulink (42) and Control Tutorials for MATLAB and Simulink (43), respectively. Note that when finding transfer functions, we always assume that the each of the initial conditions, Control Tutorials for MATLAB and Simulink (44), Control Tutorials for MATLAB and Simulink (45), Control Tutorials for MATLAB and Simulink (46), etc. is zero. The transfer function from input Control Tutorials for MATLAB and Simulink (47) to output Control Tutorials for MATLAB and Simulink (48) is, therefore:

(8)Control Tutorials for MATLAB and Simulink (49)

It is useful to factor the numerator and denominator of the transfer function into what is termed zero-pole-gain form:

(9)Control Tutorials for MATLAB and Simulink (50)

The zeros of the transfer function, Control Tutorials for MATLAB and Simulink (51), are the roots of the numerator polynomial, i.e. the values of Control Tutorials for MATLAB and Simulink (52) such that Control Tutorials for MATLAB and Simulink (53). The poles of the transfer function, Control Tutorials for MATLAB and Simulink (54), are the roots of the denominator polynomial, i.e. the values of Control Tutorials for MATLAB and Simulink (55) such that Control Tutorials for MATLAB and Simulink (56). Both the zeros and poles may be complex valued (have both real and imaginary parts). The system Gain is Control Tutorials for MATLAB and Simulink (57).

Note that we can also determine the transfer function directly from the state-space representation as follows:

(10)Control Tutorials for MATLAB and Simulink (58)

Mechanical Systems

Newton's laws of motion form the basis for analyzing mechanical systems. Newton’s second law, Equation (11), states that the sum of the forces acting on a body equals the product of its mass and acceleration. Newton's third law, for our purposes, states that if two bodies are in contact, then they experience the same magnitude contact force, just acting in opposite directions.

(11)Control Tutorials for MATLAB and Simulink (59)

When applying this equation, it is best to construct a free-body diagram (FBD) of the sysetm showing all of the applied forces.

Example: Mass-Spring-Damper System

Control Tutorials for MATLAB and Simulink (60)

The free-body diagram for this system is shown below. The spring force is proportional to the displacement of the mass, Control Tutorials for MATLAB and Simulink (61), and the viscous damping force is proportional to the velocity of the mass, Control Tutorials for MATLAB and Simulink (62). Both forces oppose the motion of the mass and are, therefore, shown in the negative Control Tutorials for MATLAB and Simulink (63)-direction. Note also that Control Tutorials for MATLAB and Simulink (64) corresponds to the position of the mass when the spring is unstretched.

Control Tutorials for MATLAB and Simulink (65)

Now we proceed by summing the forces and applying Newton’s second law, Equation (11), in each direction. In this case, there are no forces acting in the Control Tutorials for MATLAB and Simulink (66)-direction; however, in the Control Tutorials for MATLAB and Simulink (67)-direction we have:

(12)Control Tutorials for MATLAB and Simulink (68)

This equation, known as the governing equation, completely characterizes the dynamic state of the system. Later, we will see how to use this to calculate the response of the system to any external input, Control Tutorials for MATLAB and Simulink (69), as well as to analyze system properties such as stability and performance.

To determine the state-space representation of the mass-spring-damper system, we must reduce the second-order governing equation to a set of two first-order differential equations. To this end, we choose the position and velocity as our state variables.

(13)Control Tutorials for MATLAB and Simulink (70)

The position variable captures the potential energy stored in the spring, while the velocity variable captures the kinetic energy stored by the mass. The damper only dissipates energy, it doesn't store energy. Often when choosing state variables it is helpful to consider what variables capture the energy stored in the system.

The state equation in this case is:

(14)Control Tutorials for MATLAB and Simulink (71)

If, for instance, we are interested in controlling the position of the mass, then the output equation is:

(15)Control Tutorials for MATLAB and Simulink (72)

Entering State-Space Models into MATLAB

Now we will demonstrate how to enter the equations derived above into an m-file for MATLAB. Let's assign the following numerical values to each of the variables.

m mass 1.0 kgk spring constant 1.0 N/mb damping constant 0.2 Ns/mF input force 1.0 N

Create a new m-file and enter the following commands.

m = 1;k = 1;b = 0.2;F = 1;A = [0 1; -k/m -b/m];B = [0 1/m]';C = [1 0];D = [0];sys = ss(A,B,C,D)
sys = A = x1 x2 x1 0 1 x2 -1 -0.2 B = u1 x1 0 x2 1 C = x1 x2 y1 1 0 D = u1 y1 0 Continuous-time state-space model.

The Laplace transform for this system assuming zero initial conditions is

(16)Control Tutorials for MATLAB and Simulink (73)

and, therefore, the transfer function from force input to displacement output is

(17)Control Tutorials for MATLAB and Simulink (74)

Entering Transfer Function Models into MATLAB

Now we will demonstrate how to create the transfer function model derived above within MATLAB. Enter the following commands into the m-file in which you defined the system parameters.

s = tf('s');sys = 1/(m*s^2+b*s+k)
sys = 1 --------------- s^2 + 0.2 s + 1 Continuous-time transfer function.

Note that we have used the symbolic s variable here to define our transfer function model. We recommend using this method most of the time; however, in some circ*mstances, for instance in older versions of MATLAB or when interfacing with SIMULINK, you may need to define the transfer function model using the numerator and denominator polynomial coefficients directly. In these cases, use the following commands:

num = [1];den = [m b k];sys = tf(num,den)
sys = 1 --------------- s^2 + 0.2 s + 1 Continuous-time transfer function.

Electrical Systems

Like Newton’s laws for mechanical systems, Kirchoff’s circuit laws are fundamental analytical tools for modeling electrical systems. Kirchoff’s current law (KCL) states that the sum of the electrical currents entering a node in a circuit must equal the sum of electrical currents exiting the node. Kirchoff’s voltage law (KVL) states that the sum of voltage differences around any closed loop in a circuit is zero. When applying KVL, the source voltages are typically taken as positive and the load voltages are taken as negative.

Example: RLC Circuit

We will now consider a simple series combination of three passive electrical elements: a resistor, an inductor, and a capacitor, known as an RLC Circuit.

Control Tutorials for MATLAB and Simulink (75)

Since this circuit is a single loop, each node only has one input and one output; therefore, application of KCL simply shows that the current is the same throughout the circuit at any given time, Control Tutorials for MATLAB and Simulink (76). Now applying KVL around the loop and using the sign conventions indicated in the diagram, we arrive at the following governing equation.

(18)Control Tutorials for MATLAB and Simulink (77)

We note that that the governing equation for the RLC circuit has an analogous form to the mass-spring-damper mechanical system. In particular, they are both second-order systems where the charge (integral of current) corresponds to displacement, the inductance corresponds to mass, the resistance corresponds to viscous damping, and the inverse capacitance corresponds to the spring stiffness. These analogies and others like them turn out to be quite useful conceptually in understanding the behavior of dynamical systems.

The state-space representation is found by choosing the charge on the capacitor and current through the circuit (inductor) as the state variables.

(19)Control Tutorials for MATLAB and Simulink (78)

where,

(20)Control Tutorials for MATLAB and Simulink (79)

The state equation is, therefore:

(21)Control Tutorials for MATLAB and Simulink (80)

We choose the current as ouput as follows:

(22)Control Tutorials for MATLAB and Simulink (81)

The transfer function representation may be found by taking the Laplace transform as we did for the mass-spring-damper or from the state-space equation as follows:

(23)Control Tutorials for MATLAB and Simulink (82)

(24)Control Tutorials for MATLAB and Simulink (83)

The RLC state-space and transfer function models can be entered into MATLAB using the same procedure as discussed for the mass-spring-damper system above.

System Identification

In this section, we have seen how to model systems using basic physical principles; however, often this is not possible either because the parameters of the system are uncertain, or the underlying processes are simply not understood. In these cases, we must rely on experimental measurements and statistical techniques to develop a system model, a process known as system identification.

System identification may be performed using either time-domain or frequency-domain data, see the Introduction: System Identification page for further details. A couple of system identification activities can also be found from the Hardware tab located at the top of this window.

Also refer to MATLAB’s System Identification Toolbox for more information on this subject.

System Conversions

Most operations in MATLAB can be performed on either the transfer function, the state-space model, or the zero-pole-gain form. Furthermore, it is simple to transfer between these forms if the other representation is required. If you need to learn how to convert from one representation to another, see the Introduction: System Conversions page.


Published with MATLAB® 9.2

Control Tutorials for MATLAB and Simulink (2024)

FAQs

How do I find answers in MATLAB? ›

To view all of your solutions, go to a Problem page and click View my solutions. You can view your solutions in a list or in the Solution Map. If using the list view, you can review the display by selecting a Sort by option.

Is MATLAB Simulink hard to learn? ›

MATLAB is designed for the way you think and the work you do, so learning is accessible whether you are a novice or an expert. The Help Center is always available to guide you with robust documentation, community answers, and how-to videos. Additionally, online interactive training is a great way to get started.

How much time is required to learn MATLAB? ›

If you're a novice programmer, you can expect it to take a little longer than if you were a more seasoned programmer. Someone who can afford to devote all their time to MATLAB can finish learning the language in two weeks. If you have a lot of other responsibilities, however, it will take you longer to complete.

How to pass structure to Simulink? ›

To connect the structure input or output in a MATLAB function with Simulink, you must define a Simulink. Bus object in the base workspace. Then use this bus object as signal datra type for the signals which are to be connected to Matlab function.

How do you get a long answer in MATLAB? ›

To format the way numbers display, do one of the following:
  1. On the Home tab, in the Environment section, click Preferences. Select MATLAB > Command Window, and then choose a Numeric format option.
  2. Use the format function, for example: format short format short e format long.

How do I find Solver in MATLAB? ›

Description. S = solve( eqn , var ) solves the equation eqn for the variable var . If you do not specify var , the symvar function determines the variable to solve for. For example, solve(x + 1 == 2, x) solves the equation x + 1 = 2 for x.

Is MATLAB harder than Python? ›

The Difference in Technical Computing:

They are both used for the same type of work, such as numerical analysis, data visualization, and scientific computation. When it comes to syntax and readability, Python is often easier to read and understand than MATLAB.

What is the salary of MATLAB Simulink? ›

Average Annual Salary by Experience

Matlab Developer salary in India with less than 1 year of experience to 5 years ranges from ₹ 2.0 Lakhs to ₹ 9.4 Lakhs with an average annual salary of ₹ 5.6 Lakhs based on 342 latest salaries.

Is MATLAB enough for a job? ›

Conclusion. The industry has some familiar buzz that learning MATLAB will not be a good opportunity for a better career. But this is not fully true. Yes, it is an acceptable reason that salary or company structure will never be able to touch available popular jobs on other programming technologies.

Is MATLAB in high demand? ›

Matlab careers are actually on the rise today. It's a very popular programming language. It can be used by a developer, engineer, programmer, scientist, etc. to collect and sort out data, and develop apps, software, and sites.

Can I learn MATLAB in 1 month? ›

If you want to become an expert in Matlab then you need to mention which part of madlab you want to learn and want expertise. If I generalize my answer highly, It may take at least 3 months to learn matlab and may take maximum 3 years to become an expert.

How to run Simulink step by step? ›

In the Simulink Toolstrip, on the Simulation tab, click Step Forward to start a simulation of the model vdp . The simulation starts and pauses just after calculating the output values for the first simulation time and before stepping to the next simulation time.

How to generate code from Simulink? ›

To generate code, you must make the following changes: In the Modeling tab of the model toolstrip, click Model Settings. The Configuration Parameters dialog opens. Navigate to the Code Generation tab, select the Generate code only parameter, and click Apply.

How to check results in MATLAB? ›

View Results in Command Window

The Summary Report link provides access to the Model Advisor Command-Line Summary report. You can review additional results in the Command Window by calling the DisplayResults parameter when you run the Model Advisor.

How do you find the step response in MATLAB? ›

[ y , tOut ] = step( sys , tFinal ) computes the step response from t = 0 to the end time t = tFinal . [ y , tOut ] = step( sys , t ) returns the step response of a dynamic system model sys at the times specified in the vector t .

How do I find something in MATLAB code? ›

Search Using Find Dialog Box

The Find dialog box opens. The search begins at the current cursor position. MATLAB finds the text you specified and highlights it. MATLAB beeps when a search for Find Next reaches the end of the Command Window, or when a search for Find Previous reaches the top of the Command Window.

What is the ANS command in MATLAB? ›

ans is the variable created when an output is returned without a specified output argument. MATLAB® creates the ans variable and stores the output there. Changing or using the value of ans in a script or function is not recommended, as the value can change frequently. ans is specific to the current workspace.

Top Articles
Dry Socket: How to Tell, Pain Symptoms, Healing
Treating Dry Socket: The Benefits of Dry Socket Paste | Bayview Blog
Craigslist Niles Ohio
Craigslist Vans
Miss Carramello
Arrests reported by Yuba County Sheriff
J Prince Steps Over Takeoff
Best Restaurants In Seaside Heights Nj
Lost Pizza Nutrition
Valentina Gonzalez Leaked Videos And Images - EroThots
Whitley County Ky Mugshots Busted
The Weather Channel Facebook
Pro Groom Prices – The Pet Centre
Shuiby aslam - ForeverMissed.com Online Memorials
People Portal Loma Linda
Moparts Com Forum
D10 Wrestling Facebook
Fool’s Paradise movie review (2023) | Roger Ebert
New Stores Coming To Canton Ohio 2022
Ukc Message Board
Libinick
Ubg98.Github.io Unblocked
Uconn Health Outlook
Ahn Waterworks Urgent Care
Between Friends Comic Strip Today
Chase Bank Pensacola Fl
Egizi Funeral Home Turnersville Nj
Shreveport City Warrants Lookup
Cookie Clicker Advanced Method Unblocked
Fiona Shaw on Ireland: ‘It is one of the most successful countries in the world. It wasn’t when I left it’
Webworx Call Management
Top 20 scariest Roblox games
3 Ways to Drive Employee Engagement with Recognition Programs | UKG
Rs3 Bring Leela To The Tomb
Ipcam Telegram Group
Delta Rastrear Vuelo
6465319333
Fox And Friends Mega Morning Deals July 2022
Metro 72 Hour Extension 2022
Covalen hiring Ai Annotator - Dutch , Finnish, Japanese , Polish , Swedish in Dublin, County Dublin, Ireland | LinkedIn
Indiefoxx Deepfake
Arcadia Lesson Plan | Day 4: Crossword Puzzle | GradeSaver
Rochester Ny Missed Connections
The Transformation Of Vanessa Ray From Childhood To Blue Bloods - Looper
Sabrina Scharf Net Worth
Obituaries in Hagerstown, MD | The Herald-Mail
Pathfinder Wrath Of The Righteous Tiefling Traitor
Uc Davis Tech Management Minor
Jammiah Broomfield Ig
Borat: An Iconic Character Who Became More than Just a Film
Tom Kha Gai Soup Near Me
How to Do a Photoshoot in BitLife - Playbite
Latest Posts
Article information

Author: Manual Maggio

Last Updated:

Views: 5283

Rating: 4.9 / 5 (69 voted)

Reviews: 92% of readers found this page helpful

Author information

Name: Manual Maggio

Birthday: 1998-01-20

Address: 359 Kelvin Stream, Lake Eldonview, MT 33517-1242

Phone: +577037762465

Job: Product Hospitality Supervisor

Hobby: Gardening, Web surfing, Video gaming, Amateur radio, Flag Football, Reading, Table tennis

Introduction: My name is Manual Maggio, I am a thankful, tender, adventurous, delightful, fantastic, proud, graceful person who loves writing and wants to share my knowledge and understanding with you.