COMPUTER AIDED ANALYSIS AND MODELLING Lectures

Download as pdf or txt
Download as pdf or txt
You are on page 1of 41

Department of Mechanical Engineering

ME 581 COMPUTER AIDED ANALYSIS AND MODELLING


Credit: 3

PG – YEAR ONE, SEMESTER ONE

DR. R. OPOKU
INTRODUCTION
The aim of this course is to introduce students to:
• numerical methods as well as acquire practical skills in the use of
computer to model and solve mechanical engineering problems.

• the course will focus on the use of available tools such as: MATLAB,
MathCAD, etc. to solve mechanical engineering problems.

The topics will include modeling of mechanical systems and numerical


solutions of:
• linear and non-linear equations
• algebraic equations and
• ordinary and partial differential equations with initial and boundary
conditions/values.
Monday, September 2, 2019 ME 581 COMPUTER AIDED ANALYSIS & MODELING
1
Course Objectives
After studying this course, the students will be able to:

• Understand the use of physical laws to model mechanical


systems

• Appreciate the use of mathematical models to represent


the behaviour of mechanical systems.

• Understand the use of numerical tools and computer to


analyse the behaviour of mechanical systems
Monday, September 2, 2019 ME 581 COMPUTER AIDED ANALYSIS & MODELING
2
Course Assessment
• The assessment for this course shall be as follows:

Assessment Qty Mark


Quizzes - -
Assignments 2 20 %
POW - -
Mid-semester exams 1 20 %
Final exams 1 60 %
Total 10 100 %

• Pass mark is 50%

Monday, September 2, 2019 ME 581 COMPUTER AIDED ANALYSIS & MODELING


3
Outline of ME 581 Course
• Introduction to MATLab (creating m-file and writing some
MatLab syntaxes )

• Numerical Methods (Finite Difference Methods)

• Mathematical Modeling & Analysis of Mechanical Systems


(liquid-level systems, thermal systems, mass-spring systems,
etc)

• Discrete Models of Control Systems (open loop and closed


loop/feedback control systems; PID control systems, etc)
Monday, September 2, 2019 ME 581 COMPUTER AIDED ANALYSIS & MODELING
4
Introduction to MATLab – A Computational Tool for
Solving Engineering Problems
• MATLAB is a matrix-based system for performing mathematical
and engineering calculations.
• MATLAB is a language of technical computing. All variables
handled in MATLAB are matrices.
• That is, MATLAB has only one data type: a matrix or a
rectangular array of numbers.
• MATLAB has an extensive set of routines for obtaining graphical
outputs.
• MATLAB is used with a variety of toolboxes (a toolbox is a
collection of special files called M-files) to solve mathematical
problems.
• We shall now learn some basic MATLAB syntaxes.

Monday, September 2, 2019 ME 581 COMPUTER AIDED ANALYSIS & MODELING


5
MATLAB Command Meaning
Some MATLAB Syntaxes/Commands
clear Clear workspace
clf Clear current figure.
computer Type of computer
c2d Conversion of continuous-time models to discrete-time models
abs Absolute values, complex magnitude
det Determinant
diag Diagonal matrix
eig Eigenvalues and eigenvectors
exp Exponential base e
eye Identity matrix
grid on Adds major grid lines to the current axes
legend Graph legend
length Length of vector
linspace Linearly spaced vector
log10 Log base 10
xlabel x-axis label
ylabel y-axis label
zeros Zeros array
Monday, September 2, 2019 ME 581 COMPUTER AIDED ANALYSIS & MODELING
6
Some MATLAB Syntaxes/Commands -continued

MATLAB Command Meaning


max Maximum value
mean Mean value
median Median value
mesh Three-dimensional mesh surface
meshgrid X and Y arrays for three dimensional plots
min Minimum value
minreal Minimal realization and pole-zero cancellation
ode45 Solve nonstiff differential equations, medium-order method
ode23 Solve nonstiff differential equations, low-order method
ode113 Solve nonstiff differential equations, variable-order method
ord2 Generates continuous-time second-order system
who Lists all the variables currently in memory
whos List all the variables in the current workspace, together with
information about their size, bytes, class, etc.
Monday, September 2, 2019 ME 581 COMPUTER AIDED ANALYSIS & MODELING
7
MATLAB Command Meaning
Some MATLAB Syntaxes/Commands
pi Pi (π)
plot Linear x-y plot
polar Polar plot
poly Convert roots to polynomials
polyfit Polynomial curve fitting
polyval Polynomial evaluation
polyvalm Matrix polynomial evaluation
printsys Print system in pretty format
prod Product of elements
pzmap Pole-zero map of LTI models
quit Terminate program
-continued

rand Generate random numbers and matrices


rank Calculate the rank of a matrix
real Real part
rem Remainder or modulus
residue Partial-fraction expansion
roots Polynomial roots
Monday, September 2, 2019 ME 581 COMPUTER AIDED ANALYSIS & MODELING
8
Some MATLAB Syntaxes/Commands -continued

MATLAB Command Meaning


size Size of matrix
sqrt Square root
sqrtm Matrix square root
std Standard deviation
step Plot unit-step response
subplot Create axes in tiled positions
sum Sum of elements
switch Switch among several cases based on expression

Monday, September 2, 2019 ME 581 COMPUTER AIDED ANALYSIS & MODELING


9
• To write Greek letters, such as α, β, γ, δ, ω, or ξ, use ̒ \ character̓. See below.
α = \alpha θ= \theta
β = \beta ξ= \zeta
γ = \ gamma Δ = \Delta
δ = \delta ϴ = \Theta
ω = \omega ∑ = \Sigma
σ = \sigma Ω = Omega

̒
• Subscripts can be obtained by using underscore symbol ̒̒ ̒_̓ ̓. For example,
y_1 generates y1
y_2 generates y2
Superscripts can be generated by using ̒̒ ̒^ ̓ ̓. For example,
x^2 generates x2
• x^3 generates x3
Monday, September 2, 2019 ME 581 COMPUTER AIDED ANALYSIS & MODELING
10
Some Rational and Logical Operators in MATLAB
< Less than
< = Less than or equal
> Greater than
> = Greater than or equal
= = Equal
~ = Not equal
The logical operators are
& AND
| OR
~ NOT

Monday, September 2, 2019 ME 581 COMPUTER AIDED ANALYSIS & MODELING


11
Special Characters
The following special characters are used in MATLAB:
[] Used to form vectors and matrices
() Arithmetic expression precedence
, Separate subscripts and function arguments
; End rows, suppress printing
: Subscripting, vector generation
! Execute operating system command
% To make comment for others to understand your code

Use of colon. The colon plays an important role in MATLAB, being involved in creating
vectors, subscripting matrices and specifying iterations. For example, the statement t = 1:5
• generates a row vector containing the numbers from 1 to 5 with unit increment-that is, t
=1 2 3 4 5

• Note that matrices in MATALB are of order (rows, columns);


• Eg, A(5,3) is matrix A with 5 rows, 3 columns
Monday, September 2, 2019 ME 581 COMPUTER AIDED ANALYSIS & MODELING
12
• An increment other than unity can be used. For example, t = 1:0.5:3 will result in
t = 1.0000 1.5000 2.0000 2.5000 3.0000

• Negative increments may be used. For example, the statement


t = 5:-1.2 gives t=5 4 3 2

• The colon is frequently used to subscript matrices. A(:,j) is the jth column of A and A(i,:) is
the ith row of A. For example, if matrix A is given by
1 2 3
• 𝐴= 4 5 6
7 8 9
• the A(:,3) gives the third element in all of the rows (i.e., the third column), as follows:
3
6
9
• A(2,:) gives the second row of A, namely,
4 5 6
Monday, September 2, 2019 ME 581 COMPUTER AIDED ANALYSIS & MODELING
13
• x = linspace(min,max,increment)
• Example: x = linspace(-10,10,5) will give
x = -10 -5 0 5 10

• Array division. The expressions x./y, x.\y, and A./B, gives the
quotients of the individual elements. Thus for
• x = [1 2 3], y = [4 5 6]

the statement u = x./y


Gives u = [0.25 0.4 0.5]

and the statement v = x.\y


• results in v = [4 2.5 2]
Monday, September 2, 2019 ME 581 COMPUTER AIDED ANALYSIS & MODELING
14
• Transpose and conjugate transpose. The apostrophe or prime
denotes the conjugate transpose of a matrix. If the matrix is real,
the conjugate transpose is simply the transpose. An entry such as
A = [1 2 3; 4 5 6; 7 8 9] will produce the following
matrix on the screen:
A=
1 2 3
4 5 6
7 8 9
• Also, if B = A' is entered, then
B=
1 4 7
2 5 8
3 6 9
Monday, September 2, 2019
appears ME
on the screen.
581 COMPUTER AIDED ANALYSIS & MODELING
15
• Entering complex numbers. Complex numbers may be entered using the function i or j.
For example, a number 1 + 𝑗 3 may be entered as
• x = 1+sqrt(3)*i or x = 1+sqrt(3)*j
• Entering complex matrices. For the complex matrix
1 𝑗
𝑋=
−𝑗5 2
• An entry like X = [1 j; -5*j 2] will produce the following matrix on the screen:
X=
1.0000 0 + 1.0000i
0 – 5.0000i 2.0000

• Note that Y = X‘ will yield


• Y=
• 1.0000 0 + 5.0000i
• 0 – 1.0000i 2.0000
which is
1 𝑗5
• 𝑌=
−𝑗 2

Monday, September 2, 2019 ME 581 COMPUTER AIDED ANALYSIS & MODELING


16
Writing Polynomials in Matlab
• Consider a polynomial function P = s3 + 6s2 + 11s + 6.
• Note that polynomials are represented as row vectors containing the
polynomial coefficients in descending order, that is , in the present
example, P = [1 6 11 6]

• The roots of the characteristic equation p = 0 can be obtained by


entering the command r = roots(p):
• The roots are s = -3, s = -2, and s = -1.

• The roots of the characteristic equation may be reassembled back into


the original polynomial with the command q = poly(r).

• For r = [-3 -2 -1], poly(r) will produce the polynomial equation: s3 + 6s2
+ 11s + 6 = 0

Monday, September 2, 2019 ME 581 COMPUTER AIDED ANALYSIS & MODELING


17
• Convolution (product of polynomials). Consider the
polynomials:
• 𝑎 𝑠 = 3𝑠 4 + 10𝑠 3 + 25𝑠 2 + 36𝑠 + 50
• 𝑏 𝑠 = 𝑠 2 + 2𝑠 + 10
• The product of the polynomials is the convolution of the
coefficients. The product of a(s) and b(s) can be obtained by
entering the command c = conv(a,b).

• Deconvolution (divisions of polynomials). To divide the


polynomial a(s) by b(s), use the deconvolution command
[q,r] = deconv(a,b)

Monday, September 2, 2019 ME 581 COMPUTER AIDED ANALYSIS & MODELING


18
The following MATLAB output is illustrative:

>>a = [3 10 25 36 50];
>>b = [1 2 10];
>>% Define the quotient and remainder of a/b as q and r, respectively.
>>[q,r] = deconv (a, b)
q=
3 4 -13
r=
0 0 0 22 180

Monday, September 2, 2019 ME 581 COMPUTER AIDED ANALYSIS & MODELING


19
Evaluating a polynomial at a given point

• Polynomial evaluation. If p is a vector whose element are


the coefficient of a polynomial in descending powers ,
then the polyval(p,s) is the value of the polynomial,
evaluated at s. For example, to evaluate the polynomial
• p(s) = 3s2 + 2s +1 at s = 5, enter the command p = [3 2
1];
• polyval(p,5).

Monday, September 2, 2019 ME 581 COMPUTER AIDED ANALYSIS & MODELING


20
Plotting in Matlab
As another example, let us plot the graph of y = x2
Over the interval 0≤ x ≤ 3 with increment of 0.1. MATLAB Program D-1
plots this graph.

MATLAB Program D-1


>> x = 0:0.1:3;
>> y = x. ^2;
>> plot(x,y)
>> grid on
>>title('Plot of y = x^2', 'Fontsize',20, 'Fontangle', 'italic')
>> xlabel('x', 'Fontsize',20, 'Fontangle', 'italic'
>> ylabel('y', 'Fontsize',20, 'Fontangle', 'italic'

Monday, September 2, 2019 ME 581 COMPUTER AIDED ANALYSIS & MODELING


21
Please write out any important Matlab syntaxes that you have learned that can help
you analyse data collected from your research experiment.
• Example; finding the minimum, maximum, • Example; plotting your data, finding the best fit
mean, etc of your data set: polynomial function and forecasting:

Monday, September 2, 2019 ME 581 COMPUTER AIDED ANALYSIS & MODELING


22
•End of Lecture 1

Monday, September 2, 2019 ME 581 COMPUTER AIDED ANALYSIS & MODELING


23
Mathematical Modeling of Mechanical Systems
• The behaviour of an engineering system (being it mechanical,
electrical, chemical, etc) can be studied and modeled using
analytical-differential equations or empirical correlations.

• The behaviour of the system can then be predicted by


numerically solving its governing equation with the necessary
input parameters and boundary conditions.

• The mathematical models that describe the system can be


classified as either: boundary-value, initial-value or eigenvalue
models.
• In many engineering systems, we encounter models that are
both boundary-value and initial-value. The response of such
system is made of the steady solution and the transient solution
Monday, September 2, 2019 ME 581 COMPUTER AIDED ANALYSIS & MODELING
24
Mathematical Modeling of Fluid-Flow Systems
(Example: Simple Liquid-Level Systems)

In the analysis of fluid flow, you will need to first identify the type of
flow as either laminar flow or turbulent flow, by determining the Re #.
Monday, September 2, 2019 ME 581 COMPUTER AIDED ANALYSIS & MODELING
25
Laminar vs Turbulent Flow
• Laminar Flow
• Flow dominated by viscous
forces is called laminar flow
and is characterized by a
smooth, parallel line motion
of the fluid

• Turbulent Flow
• When inertia forces
dominate, the flow is called
turbulent and it is
characterized by an
irregular motion of the fluid.

Monday, September 2, 2019 ME 581 COMPUTER AIDED ANALYSIS & MODELING


26
Resistance of Liquid-Level Systems
• Consider the flow through a short pipe
connecting two tanks as shown in Figure.

• Where H1 is the height (or level) of first tank, H2 is


the height of second tank, R is the resistance in
flow of liquid and Q is the flow rate.
Monday, September 2, 2019 ME 581 COMPUTER AIDED ANALYSIS & MODELING
27
Resistance of Liquid-Level Systems
• The resistance for liquid flow in such a pipe is defined as
the change in the level difference necessary to cause a
unit change in flow rate.

change inlevel difference m


Resistance   3
change inflow rate m /s

( H1  H 2 ) dH  m s 
R  ; units  3  2 
Q dQ m / s m 
Monday, September 2, 2019 ME 581 COMPUTER AIDED ANALYSIS & MODELING
28
Resistance in Laminar Flow • Reading assignment: find the resistance if the
flow was turbulent.
• For laminar flow, the relationship
between the steady-state flow rate
and steady state height at the
restriction is given by: Q  k H
l

• Where Q = steady-state liquid flow


rate in m3/s
• Kl = constant in m2/s
• and H = steady-state height in m.

dH 1 H
• The resistance Rl is: Rl   
dQ K l Q
Monday, September 2, 2019 ME 581 COMPUTER AIDED ANALYSIS & MODELING
29
Capacitance of Liquid-Level Systems
• The capacitance of a tank is defined to be the • Reading assignment: Write out the equation to
change in quantity of stored liquid necessary to determine the capacitance of a conic tank.
cause a unity change in the height.

change inliquid stored m 3


Capacitance   or m 2
change inheight m

dV d ( A h) A dh  h dA
C  
dh dh dh
• Note that for uniform cross-section, the
Capacitance (C) is the cross sectional area (A) of
the tank.

Monday, September 2, 2019 ME 581 COMPUTER AIDED ANALYSIS & MODELING


30
Capacitance of Liquid-Level Systems - continued

Rate of change of fluid volume in the tank  flow in  flow out


dV
 qi  qo
dt
d ( A  h)
 qi  qo
dt
Monday, September 2, 2019 ME 581 COMPUTER AIDED ANALYSIS & MODELING
31
Capacitance of Liquid-Level Systems - continued
• Equation 1A is a simple differential
equation of 1st order and can be
written numerically using forward finite
difference scheme.
h
• Please write the forward finite
difference scheme for equation 1A
below:
dh
A  qi  qo
dt

• The mathematical expression/model for


the simple liquid-level system is therefore
presented as equation 1A
dh
C  qi  qo ...................( Eqn 1A)
dt
Monday, September 2, 2019 ME 581 COMPUTER AIDED ANALYSIS & MODELING
32
Modelling Example #1, disturbance from steady state conditions

Monday, September 2, 2019 ME 581 COMPUTER AIDED ANALYSIS & MODELING


33
Modelling Example #1
• The rate of change in liquid stored in the tank is equal to the inflow
minus outflow.
dh
C  (Q  qi )  (Q  qo )  qi  qo (1)
dt
• The resistance R may be written in respect of the outflow as
dH H h
R   (2)
dQ Q q0
• Rearranging equation (2)
h
q0  (3)
R

Monday, September 2, 2019 ME 581 COMPUTER AIDED ANALYSIS & MODELING


34
Modelling Example#1
dh h
C  qi  qo (1) q0  (4)
dt R

• Substitute qo in equation (3)

dh h
C  qi 
dt R
• After simplifying above equation

dh
RC  h  Rqi .............(1B)
dt
• Equation 1B can be solved numerically to obtain the system response (h)
• Note that RC is the time constant of the system
Monday, September 2, 2019 ME 581 COMPUTER AIDED ANALYSIS & MODELING
35
Tutorial
• A relay tank used at an oil processing company which
has diameter 4 meters and height 8 meters maintains a
steady liquid level of 6.5 meters at a flow rate of 20 cubic
meter per second. Find the change in the liquid level if
the inlet flow valve is adjusted such that the flow rate
increases in the following cases: by 10%, 20%, 30% and
40%; whilst the outflow valve is still kept at its position.
Assume the flow is laminar.

Monday, September 2, 2019 ME 581 COMPUTER AIDED ANALYSIS & MODELING


36
Solution • The model equation for the liquid level system is:
dh
RC  h  Rqi
dt
• The laminar flow resistance is Rl 
dH

1

H 6.5
  0.325
dQ K l Q 20

• Capacitance (C)=cross-sectional area= C


pi * D 2 3.142 * 4 2
  12.568
4 4

• The model equation is: dh


4.085  h  0.325qi
dt
h(i  1)  h(i )
4.085  h(i )  0.325qi
t
0.325qi  h(i )
h(i  1)  * t  h(i )
4.085
Monday, September 2, 2019 ME 581 COMPUTER AIDED ANALYSIS & MODELING
37
The finite forward difference equation can be solved in MATLab with the code:

• function Example1_liquid_level_laminar_flow • for q_in=0.1*Q_in:0.1*Q_in:0.4*Q_in; % increasing from


10% to 40% of flow rate
• clear all % this clears the memory when ever you re-
run the code • for i=1:iter_max %this is a a loop
• clc %this clears the solution baoard • t(i+1)=t(i)+dt;

• clf % this clears the chart for replotting the figure • h(i+1)=0.245*(0.325*q_in-h(i))*dt+h(i);
when you re-run code • end
• Q_in=20; %mass flow rate of 20 kg/s • hold all
• h(1)=0;% initial change in height from the steady • plot(t/60,h,'*-','LineWidth',3)
height • xlabel('time [minutes]')
• tmax=1*60; % time duration in seconds • ylabel('change in liquid level [meters]')
• dt=1; %time step • title('Change in Liquid-level versus time')
• t=0; %initialize • grid on
• iter_max=tmax/dt; • end
• legend('10% increment','20% increment','30%
increment','40% increment')
Monday, September 2, 2019 ME 581 COMPUTER AIDED ANALYSIS & MODELING
38
Solution Plot with MATLab
Change in Liquid-level versus time
3

2.5 10% increment


20% increment
change in liquid level [meters] 30% increment
40% increment
2

1.5

0.5

0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
time [minutes]
Monday, September 2, 2019 ME 581 COMPUTER AIDED ANALYSIS & MODELING
39
• End of Lecture 2

For any concerns, please contact me


[email protected]
(0240660955 / 0501057157)

Monday, September 2, 2019 ME 581 COMPUTER AIDED ANALYSIS & MODELING


40

You might also like