You are on page 1of 17

Mechanics with Matlab

April 2001

The MechMat project has been carried out with the support of the Commission of
the European Communities under the Leonardo da Vinci programme (contract number
CZ/98/1/82500/PI/I.1.1.b/FPI).
2

Prof. V. Stejskal
Project coordinator
Czech Technical University
Karlovo nam. 13
CZ-12135 Praha
Czech Republic
stejskal@vc.cvut.cz

Prof. P. Dehombreux
Facult Polytechnique de Mons
Belgium
pierre.dehombreux@fpms.ac.be

Prof. A. Eiber
University of Stuttgart
Germany
ae@mechb.uni-stuttgart.de

Prof. R. Gupta
Uppsala University
Sweden
ram.gupta@material.uu.se

Prof. M. Okhroulik
Czech Academy of Sciences
Czech Republic
ok@it.cas.cz
Contents

1 The MechMat Project 4


1.1 Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.2 How to use this document . . . . . . . . . . . . . . . . . . . . . . . 5
1.3 Modelling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
1.4 M ATLAB basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.4.1 Basic calculations . . . . . . . . . . . . . . . . . . . . . . . 9
1.4.2 Solving linear algebra problems with M ATLAB . . . . . . . 13
1.4.3 Plotting data in M ATLAB . . . . . . . . . . . . . . . . . . 14
1.4.4 Other useful M ATLAB commands . . . . . . . . . . . . . . 14

2 Kinematics 16
2.1 Basic Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
2.2 Kinematics of a particle. Rectilinear and curvilinear motion . . . . . 16
2.2.1 Position vector. Velocity vector. Acceleration vector . . . . 16
2.2.2 Average and instantaneous velocities . . . . . . . . . . . . 17
2.2.3 Average and instantaneous acceleration . . . . . . . . . . . 17
2.2.4 Absolute frame . . . . . . . . . . . . . . . . . . . . . . . . 18
2.2.5 Tangential and normal coordinates . . . . . . . . . . . . . . 18
2.2.6 Rotation around a fixed point in a plane . . . . . . . . . . . 22
2.3 Kinematics of a rigid body . . . . . . . . . . . . . . . . . . . . . . 23
2.3.1 Translation . . . . . . . . . . . . . . . . . . . . . . . . . . 23
2.3.2 Rotation about a fixed axis . . . . . . . . . . . . . . . . . . 24
2.3.3 Particular case: Motion in plane . . . . . . . . . . . . . . . 25
2.3.4 General motion in space . . . . . . . . . . . . . . . . . . . 29
2.3.5 Rolling without slipping . . . . . . . . . . . . . . . . . . . 31
2.4 Kinematics of systems of rigid bodies . . . . . . . . . . . . . . . . 32
2.4.1 Mechanism . . . . . . . . . . . . . . . . . . . . . . . . . . 32
2.4.2 Degrees of freedom . . . . . . . . . . . . . . . . . . . . . . 32
2.4.3 Lower pairs and higher pairs . . . . . . . . . . . . . . . . . 33
2.4.4 Kinematics exercises . . . . . . . . . . . . . . . . . . . . . 35

1
CONTENTS 2

3 Statics 61
3.1 Basic Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
3.1.1 Force . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
3.1.2 Moment of a force about a point . . . . . . . . . . . . . . . 63
3.2 Moment of a force about an axis . . . . . . . . . . . . . . . . . . 65
3.2.1 Couples of forces . . . . . . . . . . . . . . . . . . . . . . . 71
3.2.2 Principle of transmissibility . . . . . . . . . . . . . . . . . 72
3.2.3 Force systems . . . . . . . . . . . . . . . . . . . . . . . . . 72
3.2.4 Equivalence of two systems of forces . . . . . . . . . . . . 73
3.2.5 Equilibrium of force systems . . . . . . . . . . . . . . . . . 74
3.3 Equilibrium of a particle . . . . . . . . . . . . . . . . . . . . . . . 76
3.4 Equilibrium of a rigid body in a plane . . . . . . . . . . . . . . . . 83
3.5 Equilibrium of a rigid body in space . . . . . . . . . . . . . . . . . 88
3.6 Systems of rigid bodies . . . . . . . . . . . . . . . . . . . . . . . . 93
3.7 Trusses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
3.8 Bodies and systems of bodies with friction . . . . . . . . . . . . . . 104
3.8.1 Journal bearing . . . . . . . . . . . . . . . . . . . . . . . . 105
3.8.2 Thrust bearing . . . . . . . . . . . . . . . . . . . . . . . . 105
3.8.3 Rolling resistance . . . . . . . . . . . . . . . . . . . . . . . 106
3.8.4 Belt friction . . . . . . . . . . . . . . . . . . . . . . . . . . 106
3.9 Centre of gravity . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
3.10 Internal forces in a body . . . . . . . . . . . . . . . . . . . . . . . 116
3.11 Work and potential energy . . . . . . . . . . . . . . . . . . . . . . 121
3.12 Principle of virtual work . . . . . . . . . . . . . . . . . . . . . . . 128
3.13 Solutions of exercises . . . . . . . . . . . . . . . . . . . . . . . . . 132

4 Dynamics 190
4.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
4.1.1 Issues of applied dynamics . . . . . . . . . . . . . . . . . . 191
4.1.2 Modelling of Mechanical Systems . . . . . . . . . . . . . . 194
4.2 Mechanical Modelling . . . . . . . . . . . . . . . . . . . . . . . . 196
4.2.1 Elements of Multibody Systems . . . . . . . . . . . . . . . 197
4.2.2 System forces . . . . . . . . . . . . . . . . . . . . . . . . . 197
4.2.3 Kinematical constraints . . . . . . . . . . . . . . . . . . . . 199
4.3 Mathematical modelling . . . . . . . . . . . . . . . . . . . . . . . 204
4.3.1 Introduction to mathematical modelling . . . . . . . . . . . 204
4.3.2 Mathematical models and procedures . . . . . . . . . . . . 212
4.3.3 Formulation of governing equations of mechanical systems . 214
4.4 Application of Computational Procedures in Dynamic Analysis (draft
version of the chapter) . . . . . . . . . . . . . . . . . . . . . . . . 232
4.4.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . 232
CONTENTS 3

4.4.2 Dynamics of robot . . . . . . . . . . . . . . . . . . . . . . 245


4.4.3 Dynamics of slider-crank mechanism . . . . . . . . . . . . 269

5 Vibrations 301
5.1 Introduction to vibration . . . . . . . . . . . . . . . . . . . . . . . 301
5.2 Harmonic and periodic motions . . . . . . . . . . . . . . . . . . . . 302
5.3 Phase and group velocities . . . . . . . . . . . . . . . . . . . . . . 310
5.4 Fourier series . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315
5.5 Fourier integral . . . . . . . . . . . . . . . . . . . . . . . . . . . . 321
5.6 Discrete Fourier series . . . . . . . . . . . . . . . . . . . . . . . . 329
5.7 Deriving governing equations . . . . . . . . . . . . . . . . . . . . . 332
5.8 Numerical methods . . . . . . . . . . . . . . . . . . . . . . . . . . 332
5.8.1 Numerical methods for steady state vibration
problems . . . . . . . . . . . . . . . . . . . . . . . . . . . 332
5.8.2 Numerical methods for transient problems . . . . . . . . . . 337
5.9 Vibration with 1 DOF . . . . . . . . . . . . . . . . . . . . . . . . . 345
5.9.1 Undamped free linear vibration of a one-degree-of-freedom
system . . . . . . . . . . . . . . . . . . . . . . . . . . . . 345
5.9.2 Undamped forced linear vibration of
a one-degree-of-freedom system . . . . . . . . . . . . . . . 348
5.9.3 Damped linear vibration of a one-degree-of-freedom sys-
tem with a harmonic excitation force . . . . . . . . . . . . 351
5.9.4 Overdamped, critically damped and underdamped linear vi-
brations of a one-degree-of-freedom system . . . . . . . . . 357
5.9.5 A vibrating system attached to a moving support . . . . . . 361
5.9.6 Behaviour of a one-degree-of-freedom linear system at res-
onance . . . . . . . . . . . . . . . . . . . . . . . . . . . . 365
5.9.7 Vibration with Coulomb friction . . . . . . . . . . . . . . . 369
5.10 Systems with 2 DOF . . . . . . . . . . . . . . . . . . . . . . . . . 373
5.10.1 Undamped free and forced vibrations of a two-degrees-of-
freedom linear system . . . . . . . . . . . . . . . . . . . . 373
5.10.2 Comparison of analytical and numerical approaches to the
solution of the transient response of a two-degrees-of-freedom
linear system . . . . . . . . . . . . . . . . . . . . . . . . . 386
5.11 Systems with n DOF . . . . . . . . . . . . . . . . . . . . . . . . . 394
5.11.1 Vibration of a linear system with n degrees of freedom . . . 394
5.12 Continuous systems and their discretizations . . . . . . . . . . . . . 401
5.12.1 Bars . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 401
5.12.2 Beams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 462
Chapter 1

The MechMat Project

1.1 Objectives
Although the basic concepts and laws of mechanics are known for centuries, radical
changes occurred in techniques of application of these concepts in technical practice
during the last decades. These new, up-to-date approaches, allowing to solve com-
plicated technical problems with strong non-linearities, are efficiently implemented
on powerful computer platforms in forms of widely available commercial software
packages. Both HW and SW resources are easily accessible at universities as well
as in industrial sites.
These changes significantly influence the demands of employers on employ-
ees. Tough competition calls for designers who are able to use computer tools
extensively and efficiently for securing the production and frequent modification of
cheap and reliable products able to survive on the market. Many engineers on the
labour market, however, have finished their studies in times when computers were
not so frequent and methods of computational mechanics were virtually unknown
and thus were not covered by their curricula. This, together with a natural pro-
cess of forgettery, results in insufficiency of skills in training of basic principles of
mechanics in engineering community. The profound idea of liberation of designers
from routine and cumbersome computations leading to their creativity can be hardly
accomplished under the present unfavourable conditions.
The presented electronic learning tool (ELT) is a response to the fact that the
increasing availability of computers in engineering community is not always fully
accompanied by proper knowledge of numerical and programming techniques re-
quired to employ efficiently the principles of mechanics. These, in turn, are needed
for finding the sought-after results concerning the response of a mechanical system
to external loading.
The presented ELT is not a textbook in a traditional sense of the word. Its main
concept is based on new methodology of presentation called "learning by action"

4
CHAPTER 1. THE MECHMAT PROJECT 5

which means that its user (reader, learner) is expected to learn by working out nu-
merous case studies based on real problems of technical practice by himself/herself.
The modern personal computers are fully suited to the purpose. The learner
has an immediate access to reviews of basic principles and to the high-performance
numeric computation and visualisation software at the same time. Moreover, he/she
is supplied by correct numerical solutions of the numerous problem by means of
simple computer procedures.
The ELT is based on very common hardware. Any PC or Unix machine con-
nected to the internet will allow for downloading the text and computer programs.
The local Matlab installation then will permit running and modifying the worked-
out examples. The Matlab version 5.3 was used.
Matlab was used for its wide spread availability and for its ability to deal effi-
ciently with matrix algebra mathematics.
The main aim of the proposed ELT is to increase the horizons of young people
in initial training and to help designers in practice in their lifelong training to master
the basic principles of computational mechanics and their application to the practi-
cal engineering problems. This will facilitate the starts of their professional careers
and will improve their position on the labour market.
The specific objective of the ELT is to improve the knowledge and skills level
of the mechanical and civil engineering university students and practising engineers
in one of the most important basic subject of engineering which is the science of
mechanics. This knowledge and skills can be used in nearly all branches of industry.
The international co-operation in the preparation of the project secures that the
choice of practical problems to solve meets the demands of numerous engineers.
The common experience of university teachers of mechanics from different Euro-
pean countries contributes to the European level of knowledge in this particular
field.
The following impact on training is expected:

 improvement of the training level of initial training

 improvement of the ability of students to solve challenging problems them-


selves

 improvement of the students ability to use a computer as a tool for solution of


their everyday problems.

1.2 How to use this document


It has been said that this document is not a textbook in the traditional sense at all.
It is designed to supplement standard texts and to assist students of engineering
CHAPTER 1. THE MECHMAT PROJECT 6

science to get proficiency in engineering mechanics which is very often claimed to


be very difficult subject. The autors are convicted that numerous solved problems
is the best way for belief that student knows the principles and he is able to apply
them when solving problems taken from technical practice. This, of course, leads
to self-confidence.
The material presented here corresponds to standard introductory mechanics
courses but does not match any particular textbook. So any standard textbook of
mechanics (see references) can be used. Each chapter, however, begins with def-
initions, statements, principles, and theorems without pretence to be complete. A
glossary of common terms was included at the end of the text for students conve-
nience.
One of the main aims of the text is not to finish solution of problems by writting
down equations of equilibrium, equations of motion or kinematic equations without
solving them. At the end of engineering solution should stand a number. Very
often the numerical result proofs validity of the solution. But numerous of practical
problems are not so simple to allow for analytical solution. So a tool for numerical
computation is needed. The autors select M ATLAB for the purpose. The reason is
its versatility, easy use, and good graphical capabilities. Last but not least M ATLAB
is in common use within nearly all universities.
The text is designed for students who study or have studied mechanics to help
them to master the subject. The standard use is to study material displayed and
to try solve examples presented by oneself. In case of difficulties the solution can
be consult. There are M ATLAB m-files ready and by playing with constants and
modifying programs student is able to discover the base of the problem. Using
Windows capabilities it is convenient to open a window of text and another window
for M ATLAB simultaneously. Commnets in m-files can be very helpful.
The autors hope that solved problems help the students to illustrate the theory,
present methods of solution and enable them to apply the basic principles of me-
chanics correctly and confidently.

1.3 Modelling
The phenomena of nature are inherently complex and it is impossible to consider
their every detail when trying to describe, formulate and predict their future be-
haviour or occurrence. Always certain simplifications have to be accepted. The
idea behind modelling is to neglect what seems to have a negligible or small influ-
ence on what is to be grasped. Accepting simplifying assumptions, however, leads
to limited validity of models.
Engineering modelling is well defined within the scope of Newtonian physics
that admits the notion of inertial frame of reference and the notion of absolute time
CHAPTER 1. THE MECHMAT PROJECT 7

independent of space.
The Newtonian description is unchanged under a Galileo transformation which
is a mathematical device relating a single phenomenon recorded by two observers
whose frame of reference differ by virtue of their travelling at different uniform ve-
locities. According to Newtons concept, while the position of two observers differ
by virtue of their relative motion, both have an identical perception of time, which
does not depend on the frame of their reference. Newtonian mechanics provides
a vital tool, which still perfectly works in all manners of ways from the motion
of billiard balls or galaxy formation. The Newtonian concept is deterministic. If
positions, velocities and masses of various bodies are given at one time, then their
positions, velocities and accelerations are mathematically determined for all later
times. And for earlier as well.
Mechanics is the branch of physics concerned with the analysis of behaviour of
objects under the action of forces. Historically the subject dealt with rigid bodies
only, since then it is extended and applied to problems of solid and fluid continuum.
In the latter scope it is sometimes called classical mechanics as a contrast to quan-
tum mechanics. Continuum mechanics is concerned with formulation of equations
describing the motion and mechanical and thermal behavior of matter and with the
solution of these equations for prescribed initial and boundary conditions. Usually
solid and fluid continua are being distinguished and treated by somewhat different
approaches. In the text we will devote our attention to solid mechanics.
Very often mechanical structure can be modelled by a systems having finite
number of degrees of freedom. In such a case we talk about discrete mechanical
models.
Bodies we are dealing with could be considered rigid or deformable. Rigid body,
within the scope of solid continuum, is a model characterized by infinite stiffness
of matter. By definition a rigid body perfectly resists deformation due to the action
of forces, as such it cannot be deformed.
Deformable body is a body (mechanical system, structure) which deforms under
the action of an applied force. Within the scope of solid continuum it is a model
characterized by a proper constitutive relation between force and displacement, and
stress and strain.
Very often we simplify the modelling process by accepting assumptions of lin-
earity. If all basic components of a system behave linearly, the response of the
system is known as linear. This means that there is a linear relation between dis-
placements and forces, velocities and damping forces, etc. Linear systems are based
on assumptions of small strains and small displacements. Equations of equilibrium
are written for an undeformed configuration of the structure and the principle of
superposition can safely be used. The resulting system of differential equations is
of linear nature as well. On the other hand if any of the basic components behave
nonlinearly, the system is nonlinear.
CHAPTER 1. THE MECHMAT PROJECT 8

The modelling process in engineering usually proceeds in following steps.


Setting the mechanical model. The most engineering systems are complex, it
is impossible to consider every detail of them and so certain simplifications have to
be accepted. Model can be viewed as an idealization of a real or conceived machine
or structure obtained by accepting certain simplifying assumptions. We accept the
validity of Newtonian mechanics as far as the inertia frames of references are con-
cerned and thus do not deal with principles of relativity. We accept the assumptions
upon which the continuum mechanics is based, i.e., that the matter, when divided
into infinitesimal elements, has always the same mechanical properties that are in-
dependent of their size - by other words we do not deal with molecular and atomic
structure of the matter. Considered bodies or structures could be smooth or rough,
material properties could be taken as homogeneous or non-homogeneous, isotropic
or unisotropic, linear or non-linear, constraints and loading could be simplified, etc.
Very often it is expedient to model a part of the structure under consideration as
fully rigid and to neglect inertia effects of flexible parts. All together, it is a tricky
procedure and what is adequate for one purpose may not be adequate for other pur-
poses.
Derivation of governing equations. Once the mechanical model is established
we use principles of mechanics and derive the equations of motion or the equations
of equilibrium. Many approaches are commonly used - among them are free body
diagrams using the balance of forces including the inertial ones, energy balance
principles and others.
Solution of governing equations. Depending on the nature of the problem we
can use analytical methods (Fourier series, integral transforms, etc) or numerical
methods (boundary element method, finite element method, etc.)
Interpretation of results. Results must be carefully interpreted with a clear
view of physical significance and compliance with assumed simplifications. All the
mentioned steps depend essentially on the experience and judgement of the person
analyzing the problem.
In this text the modelling in mechanics is treated by distinct chapters devoted to
statics, kinematics, dynamics and vibration, with a special emphasis to numerical
treatment of numerous examples and on the discussion of results.
Statics is branch of mechanics dealing with analysis of behaviour (usually in
terms of displacements, strains, stresses and forces) of bodies (mechanical systems,
structures) while neglecting inertia effects. It is based on equilibrium conditions,
time plays no role in the analysis.
Kinematics is concerned with study of motion of bodies (mechanical systems,
structures) without regard to the forces causing the motion.
Dynamics is a branch of mechanics where due emphasis is paid to inertial ef-
fects as opposed to statics where such effects are ignored.
Vibration is a subset of dynamics of rigid and deformable bodies dedicated to
CHAPTER 1. THE MECHMAT PROJECT 9

study of oscillatory motions. It is the Matlab programming language which treats


the worked-out examples in the above-mentioned chapters. Matlab is a tool that
efficiently deals with matrix algebra mathematics and has a very high level of pro-
gramming primitives. As such it is almost predestined to be a good teaching tool
for learning how to implement mechanical and numerical principles needed for the
solution of a wide class of mechanical problems in engineering.

1.4 M ATLAB basics


M ATLAB is a commercial interpreter devoted to numerical matrix algebra comput-
ing and graphical representation. This section summarizes some basic commands
showing how the exercises can be solved using the software. The reader is assumed
to already have some knowledge of M ATLAB . A prior reading of the Getting started
with M ATLAB handbook ([2]) is therefore recommended.

1.4.1 Basic calculations


One can perform the following elementary operations simply introducing the cor- + * - /
responding commands after the > sign. The complex numbers can be used without
restriction:
> 2*4+2
ans =
10
> (2+sqrt(-1))^2
ans =
3.0000 + 4.0000i

In M ATLAB , the variables do not need a prior declaration. Their names may variables
be of any length, using most most printable characters and are case-sensitive. If
the semicolon terminates a command, no output is produced in the active M ATLAB
window.
> rayon = 1e-1;
> surface = pi * rayon * rayon
surface =
0.0314

Matrices are defined using square brackets [ and ]. In each row, the ele-
ments are distinguished using commas , or spaces and the rows are distinguished
using semicolons ;. To address matrix elements, one has to specify them in paren-
theses ( and )by means indices. vectors
matrices
CHAPTER 1. THE MECHMAT PROJECT 10

> MAT = [ 1, 2, 3; 4, 5, 6; 7, 8, 10]


MAT =
1 2 3
4 5 6
7 8 10
> MAT(3,3) = 17
MAT =
1 2 3
4 5 6
7 8 17
> vec = [10; 0; 1000]
vec =
10
0
1000

The vectors can be seen as column-vectors (n-by-1 matrices) by default or as


row-vectors (1-by-m matrices).
The colon : can either be used to define ranges or, alternatively, to generate a
series of numbers. In parentheses, the colon : refers to all elements included in a
row (column) of a matrix.
> t = 1:5
t =
1 2 3 4 5
> lin = MAT(1,:)
lin =
1 2 3
> col = MAT(:,1)
col =
1
4
7
> 1:0.3:2
ans =
1 1.3000 1.6000 1.9000

Many problems may arise from a possible confusion between row-vectors and
column-vectors. With M ATLAB , it is quite natural to generate row-column vectors
(t=1:5). A straight method to be sure that a vector is of a column is to use the :
operator:
> tt = t(:)
tt =
1
2
3
CHAPTER 1. THE MECHMAT PROJECT 11

A conjugated transpose (hermitian) of A


A. unconjugated transpose of A
conj(A) conjugate of A
Table 1.1: Conjugated and transposed matrices

4
5

As for scalars, vectorial or matricial operations are computed quite easily:


> sum = vec - 2*col
sum =
8
-8
986
> lin * col
ans =
30
> product = MAT * vec
product =
3010
6040
17070

Certain operations between vectors and matrices can be computed element-by-


element if the related operator (product * for example) is preceded by a dot ..
. element-by-
> MAT.*MAT element
ans = operations
1 4 9
16 25 36
49 64 289
Transpose
One can transpose a real matrix (or vector) using the apostrophe . As shown Conjugate
in Table 1.1, if the matrix (or vector) is complex, one has to use the dot-apostrophe
operator . to simply transpose it; in that case, the sole apostrophe provides the
conjugated transpose.
It is quite easy to call and work with a function but it needs the prior definition of
a text file which name is identical to the name of the function and which extension
is .m. Any text editor can be used for this purpose. For example, the file myfunc.m
will include the following operations:
function [result] = myfunc (x)
x3 = x*x*x;
result = x3 + sin(x) - 2;
CHAPTER 1. THE MECHMAT PROJECT 12

The functions define within themselves local variables that can not be reached out-
side this context. The local variables do not exist outside the scope of their defini-
tion.
Any function can be directly used from the directory wherein it has been saved
(use the pathtool command to browse, define or edit the current path).
> myfunc(1,-2)
ans =
-2.1585
> x3
x3 = Result is undefined

A function defines inputs and outputs that may vary in number and type (real,
scalar, matrix, other function, ...).
The logical variables are either 1 (true) or 0 (false). One can carry out compar- logical
isons between scalars using the following operators: >, >=, <, <=, == (equality), ~= operations
(non equality). The logical and and or operations are defined by the & and
| operators, respectively.
M ATLAB supports test structures like : if then
else
x=input(Value);
if x > 5
x greater than 5
else
if x == 5
x equals 5
else
x is less than 5
end
end

M ATLAB supports iterative structures like : for while

x = 1:5
for i = 2:4
x.^i
end
% Comment: gives second, third and fourth powers for x evolving from 1 to 5
i=2;
while i<5
x.^i
i=i+1;
end
CHAPTER 1. THE MECHMAT PROJECT 13

1.4.2 Solving linear algebra problems with M ATLAB


The solution of a classical linear system of equations A:x = b can be easily ob- Linear
tained using the \ operator that should not be confused with the / division systems
operator.
> x = MAT \ vector
x =
993.33
-2006.7
1010

Ax Bx
The eigenvalue problem : =  : is solved using the function eig(A,B) Eigenvalues
that produces two outputs: val for the eigenvalues  and vec, for the eigenvectors
x :
> [vec,val] = eig (A,B);

As long as the eigenvalues are not sorted by the eig function, one has to use the
sort function to do so, if necessary.
A polynomial ak xk + : : : + a2 x2 + a1 x + a0 is defined by the row vector of its Polynomial
coefficients [ak ; : : : ; a2 ; a1 ; a0 ]. The polyval function evaluates this polynomial for
a given argument.
> pol=[1,2,3,4]
pol =
1 2 3 4
> polyval(pol,-1)
ans =
2

The roots of a polynomial are computed using the roots function that takes Polynomial
the coefficients of that polynomial as input. One can therefore find the roots of roots
x3 + 2x2 + 3x + 4 computing:
> pol=[1,2,3,4]
pol =
1 2 3 4
> roots(pol)
ans =
-1.6506+ 0.0000j
-0.1747+ 1.5469j
-0.1747- 1.5469j

If one wants to fit a set of values y (x) in a least-square sense, the polyfit polynomial
function can be used to determine the coefficients of that optimal polynomial. For regression
example, to establish the best straight line through the coordinates (1,10), (3,18)
and (10,37), one has to compute:
CHAPTER 1. THE MECHMAT PROJECT 14

> x=[1 3 10];


> y=[10 18 37];
> polyfit(x,y,1)
ans =
2.92537 8.01493

The line is therefore described by the equation y = 2:925x + 8:015.


To find the zeros of a nonlinear function, the nonstandard rroots function can zero of a
be used : function
> racines=rroots(myfunc,-1,10,100,1e-6)
> racines =
1.0434

The rroots function works with the following input arguments: the name of
the studied function, the lower and upper bounds for the zeros to be determined, the
number of sub-intervals for the bisection algorithm to be applied and the tolerance
related to the function residue(see the rroots.m file for details).
The numerical integration of the equations of motion Newmark

Mq + C_q + Kq = F(q_ ; q; t) (1.1)


integration

of a mechanical system defined through its mass M, damping C and stiffness K


matrices, and submitted to the generalized forces F can be performed using the
newmark and defphy functions. See mckf*.m files for examples.

1.4.3 Plotting data in M ATLAB


plot
M ATLAB provides a wide library of visualization functions to work with line and
surface plots, histograms, 3D objects with shading and animation. One can refer to
[1] for a detailed description of the available features.
We recall that the plot(x,y) command produces a classical y vs. x graph. An
example is provided here under. The result is shown in Figure 1.1
x=(-5:0.1:5);
plot(x,sin(x)./(x.*x+1));
xlabel (X axis)
ylabel (Y axis)
grid on
title (A plot with MATLAB)

1.4.4 Other useful M ATLAB commands


M ATLAB commands who and whos list the existing variables. The clear command who
clears all variables. close all closes all the active figure windows. whos
clear
BIBLIOGRAPHY 15

A plot with MATLAB


0.5

0.4

0.3

0.2

Y axis 0.1

0.1

0.2

0.3

0.4

0.5
5 4 3 2 1 0 1 2 3 4 5
X axis

Figure 1.1: Graph of sin(x)=(x2 + 1).

Bibliography
[1] Using MATLAB Graphics. The MathWorks, Natick, MA, USA, 1996.

[2] Getting Started with MATLAB. The MathWorks, Natick, MA, USA, 1997.

[3] Irving H. Shames. Engineering Mechanics. Statics and Dynamics. Prentice


Hall, Upper Saddle River, New Jersey, USA, 1996.

You might also like