Control Tutorials for MATLAB and Simulink (2024)

Key MATLAB commands used in this tutorial are: ss , ctrb , rank , lqr , step

Related Tutorial Links

  • State Space Intro
  • LQR Animation 1
  • LQR Animation 2

Related External Links

Contents

  • Controllability
  • Control design via pole placement
  • Linear quadratic regulation
  • Adding precompensation

In the Aircraft Pitch: System Modeling page. the state-space model of the plant was derived as

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

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

where the input is elevator deflection angle Control Tutorials for MATLAB and Simulink (3) and the output is the aircraft pitch angle Control Tutorials for MATLAB and Simulink (4). The above equations match the general, linear state-space form.

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

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

For a step reference of 0.2 radians, the design criteria are the following.

  • Overshoot less than 10%
  • Rise time less than 2 seconds
  • Settling time less than 10 seconds
  • Steady-state error less than 2%

In this page we will apply a state-space controller design technique. In particular, we will attempt to place the closed-loop poles of the system by designing a controller that calculates its control based on the states of the system.

Controllability

In order to apply our state-space controller design techniques we need to first verify an important property, controllability. The controllability property is necessary to guarantee that we have the authority to drive the state of the system anywhere we like. This corresponds to the ability to place the closed-loop poles of the system anywhere in the complex s-plane.

For the system to be completely state controllable, the controllability matrix

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

must have rank Control Tutorials for MATLAB and Simulink (8). The rank of a matrix is the number of linearly independent rows (or columns). The number Control Tutorials for MATLAB and Simulink (9) corresponds to the number of state variables of the system. Adding additional terms to the controllability matrix with higher powers of the matrix Control Tutorials for MATLAB and Simulink (10) will not increase the rank of the controllability matrix since these additional terms will just be linear combinations of the earlier terms.

Since our controllability matrix is 3x3, the rank of the matrix must be 3. The MATLAB command rank can give you the rank of this matrix. Create a new m-file and enter the following commands. Running this m-file in the MATLAB command window, will produce the following output.

A = [-0.313 56.7 0; -0.0139 -0.426 0; 0 56.7 0];B = [0.232; 0.0203; 0];C = [0 0 1];D = [0];co = ctrb(A,B);Controllability = rank(co)
Controllability = 3

Therefore, our system is completely state controllable since the controllability matrix has rank 3.

Control design via pole placement

The schematic of a full-state feedback control system is shown below (with Control Tutorials for MATLAB and Simulink (11) = 0).

Control Tutorials for MATLAB and Simulink (12)

where

  • Control Tutorials for MATLAB and Simulink (13) = control gain matrix
  • Control Tutorials for MATLAB and Simulink (14) = Control Tutorials for MATLAB and Simulink (15) = state vector
  • Control Tutorials for MATLAB and Simulink (16) = reference (Control Tutorials for MATLAB and Simulink (17))
  • Control Tutorials for MATLAB and Simulink (18) = Control Tutorials for MATLAB and Simulink (19) = control input (Control Tutorials for MATLAB and Simulink (20))
  • Control Tutorials for MATLAB and Simulink (21) = output (Control Tutorials for MATLAB and Simulink (22))

Referring back to the state-space equations at the top of the page, we see that substituting the state-feedback law Control Tutorials for MATLAB and Simulink (23) for Control Tutorials for MATLAB and Simulink (24) leads to the following.

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

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

Based on the above, matrix Control Tutorials for MATLAB and Simulink (27) determines the closed-loop dynamics of our system. Specfically, the roots of the determinant of the matrix Control Tutorials for MATLAB and Simulink (28) are the closed-loop poles of the system. Since the determinant of Control Tutorials for MATLAB and Simulink (29) is a third-order polynomial, there are three poles we can place and since our system is completely state controllable, we can place the poles anywhere we like. Recall from the Introduction: State-Space Methods for Controller Design page that a "pole-placement" technique can be used to find the control gain matrix Control Tutorials for MATLAB and Simulink (30) to place the closed-loop poles in the desired locations. Note that this feedback law presumes that all of the state variables in the vector Control Tutorials for MATLAB and Simulink (31) are measured, even though Control Tutorials for MATLAB and Simulink (32) is our only output. If this is not the case, then an observer needs to be designed to estimate the other state variables.

We know from the above that we can place the closed-loop poles of the system anywhere we would like. The question then that is left is, where should we place them? If we have a standard first- or second-order system, we then have relationships that directly relate pole locations to characteristics of the step response and can use these relations to place the poles in order to meet our given requirements. This process becomes more difficult if we have a higher-order system or zeros. With a higher-order system, one approach is to place the higher-order poles 5-10 times farther to the left in the complex plane than the dominant poles, thereby leading them to have negligible contribution to the transient response. The effect of zeros is more difficult to address using a pole-placement approach to control. Another limitation of this pole-placement approach is that it doesn't explicitly take into account other factors like the amount of required control effort.

Linear quadratic regulation

We will use a technique called the Linear Quadratic Regulator (LQR) method to generate the "best" gain matrix Control Tutorials for MATLAB and Simulink (33), without explicitly choosing to place the closed-loop poles in particular locations. This type of control technique optimally balances the system error and the control effort based on a cost that the designer specifies that defines the relative importance of minimizing errors and minimimizing control effort. In the case of the regulator problem, it is assumed that the reference is zero. Therefore, in this case the magnitude of the error is equal to the magnitude of the state. Please consult your control textbook for details. To use this LQR method, we need to define two parameters: the state-cost weighted matrix (Control Tutorials for MATLAB and Simulink (34)) and the control weighted matrix (Control Tutorials for MATLAB and Simulink (35)). For simplicity, we will choose the control weighted matrix equal to 1 (Control Tutorials for MATLAB and Simulink (36) = 1), and the state-cost matrix (Control Tutorials for MATLAB and Simulink (37)) equal to Control Tutorials for MATLAB and Simulink (38). Employing the vector Control Tutorials for MATLAB and Simulink (39) from the output equation means that we will only consider those states in the output in defining our cost. In this case, Control Tutorials for MATLAB and Simulink (40) is the only state variable in the output. The weighting factor (Control Tutorials for MATLAB and Simulink (41)) will be varied in order to modify the step response. In this case, Control Tutorials for MATLAB and Simulink (42) is a scalar since we have a single input system.

Now we are ready to find the control matrix (Control Tutorials for MATLAB and Simulink (43)) employing the MATLAB command lqr. We will first let the weighting factor (Control Tutorials for MATLAB and Simulink (44)) equal 2. Add the following commands to your m-file and run it in the MATLAB command window.

p = 2;Q = p*C'*CR = 1;[K] = lqr(A,B,Q,R)
Q = 0 0 0 0 0 0 0 0 2K = -0.5034 52.8645 1.4142

Note the structure of the weighting matrix Control Tutorials for MATLAB and Simulink (45) and the resulting gain matrix Control Tutorials for MATLAB and Simulink (46). Referring to the closed-loop state equations given above assuming a control law with non-zero reference, Control Tutorials for MATLAB and Simulink (47), we can then generate the closed-loop step response by adding the following commands to your m-file and running it in the MATLAB command window. Note that the response is scaled to model the fact that the pitch angle reference is a 0.2 radian (11 degree) step. The step response shown below should then be generated.

sys_cl = ss(A-B*K, B, C, D);step(0.2*sys_cl)ylabel('pitch angle (rad)');title('Closed-Loop Step Response: LQR');

Control Tutorials for MATLAB and Simulink (48)

Examination of the above demonstrates that the response is too slow. We can tune the performance of our system to be faster by weighting the importance of the error more heavily than the importance of the control effort. More specifically, this can be done by increasing the weighting factor Control Tutorials for MATLAB and Simulink (49). After some trial and error, we settle on a value of Control Tutorials for MATLAB and Simulink (50) = 50. Modify the code of your m-file as follows and then run at the command line to produce the following step response.

p = 50;Q = p*C'*C;R = 1;[K] = lqr(A,B,Q,R)sys_cl = ss(A-B*K, B, C, D);step(0.2*sys_cl)ylabel('pitch angle (rad)');title('Closed-Loop Step Response: LQR');
K = -0.6435 169.6950 7.0711

Control Tutorials for MATLAB and Simulink (51)

Examination of the above demonstrates that the rise time, overshoot, and settling time are satisfactory. However, there is a large steady-state error. One way to correct this is by introducing a precompensator (Control Tutorials for MATLAB and Simulink (52)) to scale the overall output.

Adding precompensation

Unlike other design methods, the full-state feedback system does not compare the output to the reference; instead, it compares all states multiplied by the control matrix (Control Tutorials for MATLAB and Simulink (53)) to the reference (see the schematic shown above). Thus, we should not expect the output to equal the commanded reference. To obtain the desired output, we can scale the reference input so that the output does equal the reference in steady state. This can be done by introducing a precompensator scaling factor called Control Tutorials for MATLAB and Simulink (54). The basic schematic of our state-feedback system with scaling factor (Control Tutorials for MATLAB and Simulink (55)) is shown below.

Control Tutorials for MATLAB and Simulink (56)

We can easily find Control Tutorials for MATLAB and Simulink (57) from the MATLAB function rscale.m. Since rscale.m is a user-defined function, you need to copy and save the function to your directory. For further assistance in using user-defined functions, refer to the function page. After you have saved the rscale.m file to your directory, modify the code of your m-file as follows and run it in the MATLAB command window.

p = 50;Q = p*C'*C;R = 1;[K] = lqr(A,B,Q,R);Nbar = rscale(A,B,C,D,K)
Nbar = 7.0711

Adding the following code and rerunning your m-file will then generate the response shown below.

sys_cl = ss(A-B*K,B*Nbar,C,D);step(0.2*sys_cl)ylabel('pitch angle (rad)');title('Closed-Loop Step Response: LQR with Precompensation');

Control Tutorials for MATLAB and Simulink (58)

Now the steady-state error has been eliminated and all design requirements are satisfied.

Note that the precompensator Control Tutorials for MATLAB and Simulink (59) employed above is calculated based on the model of the plant and further that the precompensator is located outside of the feedback loop. Therefore, if there are errors in the model (or unknown disturbances) the precompensator will not correct for them and there will be steady-state error. You may recall that the addition of integral control may also be used to eliminate steady-state error, even in the presence of model uncertainty and step disturbances. For an example of how to implement integral control in the state space setting, see the DC Motor Position: State-Space Methods for Controller Design page. The tradeoff with using integral control is that the error must first develop before it can be corrected for, therefore, the system may be slow to respond. The precompensator on the other hand is able to anticipitate the steady-state offset using knowledge of the plant model. A useful technique is to combine the precompensator with integral control to leverage the advantages of each approach.


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.

How difficult is MATLAB to learn? ›

MATLAB® is not hard to learn if you go for any professional course. It is ideal for engineering graduates and IT professionals willing to develop MATLAB® skills in their related fields.

How much time does it take 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.

Can I learn MATLAB on my own? ›

Start learning MATLAB and Simulink with free tutorials. Expand your knowledge through interactive courses, explore documentation and code examples, or watch how-to videos on product capabilities. Note: You must be on a desktop computer to take courses.

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 to solve MATLAB equations? ›

Solve an Equation

If eqn is an equation, solve(eqn, x) solves eqn for the symbolic variable x . Use the == operator to specify the familiar quadratic equation and solve it using solve . solx is a symbolic vector containing the two solutions of the quadratic equation.

Which is harder Python or MATLAB? ›

Learning curve: Python is significantly simpler than Matlab and doesn't require as much background knowledge. Matlab is structured in a very logical and comprehensible way but is aimed at users with a deep knowledge of math.

Is MATLAB or Python better for machine learning? ›

MATLAB may have an edge for computationally intensive tasks, but for general-purpose programming, data manipulation, and machine learning, Python's performance is often deemed satisfactory.

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.

What is Simulink used for in MATLAB? ›

Simulink is the platform for Model-Based Design that supports system-level design, simulation, automatic code generation, and continuous test and verification of embedded systems. Key capabilities include: A graphical editor for modeling all components of a system.

Is MATLAB in high demand? ›

It is an essential tool for engineers, data analysts, scientists, and researchers who work with large amounts of data. In today's job market, the demand for professionals with MATLAB skills is on the rise, and many employers prefer candidates who have experience working with MATLAB.

Is MATLAB beginner friendly? ›

MATLAB is beginner-friendly, so you can learn it even if you're new to programming.

Is MATLAB real coding? ›

MATLAB is a high-level programming language designed for engineers and scientists that expresses matrix and array mathematics directly.

How much does it cost to get MATLAB certified? ›

Upcoming Certification Exams
DatesCertification ExamPrice
22 Oct 2024MathWorks Certified MATLAB Professional ExamUSD 800
14 Nov 2024MathWorks Certified MATLAB Professional ExamUSD 800
10 Dec 2024MathWorks Certified MATLAB Professional ExamUSD 800

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 open Solver in MATLAB? ›

Open the Solver Profiler by clicking the hyperlink in the lower-right corner of the Simulink® Editor. The Solver Profiler provides smart logging and diagnostics of continuous model states and Simscape™ states. To enable this, select the Continuous States, Zero Crossing or Simscape States option before a run.

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.

References

Top Articles
Octopath Traveler 2: How To Easily Complete The Five-Tiered Tower | Optional Bosses Guide - Gameranx
Octopath Traveler: The Best Character / Secret Job Combos | Ultimate Team Guide - Gameranx
Wmaz 13
Words With Friends Cheat Board Layout 11X11
Incredibox Deluxe
Hallmark White Coat Ceremony Cards
Growing At 495%, Saviynt Says It Prevails Over SailPoint In $20B Market
Phun.celeb
Everything You Might Want to Know About Tantric Massage - We've Asked a Pro
Kcrubicon
New Stores Coming To Canton Ohio 2022
gameplay:shiny_pokemon_and_luck [PokéRogue Wiki]
Milk And Mocha Bear Gifs
Aita For Helping My Girlfriend Get Over Her Trauma
Clarita Amish Auction 2023
Maryse Mizanin Nip Slip
Justine Waddell talks about a season of screenings MELODIA!
The Obscure Spring Watch Online Free
Craigslist Westchester Cars For Sale By Owner
2406982423
Gncc Live Timing And Scoring
Ratchet & Clank Rift Apart: Trofea - lista | GRYOnline.pl
Biobased Circular Business Platform
Spinning Gold Showtimes Near Mjr Westland Grand Cinema 16
Thermal Pants Mens Walmart
Pole Barns 101: Everything You Need to Know - Big Buildings Direct
Liquor Barn Redding
Chess Unblocked Games 66
Vineland Daily Journal Obits
Lucky Dragon Net
2005 Chevy Colorado 3.5 Head Bolt Torque Specs
Cal Poly 2027 College Confidential
San Bernardino Pick A Part Inventory
Are Swagg And Nadia Dating? The Streamers Appear More Than Friends - Eliktopia
Super Restore Vs Prayer Potion
Sky Nails Albany Oregon
Harry Potter 3 123Movies
Embu village mines precious coltan for years 'without knowing its value’
Brian Lizer Life Below Zero Next Generation
Liv Morgan Wedgie
Exterior Ballistics Calculator
Acbl Homeport
Everything 2023's 'The Little Mermaid' Changes From the Original Disney Classic
Arrival – AIRPOWER24 6th – 7th Sept 24
The Stock Exchange Kamas
Alibaba Expands Membership Perks for 88VIP
Riscap Attorney Registration
Benson Downs Resident Portal
Kaiju Universe: Best Monster Tier List (January 2024) - Item Level Gaming
Nine Star Hegemon Body Art
Eugenics Apush
Latest Posts
Article information

Author: Tuan Roob DDS

Last Updated:

Views: 5960

Rating: 4.1 / 5 (62 voted)

Reviews: 85% of readers found this page helpful

Author information

Name: Tuan Roob DDS

Birthday: 1999-11-20

Address: Suite 592 642 Pfannerstill Island, South Keila, LA 74970-3076

Phone: +9617721773649

Job: Marketing Producer

Hobby: Skydiving, Flag Football, Knitting, Running, Lego building, Hunting, Juggling

Introduction: My name is Tuan Roob DDS, I am a friendly, good, energetic, faithful, fantastic, gentle, enchanting person who loves writing and wants to share my knowledge and understanding with you.