PP Introduction To MATLAB
PP Introduction To MATLAB
Dosen pengampu
Sutanto
2. Matrices
Input of a matrix can be carried out as below:
The important basic matrix operations are addition and subtraction, multiplication, transpose,
powers, and so-called array operations, which are element-to-element operations. Colon notation
allows us to generate a row vector containing the numbers from a given starting value, xi, to a final
value, xf, with a specified increment, dx. It is shown in Fig. 2.
MATLAB can be used to assist in the analysis of a typical system, for example a spring-mass-
damper. Using a MATLAB, we will develop an interactive analysis capability to analyze the effects of
natural frequency and damping on the unforced response of the mass displacement. In particular, we
are interested in how MATLAB can assist us in manipulating polynomials, computing poles and zeros of
transfer functions, computing closed-loop transfer functions, block diagram reduction, and computing
the response of a system to a unit step input.
1. Spring-Mass-Damper System
A spring-mass-damper mechanical system is shown in Fig. 8
The motion of the mass, denoted by y(t), is described by the differential equation.
r(t) represents the forcing function. The model is based on lumped, linear time-invariant approximation
to the physical process. It is valid only in regions where the spring force is a linear function of the mass
displacement, and the damping due to friction is a linear function of the velocity.
The mathematical model might represent an off-road vehicle shock absorber. Our objective
could be to design an active control system to make the ride smoother when traversing unpaved roads.
The control design and subsequent analysis would be based on the vehicle shock absorber model in the
Eq. The real test of the control design is to meet the objective of smoother ride on a bumpy road, but
we will see how to use MATLAB to enhance our control design and analysis capability.
The unforced dynamic response, y(t), of the spring-mass-damper mechanical system is
Where ϴ = cos-1ζ. The initial displacement is y(0). The transient system response is underdamped when ζ
<1, overdamped when ζ > 1, and critically damped when ζ = 1. Consider the overdamped and
underdamped cases:
The MATLAB commands and script to generate the plot of the unforced response are shown in Fig.
9. In the MATLAB setup, the variables y(0), ωn, t, ζ1, and ζ2 are input typed in the MATLAB command
window. The time-response plot is in Fig. 10. Since you can relate the natural frequency and damping
ratio to the spring constant, K, and friction f, you can also analyze the effect of K and f on the response.
2. Transfer Function
The transfer function is an input-output description of an LTI system. It relates the Laplace transform
of the output variable to the Laplace transform of the input variable with zero initial conditions.
Consider the LTI system described by the transfer function G(s), where
Where m<=n. The roots of the numerator polynomial of G(s) are called the zeros of the system; the
roors of the denominator polynomial are called the poles. Setting the denominator polynomial to zero
yields the characteristic equation
The transient response of a system is directly related to the s-plane locations of the poles and zeros.
Example of how to find roots of characteristics eq. is shown below:
Multiplication of polynomials is accomplished with the conv function. Suppose we want to expand the
polynomial n(s), where
The associated MATLAB commands using the conv function are as below:
Using MATLAB, we can plot the location of the pole-zero using command as below:
We can also plot the pole-zero for the transfer function of G(s)/H(s) by using script as below:
The result is shown below
II. ASSIGNMENT
A. Introduction to MATLAB
1. Matrices Generation
Generate matrices A, B, and C with size of 1 x 2, 2 x 2, 2 x 3, by using MATLAB. The values of the
matrices are up to you. Write down the commands and the execution results for your short
discussion.
2. Plot a curve of function y = x.sin(x) with range of x values from 0 to 1.0. Plot also a curve of y = sin(x).
Plot these function in single figure.
3. Given data in excel (provided by teacher), plot the data by using MATLAB with script as below:
data=xlsread('Data_prakt.xlsx');
x=data(:,1);
y1=data(:,2);
y2=data(:,3);
y3=data(:,4);
% PLOT KETERANGAN AKSIS
yyaxis left
%title('Plots with Different y-Scales')
xlabel('Time (s)')
ylabel('Power to flow ratio')
yyaxis right
ylabel('Steam temperature (^oC)')
% PLOT DATA
hold on
yyaxis left
plot(x,y1);
plot(x,y2);
yyaxis right
plot(x,y3);
hold off
B. System Modeling
1. Spring-mass-damper unforced response
Based on Fig. 8 and its model, shown the system’s response by typing the following script.
Execute and observed the results for discussion in your report.
2. Pole-Zero
Given transfer functions as below:
Plot the pole-zero location of the transfer function G(s)/H(s) by typing the script below:
Using the same way, plot the pole-zero location for the transfer function of each G(s) and H(s).