0% found this document useful (0 votes)
5 views7 pages

MATLAB Assignment 1

The document outlines a series of MATLAB-based laboratory exercises for Control System Engineering, covering basic operations, vectors, vector manipulation, polynomials, matrices, functions, and plotting. Each exercise includes specific tasks such as performing arithmetic operations, plotting graphs, solving equations, and analyzing transfer functions. The exercises aim to enhance understanding of control systems through practical MATLAB applications.

Uploaded by

jaxodo8684
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views7 pages

MATLAB Assignment 1

The document outlines a series of MATLAB-based laboratory exercises for Control System Engineering, covering basic operations, vectors, vector manipulation, polynomials, matrices, functions, and plotting. Each exercise includes specific tasks such as performing arithmetic operations, plotting graphs, solving equations, and analyzing transfer functions. The exercises aim to enhance understanding of control systems through practical MATLAB applications.

Uploaded by

jaxodo8684
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

MATLAB-based laboratory assignments

for Control System Engineering


EXERCISE 1: Basic Operations
Complete the table below in Matlab for the basic arithmetic operators shown: Use values of a=4
and b=-2.1

Operation Operator Example Result


Plus + a+b
Minus - a-b
Multiply * a*b
Power ^ a^b
Divide / a/b

EXERCISE 2: Vectors
a) Enter the first three prime numbers as a row vector.
b) Repeat (a), but use column vector.
c) The following table shows some measurements a voltage across a resistor as a function of
time.

Time(s) 0.0 1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0
Voltage (V) 1.1 1.2 1.3 1.4 1.5 1.4 1.3 1.2 1.1 1.0

d) Enter the time as a column vector called tim.


e) Enter the voltage as ac column vector called vol.
f) Enter the command plot (tim,vol).

Which variable is on the independent axis?


Which variable is on the dependent axis?

EXERCISE 3: Vector manipulation


Try the following vector operations and write down the results. Ensure that the dimensions of 'x'
and 'y' are appropriate for the operations attempted. Note that some of the operators are different
from the scalar operators.

Operation Operator Example Notes


Plus + x+y Must be same dimension

Minus - x-y Must be same dimension


Multiply * x*y Must be appropriate
dimension
Multiply element by element .* x.*y Must be same dimension

Divide element by element; second vector ./ x./y Must be same dimension


elements by first vector elements
Divide element by element; first vector .\ x.\y Must be same dimension
elements by second vector elements

Explain in words the three operations: .* , ./ and .\.


Think of an example where we might need this type of operation.

EXERCISE 4: Polynomials
We wish to plot a second-order polynomial y (t) = 4t2 + 2t – 3 as a function of time and check
the roots of the equation. We can do this in two ways:

1) We can enter the polynomial coefficients as a vector and use the roots command.
2) We can plot the function 'y' against time and note the points where the function cross the
time axis (that is, the point where y = 0). To do this, follow these steps.

(a) Write Matlab code to create a vector 't' which has values evenly spaced from –5 to
5, in steps of 0.5.
(b) Calculate y(t) = 4t2 + 2t – 3 for all values of the time vector, t. Since t is a vector,
think carefully how you will calculate 4t2 + 2t – 3.
(c) Request a plot using plot (t,y). Find the roots on the graph. Are the roots on the
graph similar to the answer in item 1 above?

Exercise 5: Matrices
Find the solution of the following set of linear equations:

2x1 + 5x2 – 3x3 = 6


3 x1– 2 x2 + 4 x3 = -2
x1 + 6 x2 – 4 x3 = 3

Hint: We write this in the matrix form, that is, AX = B, where


A is the matrix of coefficients of x1, x2 and x3
X is the column vector which will contain the solutions x1, x2 and x3
B is the column vector on the RHS
Answer: X = A-1B = ?
EXERCISE 6: Functions

A sine wave of amplitude 5 and frequency 0.1 Hz is applied to the input of an analog device
which has a constant gain of 1.5 over all frequencies. Write Matlab code to calculate the output
signal for the interval 0 to 10 seconds in increments of 0.1 seconds.

Use the command plot(t,y) to see a graph of this signal. What is the frequency of the sine wave
on the plot? (Use the grid command to help work this out (approximately).
Does it agree with the frequency of 0.1 Hz given in the question?

EXERCISE 7:
(a) Enter the complex number 3 + j4 in Matlab.
(b) Find the modulus and angle of this complex number.
(c) Convert the calculated magnitude to dB and the value of angle to degrees.
(d) Write down the Matlab commands that were entered.

EXERCISE 8: Plotting

The input-output relationship of a n RC circuit can be represented by the following complex


function:

g(jω) = Vo/Vi = K/(jτω+1)

Where K is the gain and τ is the time constant.

(a) For K=10 and τ = 5, write Matlab code to calculate the gain and phase of V o/Vi for ω = 0.01,
0.05, 0.1, 2,5,10 rad/s.
(a) Plot the gain and phase using the semilogx command.

Hints:
1. Enter the values of K and τ as K and tau. Define a frequency vector, w.
2. Calculate g = K. /(j*tau*w+1). Note the operation ./.
3. Calculate the gain in dB and the phase in degrees.
4. Plot the response using semilogx (w, gain) and semilogx (w,phase).
5. Label the axes and insert a title for the plot.

EXERCISE 9: Given the following transfer functions:

3( s  1 ) 2s  3
g1(s) = , g2(s) =
s 2  3s  1 s ^ 3 1
(a) Enter g1(s) using row vectors
(b) Enter g2(s) using the s=tf(‘s’) notation. Record from the screen the MATLAB
commands that were entered.
(c) Find the roots of the numerator and denominator polynomials using the roots
command.
(d) Compare with the results using the zero and pole commands.
(e) Examine where the roots are using the pzmap function.

Exercise 10:
1) Create a time vector t with points spaced at 0.1 seconds between 0 and 10 seconds. Plot the
function y = 2 sint + 3cost and use the max function to find the maximum value of the function.
Verify using the cursor.
2) write Matlab code to find the roots of the following polynomial equations:
a) s3+2s2+1 = 0
b) p3+1 = 0
c) –3s2-5+2 = 0

3) For the following transfer function descriptions, enter the Matlab commands to provide the
appropriate transfer function expression.
a) System GA has a unity gain at ω = 0 rad/sec, a pole at –3 and a zero at –
4.
b) System GB has a gain of 10 at ω = 0rad/sec, a zero at –1 and two poles at
–1+j0.5 and –1-j0.5.
c) System GC has an infinite gain at ω = 0 rad/sec, a zero at –6, two poles
at the origin and a pole at –4.

4) For the following system, where G1(s) = 1/(τs+1) and U(s) is a unit step input, write an M-
file to plot the output y(t) for the three cases τ = 2, τ = 4 and τ = 6 seconds. Plot the three
responses on the same graph.

U(s) Y(s)
G1(s)

5) Given the following transfer functions:

s ^ 2  2s  1 2s ^ 2  3
g1(s) = , g2(s) =
s ^ 3  3s ^ 2  1 ( s ^ 3  1 )( s ^ 2  s  1 )

a) Enter g1(s) using row vector.


b) Enter g2(s) using the s = tf(‘s’) notation. Record from the screen
the Matlab commands that were entered.
c) Write Matlab code to find the zeros of the numerator and
denominator of g1(s) using the roots command.
d) Write Matlab code to compare with the results using the zero and
pole commands. Examine where the roots are using the pzmap
function.
e) Write Matlab code to find the zeros and poles of g2(s) using
appropriate commands. Use the pzmap function to ascertain if the
system is stable.

6) Write an M-file to solve the following set of equations:

2 1 0 0 x 1
1 2 1 0 y 1
0 1 2 1 z = 1
0 0 1 2 t -2

7) The Laplace transform of a time delay is e -Ts. The following transfer function has a time
delay of 2 seconds.
G(s) = (10 e-2s)/ (5s+1)

a) Enter a transfer function g1 which represents g(s) without the time delay.
b) Enter get(g1); we see in the list of attributes of g1 when input delay is zero.
c) Use the following commands to enter g(s):
g = g1;
set (g, ‘inputdelay’,2)
d) Plot the step response of the system with and without the time delay and compare the
results.

[11] Write a Matlab function to check whether the number N is prime. (Hint: investigate the mod
function)

[12] The input-output relationship of a servo system can be represented by the following
complex function:
 K
G(jω) = =
Vi j ( j  1 )
Where K is the gain and τ is the time constant.

a) For K=10 and τ = 2.5, calculate the gain and phase of for ω = 0.01,0.05,0.1,2,5,10
Vi
(rad/sec).
b) Plot the gain and phase using the semilogx command.

[13] Write an M-file to find and plot the response of the following system to an input signal of
R(s) = 10/s.
R(s) + Y(s)
0.1/s 1/(s+1)
-
[14] Plot the frequency response of the following system for K=1.

10 K
G(s) =
s( s  5 )

a) Determine the frequency at which the magnitude plots crosses the 0 dB line.
b) What value of K would ensure that the magnitude plot crosses 0 dB at 5 rad/s?

[15] Write an M-file which enters the following transfer function and plots the two step
responses corresponding to k=1 and k=2 on the same plot.
k
g1( s)  .
( s  1)

7
[16] For a unity feedback system with G(s) = . Write Matlab code to determine
( s 2  4s  2)
transient and steady-state specifications. Also implement the same using unity-feedback system
in SIMULINK.

[17] Consider a system described by the following differential equations:

2
Y 1( s )  U 1( s )
3s  1
5
Y 2( s)  6Y 1( s )  U 2( s )
6s  1

(a) Implement the model in simulink.


(b) Plot y2(t) for u1(t)=u2(t)=1.

[18] Write an M-file to find the transient response specifications to a step input of
magnitude 3and also plot the response for the following systems:
10 3
(a) G(s)  (b) G(s) 
2s  1 s4

[19] An open-loop system is given by

(2s  1)
G( s) 
(0.5s  1)(12s  1)
(10s  1)
The system is placed in a unity-feedback loop with a controller K(S) =
s
in the forward path. Using MATLAB, determine the closed-loop poles and zeros.
Comment on the stability of the system.

[20] The figure below shows a typical closed-loop system with the system transfer
function G(S) and the controller transfer function K(s).

6
G( s)  .
( s  1)
Write Matlab code to determine the close-loop transfer function and the steady-state error for the
controller K(s) being:
(a) A P controller
(b) PD controller
(c) PI controller
(d) PID controller. Comment on the error produced for each controller.

[21] For the following system write MATLAB code to plot the root locus.

( s  4) K
(a) G( s)  . (b) G( s)  , K  1.
( s  1)( s  2)( s  3) s( s  2)
[22] For the following systems
1 400
(a) G( s)  (b) G( s) 
( s 2  0.6s  1) ( s  10)( s 2  0.4s  4)
Write MATLAB code to plot the frequency response and determine stability margins using:
(a) Bode plot
(b) Nichols plot
(c) Nyquist plot.
Comment on stability of the systems.

You might also like