Control Tutorials for MATLAB and Simulink (2024)

Key MATLAB commands used in this tutorial are: tf , step , feedback , pole , margin , stepinfo

Related Tutorial Links

  • Intro to Freq Resp
  • Freq Resp Activity
  • Lead/Lag Freq Resp

Related External Links

Contents

  • Open-loop response
  • Closed-loop response
  • Lead compensator

From the main problem, the open-loop transfer function for the aircraft pitch dynamics is

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

where the input is elevator deflection angle Control Tutorials for MATLAB and Simulink (2) and the output is the aircraft pitch angle Control Tutorials for MATLAB and Simulink (3).

For the original problem setup and the derivation of the above transfer function please refer to the Aircraft Pitch: System Modeling page

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%

Open-loop response

Let's first begin by examining the behavior of the open-loop plant. Specifically, create a new m-file, and enter the following commands. Note the scaling of the step response by 0.2 to account for the fact that the input is a step of 0.2 radians (11 degrees). Running this m-file in the MATLAB command window should give you the step response plot shown below.

t = [0:0.01:10];s = tf('s');P_pitch = (1.151*s + 0.1774)/(s^3 + 0.739*s^2 + 0.921*s);step(0.2*P_pitch,t);axis([0 10 0 0.8]);ylabel('pitch angle (rad)');title('Open-loop Step Response');grid

Control Tutorials for MATLAB and Simulink (4)

Examination of the above plot indicates that the open-loop system is unstable for a step input, that is, its output grows unbounded when given a step input. This is due to the fact that the transfer function has a pole at the origin.

Closed-loop response

Let's now close the loop on our plant and see if that stabilizes the system. Consider the following unity feedback architecture for our system.

Control Tutorials for MATLAB and Simulink (5)

The following code entered in the MATLAB command window generates the closed-loop transfer function assuming the unity-feedback architecture above and a unity-gain controller, C(s) = 1.

sys_cl = feedback(P_pitch,1)
sys_cl = 1.151 s + 0.1774 ---------------------------------- s^3 + 0.739 s^2 + 2.072 s + 0.1774 Continuous-time transfer function.

Examining the poles of this transfer function using the pole command as shown below, it can be seen that this closed-loop system is indeed stable since all of the poles have negative real part.

pole(sys_cl)
ans = -0.3255 + 1.3816i -0.3255 - 1.3816i -0.0881 + 0.0000i

Stability of this closed-loop system can also be determined using the frequency response of the open-loop system. The margin command generates the Bode plot for the given transfer function with annotations for the gain margin and phase margin of the system when the loop is closed as demonstrated below.

margin(P_pitch), grid

Control Tutorials for MATLAB and Simulink (6)

Examination of the above demonstrates that the closed-loop system is indeed stable since the phase margin and gain margin are both positive. Specifically, the phase margin equals 46.9 degrees and the gain margin is infinite. It is good that this closed-loop system is stable, but does it meet our requirements? Add the following code to your m-file and re-run and you will generate the step response plot shown below.

sys_cl = feedback(P_pitch,1);step(0.2*sys_cl), gridylabel('pitch angle (rad)');title('Closed-loop Step Response')

Control Tutorials for MATLAB and Simulink (7)

Examination of the above demonstrates that the settle time requirement of 10 seconds is not close to being met. One way to address this is to make the system response faster, but then the overshoot shown above will likely become a problem. Therefore, the overshoot must be reduced in conjunction with making the system response faster. We can accomplish these goals by adding a compensator to reshape the Bode plot of the open-loop system. The Bode plot of the open-loop system indicates behavior of the closed-loop system. More specifically,

  • the gain crossover frequency is directly related to the closed-loop system's speed of response, and
  • the phase margin is inversely related to the closed-loop system's overshoot.

Therefore, we need to add a compensator that will increase the gain crossover frequency and increase the phase margin as indicated in the Bode plot of the open-loop system.

Lead compensator

A type of compensator that can accomplish both of our goals is a lead compensator. Referring to the Lead and Lag Compensators page, a lead compensator adds positive phase to the system. Additional positive phase increases the phase margin, thus, increasing the damping. The lead compensator also generally increases the magnitude of the open-loop frequency response at higher frequencies, thereby, increasing the gain crossover frequency and overall speed of the system. Therefore, the settling time should decrease as a result of the addition of a lead compensator. The general form of the transfer function of a lead compensator is the following.

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

We thus need to find Control Tutorials for MATLAB and Simulink (9), Control Tutorials for MATLAB and Simulink (10) and Control Tutorials for MATLAB and Simulink (11). Typically, the gain Control Tutorials for MATLAB and Simulink (12) is set to satisfy requirements on steady-state error. Since our system is already type 1 (the plant has an integrator) the steady-state error for a step input will be zero for any value of Control Tutorials for MATLAB and Simulink (13). Even though the steady-state error is zero, the slow tail on the response can be attributed to the fact the velocity-error constant is too small. This deficiency can be addressed by employing a value of Control Tutorials for MATLAB and Simulink (14) that is greater than 1, in other words, a value of Control Tutorials for MATLAB and Simulink (15) that will shift the magnitude plot upward. Through some trial and error, we will somewhat arbitrarily choose Control Tutorials for MATLAB and Simulink (16) = 10. Running the following code in the MATLAB window will demonstrate the effect of adding this Control Tutorials for MATLAB and Simulink (17).

K = 10;margin(K*P_pitch), gridfigure;sys_cl = feedback(K*P_pitch,1);step(0.2*sys_cl), gridtitle('Closed-loop Step Response with K = 10')

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

From examination of the above Bode plot, we have increased the system's magnitude at all frequencies and have pushed the gain crossover frequency higher. The effect of these changes are evident in the closed-loop step response shown above. Unfortunately, the addition of the Control Tutorials for MATLAB and Simulink (20) has also reduced the system's phase margin as evidenced by the increased overshoot in the system's step response. As mentioned previously, the lead compensator will help add damping to the system in order to reduce the overshoot in the step response.

Continuing with the design of our compensator, we will next address the parameter Control Tutorials for MATLAB and Simulink (21) which is defined as the ratio between the zero and pole. The larger the separation between the zero and the pole the greater the bump in phase where the maximum amount of phase that can be added with a single pole-zero pair is 90 degrees. The following equation captures the maximum phase added by a lead compensator as a function of Control Tutorials for MATLAB and Simulink (22).

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

Relationships between the time response and frequency response of a standard underdamped second-order system can be derived. One such relationship that is a good approximation for damping ratios less than approximately 0.6 or 0.7 is the following.

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

While our system does not have the form of a standard second-order system, we can use the above relationship as a starting point in our design. As we are required to have overshoot less than 10%, we need our damping ratio Control Tutorials for MATLAB and Simulink (25) to be approximately larger than 0.59 and thus need a phase margin greater than about 59 degrees. Since our current phase margin (with the addition of Control Tutorials for MATLAB and Simulink (26)) is approximately 10.4 degrees, an additional 50 degrees of phase bump from the lead compensator should be sufficient. Since it is known that the lead compensator will further increase the magnitude of the frequency response, we will need to add more than 50 degrees of phase lead to account for the fact that the gain crossover frequency will increase to a point where the system has more phase lag. We will somewhat arbitrarily add 5 degrees and aim for a total bump in phase of 50+5 = 55 degrees.

We can then use this number to solve the above relationship for Control Tutorials for MATLAB and Simulink (27) as shown below.

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

From the above, we can calculate that Control Tutorials for MATLAB and Simulink (29) must be less than approximately 0.10. For this value of Control Tutorials for MATLAB and Simulink (30), the following relationship can be used to determine the amount of magnitude increase that will be supplied by the lead compensator at the location of the maximum bump in phase.

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

Examining the Bode plot shown above, the magnitude of the uncompensated system equals -10 dB at approximately 6.1 rad/sec. Therefore, the addition of our lead compensator will move the gain crossover frequency from 3.49 rad/sec to approximately 6.1 rad/sec. Using this information, we can then calculate a value of Control Tutorials for MATLAB and Simulink (32) from the following in order to center the maximum bump in phase at the new gain crossover frequency in order to maximize the system's resulting phase margin.

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

With the values Control Tutorials for MATLAB and Simulink (34) = 10, Control Tutorials for MATLAB and Simulink (35) = 0.10, and Control Tutorials for MATLAB and Simulink (36) = 0.52 calculated above, we now have a first attempt at our lead compensator. Adding the following lines to your m-file and running at the command line will generate the plot shown below demonstrating the effect of your lead compensator on the system's frequency response.

K = 10;alpha = 0.10;T = 0.52;C_lead = K*(T*s + 1) / (alpha*T*s + 1);margin(C_lead*P_pitch), grid

Control Tutorials for MATLAB and Simulink (37)

Examination of the above demonstrates that the lead compensator increased the system's phase margin and gain crossover frequency as desired. We now need to look at the actual closed-loop step response in order to determine if we are close to meeting our requirements. Replace the step response code in your m-file with the following and re-run in the MATLAB command window.

sys_cl = feedback(C_lead*P_pitch,1);step(0.2*sys_cl), gridtitle('Closed-loop Step Response with K = 10, \alpha = 0.10, and T = 0.52')

Control Tutorials for MATLAB and Simulink (38)

Examination of the above demonstrates that we are close to meeting our requirements. Using the MATLAB command stepinfo as shown below we can see precisely the characteristics of the closed-loop step response.

stepinfo(0.2*sys_cl)
ans = struct with fields: RiseTime: 0.2074 SettlingTime: 8.9835 SettlingMin: 0.1801 SettlingMax: 0.2240 Overshoot: 11.9792 Undershoot: 0 Peak: 0.2240 PeakTime: 0.4886

From the above, all of our requirements are met except for the overshoot which is a bit larger than the requirement of 10%. Iterating on the above design process, we arrive at the parameters Control Tutorials for MATLAB and Simulink (39) = 10, Control Tutorials for MATLAB and Simulink (40) = 0.04, and Control Tutorials for MATLAB and Simulink (41) = 0.55. The performance achieved with this controller can then be verified by modifying the code in your m-file as follows.

K = 10;alpha = 0.04;T = 0.55;C_lead = K*(T*s + 1) / (alpha*T*s + 1);sys_cl = feedback(C_lead*P_pitch,1);step(0.2*sys_cl), gridtitle('Closed-loop Step Response with K = 10, \alpha = 0.04, and T = 0.55')

Control Tutorials for MATLAB and Simulink (42)

Examination of the above step response demonstrates that the requirements are now met. Using the stepinfo command again more clearly demonstrates that the requirements are met.

stepinfo(0.2*sys_cl)
ans = struct with fields: RiseTime: 0.2203 SettlingTime: 9.0427 SettlingMin: 0.1805 SettlingMax: 0.2137 Overshoot: 6.8478 Undershoot: 0 Peak: 0.2137 PeakTime: 0.5394

Therefore, the following lead compensator is able to satisfy all of our design requirements.

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


Published with MATLAB® 9.2

Control Tutorials for MATLAB and Simulink (2024)

FAQs

Is MATLAB Simulink hard to learn? ›

Is MATLAB 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.

How much time does it take to learn Simulink? ›

Learn MATLAB and SIMULINK in one week

Ideal for beginners from any field, it covers vectors, matrices, loops, and functions.

How long does it take to be proficient in 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.

Why is MATLAB saying not enough input arguments? ›

your function needs to be called with at least three input arguments. Therefore you must call it with exactly three input arguments. From the text of the error message you're likely calling it with fewer than three input arguments.

Is MATLAB harder than Python? ›

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.

What is the salary of MATLAB Simulink engineer? ›

Matlab Simulink Developer salary in India ranges between ₹ 2.9 Lakhs to ₹ 15.0 Lakhs with an average annual salary of ₹ 5.5 Lakhs. Salary estimates are based on 46 latest salaries received from Matlab Simulink Developers. 1 - 4 years exp.

Does NASA use Simulink? ›

NASA Marshall Engineers have developed an ADCS Simulink simulation to be used as a component for the flight software of a satellite. This generated code can be used for carrying out Hardware in the loop testing of components for a satellite in a convenient manner with easily tunable parameters.

What is the disadvantage of Simulink? ›

Simulink's drawback lies in its confinement to pre-existing block functionalities, potentially limiting specific needs or requiring adjustments that might not align with desired behaviors or appearances.

Do engineers use Simulink? ›

Engineering: MATLAB and SIMULINK are commonly used in engineering disciplines such as electrical, mechanical, and aerospace engineering. Job opportunities can include system modeling, control systems design, signal processing, and simulation.

Is MATLAB in high demand? ›

High Demand: Employers across industries, including engineering, finance, and research, actively seek skilled MATLAB professionals.

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.

Can I learn MATLAB on my own? ›

MATLAB's official website provides comprehensive resources, including documentation, tutorials, and examples. The MATLAB documentation covers all aspects of the language and its various toolboxes. It's an excellent starting point for learning MATLAB from scratch.

How do I make MATLAB more accurate? ›

By default, MATLAB® uses 16 digits of precision. For higher precision, use the vpa function in Symbolic Math Toolbox™. vpa provides variable precision which can be increased without limit.

How to improve performance in MATLAB? ›

Improve the Performance of Your MATLAB Code
  1. Measure code execution time with functions like tic , toc , and timeit.
  2. Use the MATLAB Profiler to see which parts of your program take the most time to run.
  3. Use the MATLAB Code Analyzer for additional suggestions to improve performance.

Is it possible to have no outputs to a function in MATLAB? ›

The user-defined function below draws a star, but does not return a value. Note that in the function declaration line (signature) that empty square brackets are placed where the output value would normally go. The inputs are the size and color of the star.

How to learn MATLAB Simulink? ›

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.

Is Simulink better than MATLAB? ›

Another factor to consider when choosing between Simulink blocks and MATLAB code is the speed and efficiency of your system. Simulink blocks can be faster and more efficient for some tasks, such as prototyping, testing, and debugging.

Is MATLAB easy to learn for beginners? ›

If you're new to programming and eager to explore the world of numerical computation, MATLAB is an excellent starting point. MATLAB, developed by MathWorks, is a versatile programming language that simplifies complex mathematical operations through its matrix-centric approach.

Is Simulink worth it? ›

Simulink is one of the most effective block diagram environment for modelling, simulation, and analysis of diverse systems. It is an intuitive tool that is very simple to understand.

Top Articles
Latest Posts
Recommended Articles
Article information

Author: Allyn Kozey

Last Updated:

Views: 6071

Rating: 4.2 / 5 (63 voted)

Reviews: 86% of readers found this page helpful

Author information

Name: Allyn Kozey

Birthday: 1993-12-21

Address: Suite 454 40343 Larson Union, Port Melia, TX 16164

Phone: +2456904400762

Job: Investor Administrator

Hobby: Sketching, Puzzles, Pet, Mountaineering, Skydiving, Dowsing, Sports

Introduction: My name is Allyn Kozey, I am a outstanding, colorful, adventurous, encouraging, zealous, tender, helpful person who loves writing and wants to share my knowledge and understanding with you.