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

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? ›

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 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 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? ›

Select solvers in the Solver pane of model configuration parameters. All solvers provided by MATLAB® and Simulink follow a similar naming convention: ode , followed by two or three numerals indicating the orders of the solver.

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? ›

Matlab Developer salary in India ranges between ₹ 2.0 Lakhs to ₹ 9.4 Lakhs with an average annual salary of ₹ 5.5 Lakhs. Salary estimates are based on 343 latest salaries received from Matlab Developers. 1 - 5 years exp. 1 - 5 years exp.

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 coding language is MATLAB most like? ›

Language Comparison

The language of Python and MATLAB can be used interactively (a single command at a time) or to develop large-scale applications.

Can I learn MATLAB on my own? ›

Get Started with Introductory Videos

See common applications and workflows, and discover new product capabilities. Get started with MATLAB by walking through an example. This video shows you the basics, and it gives you an idea of what working in MATLAB is like.

What should I learn first MATLAB or Python? ›

The OOP in MATLAB is more advanced and complex, which to some can be more confusing. That being said, MATLAB is generally a more advanced language while Python is more of a beginner's language. Therefore, just because MATLAB may be more complex and confusing at first, with practice, it will become easier to grasp.

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

What should I learn before learning MATLAB? ›

Also, it would be beneficial to have some basic knowledge on linear algebra and calculus. However, it is not essential to have any prior programming experience or a strong mathematical background as this course is designed with beginners in mind.

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.

How do you search text in MATLAB? ›

Search for Text

To locate where the text occurs, use the strfind function, which returns starting indices. Find and extract text using extraction functions, such as extract , extractBetween , extractBefore , or extractAfter . Optionally, include the boundary text.

Top Articles
Latest Posts
Recommended Articles
Article information

Author: Cheryll Lueilwitz

Last Updated:

Views: 5413

Rating: 4.3 / 5 (54 voted)

Reviews: 93% of readers found this page helpful

Author information

Name: Cheryll Lueilwitz

Birthday: 1997-12-23

Address: 4653 O'Kon Hill, Lake Juanstad, AR 65469

Phone: +494124489301

Job: Marketing Representative

Hobby: Reading, Ice skating, Foraging, BASE jumping, Hiking, Skateboarding, Kayaking

Introduction: My name is Cheryll Lueilwitz, I am a sparkling, clean, super, lucky, joyous, outstanding, lucky person who loves writing and wants to share my knowledge and understanding with you.