Вы находитесь на странице: 1из 43

ME3100: Modeling and Simulation

Date: 04/01/2018
Mon : 16:00-17:25; Thurs: 14:30-15:55; Room No. C-LH4

I) Modeling and simulation: Introduction to MATLAB and GUI Development

II) Simulation technique:

a) Solution of Algebraic equation: Incremental search method, Bisection method, Ridder’s method, Secant
method, Newton-Raphson methods.

b) Solution of systems of equations: Linear and nonlinear systems

c) Solution of IVP and BVP: Euler, RK –different order, Shooting method, Finite difference method

d) Curve fitting and interpolation technique.

e) Solutions of numerical integrations

f) Minimization of function of single and several variables; and functional.

III) Modeling technique:

a) Newton’s method with unconstraint and constraint conditions

b) Virtual work principle for unconstraint and constraint conditions

c) Lagrangian and Hamiltonian formulation for unconstraint and constraint conditions.

References:
Grading: 1)Ramin S. Esfandian, “Numerical methods for Engineers and Scientist” CRC Press,,
1) Attendence: 10% New York 2013.
2) Assignments+Quiz (3): 30% 2) Rudra Pratap, “Getting started with MATLAB: A Quick Introduction to Scientists and
3) Mid sem (4 Feb): 30% Engineers”Oxford University Press, Latest Edition.
4) End sem (14 March): 35% 3)Jaan Kiusalaas, “Numerical methods for Engineering with Matlab” Cambridge
University Press, Cambridge, 2010.
4)Firdaus E. Udwadia abd Robert E. Kalaba, “Analytical Dynamics: A new approach”
Total 100%

(Contact Email: ashok@iith.ac.in )


MATLAB for Mechanical System

Introduction to MATrix LABoratory


(MATLAB - A Trademark of MathWorks, Inc. USA)

(Presentation for Academic Purpose)


By
Dr. Ashok Kumar Pandey

Department of Mechanical and Aerospace Engineering


Indian Institute of Technology Hyderabad
(Contact Email: ashok@iith.ac.in )
Breakout Sessions
Topic 1: Introduction to Numbers, Functions, Equation and systems of
equations, Matrix and their operations, Functions , Plots – 2D, 3D,
Visualization.

Topic 2: Equations with single variable and multivariable,


Linear and nonlinear forms of equations, and their solution
methodology.

Topic 3: Ordinary Differential Equation: Linear and Nonlinear Forms,


Analytical solution of ordinary differential equations.
Numerical solution of ordinary differential equations.

Topic 4: Continuation of Topic 3.


A Must Do Steps for MATLAB
i) Create a new folder in D:\ directory
>> mkdir D:\MATLAB_Course
ii) Make the working directory of MATLAB as the above folder
>> cd D:\MATLAB_Course
iii) Clear all the data
>> clc

iv) Open a new Editor and name it accordingly, for example “Example_1.m”
>> edit Example_1.m
(A prompt opens! To create a blank file with name Example_1.m, click Yes)
v) First Command in the Edit file should be
>> clear all; (If you are not using any old information.)
>> clc; (To clear the screen!)
v) To display any statement
>> display('Welcome to Hyderabad') % Automatically goes to next command
>> input('Welcome to Hyderabad') % Press any button to continue…
v) For any help, type “help” command in command prompt, for exp. help regarding display
>> help 'display’
>> help display
Some Basic Operators
Arithmetic operators.

plus - Plus +
uplus - Unary plus +
minus - Minus -
uminus - Unary minus -
mtimes - Matrix multiply *
times - Array multiply .*
mpower - Matrix power ^
power - Array power .^
mldivide - Backslash or left matrix divide \
mrdivide - Slash or right matrix divide /
ldivide - Left array divide .\
rdivide - Right array divide ./
idivide - Integer division with rounding option .
kron - Kronecker tensor product
Some More Operators
Relational operators. Logical operators.
eq - Equal ==
ne - Not equal ~= relop - Short-circuit logical AND &&
lt - Less than < relop - Short-circuit logical OR ||
gt - Greater than > and - Element-wise logical AND &
le - Less than or equal <= or - Element-wise logical OR |
ge - Greater than or equal >= not - Logical NOT ~

Relational operators.
colon - Colon : punct - Continuation ...
paren - Parentheses and subscripting () punct - Separator ,
paren - Brackets [] punct - Semicolon ;
paren - Braces and subscripting {} punct - Comment %
punct - Function handle creation @ punct - Invoke operating system command !
punct - Decimal point . punct - Assignment =
punct - Structure field access . punct - Quote '
punct - Parent directory .. transpose - Transpose .'
ctranspose - Complex conjugate transpose '
Numbers, Functions, and Equations
Numbers: Scalar, Vector, and Matrix

1. Scalar: A quantity that is denoted by a single number. Example: 1; 2; 4; ½; 0.5; 5 × 10−6 ;


Any number a ∈ (-1.7977e+308, 1.7977e+308) ; Inf = 1.7977e+308;
MATLAB Command: >> 1; 2; 4; 1/2; 0.5; 5e-6;

2. Formats: Set the format of fixed/floating numbers.


(Fixed: Fixed bits on the right and left of decimal points (Integer I and F parts: I.F)
Floating Points: Three parts – Sign S, Exponent E, Mantissa M: S*M*2^E)

Example: For expressing A=1.22222222222222222222


i) FORMAT SHORT Scaled fixed point format with 5 digits; A=1.2222
ii) FORMAT LONG Scaled fixed/floating point format with 15 digits for double
[8 bytes (64 bits)] and 7 digits for single [4 bytes (32 bits)].
A=1.222222222222222
iii) FORMAT SHORT E Floating point format with 5 digits. A=1.2222e+000
iv) FORMAT LONG E Floating point format with 15 digits for double and 7 digits for
single
A=1.222222222222222e+000
v) To know more about formats: type >> help format
Numbers, Functions, and Equations
Numbers: Scalar, Vector, and Matrix

1. Vector: An arrays of two or more numbers.


Example: Row vector - (1, 2); Column vector - (1;2); Row vector - (0.1, 1, 1e-2);

For 64-bit Windows XP (Workspace Memory: 3155 MB)


- Largest Matrix Size: 2047 MB
- Number of elements in Largest Real Double Array: 268e6
For more information, please visit http://www.mathworks.com/matlabcentral/answers/91711
MATLAB Command: >> A=[1,2]; B=[1;2]; C=[0.1, 1, 1e-2];

2. Matrix: An arrays of numbers with a size of M× N, where M and N are integers.


1 2
Example:A = ;
4 3
MATLAB Command: >> A=[1,2; 4, 3];

3. Dimensions and size of a Matrix, For example: A with size m× n


MATLAB Syntax: >>[m, n] = size(A); %It returns the size of matrix A in separate variables
For Scalar: m=1, n=1;
For Vector: Row vector: m=1, n>1; Row vector: d=n
Column vector: m>1, n=1; For Vector: >>d=length(A) Column vector: d=m
Numbers, Functions, and Equations
Function of single variable:

1. Inbuilt functions, f(x)


2. A combination of numbers and standard functions, F(x)=c.g(x)+b.f(x)+d.h(x)2
Both types require prior information of quantity x, over a specified range [a,b]
MATLAB Syntax for [1,10] for 5 points can be written as

>> x=linspace(1,10,5)
Answer: [1.0000 3.2500 5.5000 7.7500 10.0000]
>> x=[1:2.25:10];
Answer: [1.0000 3.2500 5.5000 7.7500 10.0000]
I. Inbuilt functions, f(x): Most commonly used functions are already present in MATLAB.
Examples: i) Polynomial of different orders and all trigonometric functions and their inverse
such as sin, cos, tan, etc
ii) Exponential and logarithmic functions
iii) Bessel’s function of different order
iv) Many more standard/special functions.
II. Other functions: Functions different from inbuilt functions can be obtained by performing
different operations such as addition, subtraction, product and division with
different inbuilt functions and polynomial functions using predefined vector ‘x’.
Numbers, Functions, and Equations
Examples:

1. Inbuilt functions, f(x)


>> x=linspace(1,10,5)
Answer: 1.0000 3.2500 5.5000 7.7500 10.0000
>> sin(x)
Answer: 0.8415 -0.1082 -0.7055 0.9946 -0.5440
>> log(x) % Logarithm of base ‘e’
Answer: 0 1.1787 1.7047 2.0477 2.3026
>> log10(x) % Logarithm of base 10
Answer: 0 0.5119 0.7404 0.8893 1.0000

2. A combination of numbers and standard functions, F(x)=c.g(x)+b.f(x)+d.h(x)2


>> x=linspace(1,10,5)
Answer: 1.0000 3.2500 5.5000 7.7500 10.0000
>> 5*sin(x)+3*log10(x)+x.^2
Answer: 5.2074 11.5572 28.9434 67.7034 100.2799
>> 5*sin(x)+3*log10(x)+x.^2+bessel(1,x)
Answer: 5.6474 11.7983 28.6019 67.8950 100.3234
Numbers, Functions, and Equations
Function of multi variable:
1. Inbuilt functions, f(x,y)
2. A combination of numbers and standard functions, F(x,y)=c.g(x)+b.f(y)+d.h(x,y)
Both types require prior information of quantities x and y, over a specified range [a,b] and [c,d],
respectively.

MATLAB Syntax for [1,10] for 5 points can be written as


1) If the independent variables are specified.
>> x=linspace(1,10,5); y=linspace(1,10,5);
Answer: x=[1.0000 3.2500 5.5000 7.7500 10.0000]; y=[1.0000 3.2500 5.5000 7.7500 10.0000];
2) A function f(x,y)=sin(x) cos(y)+xy2.
>> f=sin(x).*cos(y)+x.*y.^2
Answer: 0.0015e+003 0.0344e+003 0.1659e+003 0.4656e+003 1.0005e+003
3) By using ‘inline’ syntex:
>> g=inline('sin(x)*cos(x)+x*y^2')
Answer: Inline function: Alternate way to define a function:
g(x,y) = sin(x)*cos(x)+x*y^2 >> g=@(x)(sin(x).*cos(x)+x.*y.^2)
4) Find the value of g at x=3.25 and y=3.25 Answer: Inline function:
>> g(3.25,3.25) g = @(sin(x).*cos(x)+x.*y.^2)
Answer: 34.4357
Numbers, Functions, and Equations
Equation: When two functions/expressions are same

Examples: y = f(x,a); : f(x,y)=g(x,y); 𝑓(𝑥, 𝑦, 𝑦 ′ , 𝑦′′) = 𝑔(𝑥, 𝑦, 𝑦 ′ , 𝑦′′)


=> AX=B; X=[x,y];

1. Linear equations
Linear Equations: ax=b, when, x is unknown, and a and b are constant terms
A linear equation of two variable is a straight line in 2D.
A linear equation of three variable represents a plane in 3D.
A linear equation of n-variables represents a hyperplane in n-D.

Matrices of linear systems AX=B, X contains n-variables in n-D space


(Standard straight forward method of solutions)

2. Generalized Linear/Nonlinear equations


If a function f(x1,x2,x3,x4,…xn)=0 is a function of n-unknowns x=[x1,x2,x3,x4,…xn].
(Iterative Methods are employed!)

3. Systems of equations
If f1(x)=0; f2(x)=0; f3(x)=0; f4(x)=0; f5(x)=0; …… , fN(x)=0; are N equations,
System of equations can be represented by a vector F(x)=[f1(x); f2(x); f3(x); ……, fN(x)]=0.
Creating a function file in MATLAB
Any function/equation or a system of equations can be written in MATLAB
The first line of a function m-file may be written in the following form

function [output_parameter_list] = function_name(input_parameter_list);

where, output_parameter_list=vector of unknowns


input_parameter_list = vectors of knowns
function_name = function should be saved as function_name.m file
Rewrite the equation in F(x)=0
Example: Write a system of equations
2𝑥1 − 𝑥2 − 𝑒 −𝑥1 = 0
2𝑥1 − 𝑥2 = 𝑒 −𝑥1 −𝑥1 + 2𝑥2 − 𝑒 −𝑥2 = 0
−𝑥1 + 2𝑥2 = 𝑒 −𝑥2
Function files saved as myfun.m
as a function file
function F = myfun(x)

F=[2*x(1) – x(2) – exp(-x(1));


- x(1) +2*x(2) – exp(-x(2))];
Plots-2D
Any function/expression can be plotted for a given range of inputs

An example of 2D line plot

Matlab Syntex: y vs sin(x)

0.8
plot(Y)
plot(X1,Y1,…,Xn,Yn) 0.6

plot(X1, Y1, LineSpec,…, Xn, Yn, LineSpec) 0.4

0.2

y=sin(x)
Plot y=sin(x) 0

>>x=-pi:0.1:pi; -0.2

>>y=sin(x); -0.4

>> plot(x,y) -0.6

>> xlabel('x'); ylabel('y=sin(x)'); -0.8

>> axis tight -3 -2 -1 0 1 2 3


x

Other related commands: axes, grid, subplot, xlim, ylim, zlim, axis
Plots-3D
Any function/expression can be plotted for a given range of inputs

An example of 3D line plot

Matlab Syntex:
40

plot(X1,Y1,Z1)
30

20

Plot x=sin(t), y=cos(t), z=t;


10

>>t=0:pi/50:10*pi; 0
1
>>x=sin(t);y=cos(t); z=t;
0.5 1
>> plot3(x,y,z) 0
0
>> grid on; -0.5
-1 -1
>> axis tight;

Other related commands: axis, bar3, grid, line, LineSpec, loglog, plot, semilogx, semilogy, subplot surf
Visualization
To visualize the variation of a function, different 2D plots, contour,
35
surface plots can be obtained
30

25

Visualization 20

15
>> view([-1, -1, 0.5])
10

5
5
0
1 1

0 0
0 -1 -1
3D Contour plots

>>[X,Y,Z] = meshgrid(-3:0.125:3) -5
>>Z=peaks(30);
>> meshc(XYZ) -10
>>surf(X,Y,Z)
2
3
>>surfc(XYZ) 2
0 1
>>colormap hsv -1
0
-2 -2
>>axis([-3 3 -3 3 -10 5]): -3
Other related commands:
axis, caxis, colormap, contour, delaunay, imagesc, mesh, meshgrid, pcolor, shading, trisurf, view
Breakout Sessions
Topic 1: Introduction to Numbers, Functions, Equation and systems of
equations, Matrix and their operations, Functions , Plots – 2D, 3D,
Visualization.

Topic 2: Equations with single variable and multivariable,


Linear and nonlinear forms of equations, and their solution
methodology.

Topic 3: Ordinary Differential Equation: Linear and Nonlinear Forms,


Analytical solution of ordinary differential equations.
Numerical solution of ordinary differential equations.

Topic 4: Continuation of Topic 3.


System of Linear Equations
Operation involving the Matrix and the solution of linear equation
AX=B
where, A is a square matrix, X and B are vectors

Review of Some Basic operations: MATLAB Syntex


1. Transpose 1. A’
2. Multiplication 2. *, .*
3. Division 3. Left /, Right \
4. Inverse 4. inv
5. Determinant 5. det
6. Eigen values and 6. [V,D] = eig(A), D=eigen values,
7. eigen vectors 7. V=Eigenvector such that A*V=V*D
8. LU decomposition 8. lu(A)
Solution commands: Examples:
1. X= inv(A)*X 1. Find the solution of linear algebraic solution and
2. X=A\B also the Eigen values :
3. X=(B'/A')‘ x+2y+3z = 1
4. [L,U]=lu(A); Y=L\B; X=U\Y; 3x+3y+4z = 1
2x+3y+3z = 2
2. Find the Eigen values and vectors of coefficient matrix
A Function of Single Variable
Solution Methodology: F(x)=0,
where, x =roots of F(x),
F(x) =linear/nonlinear function of x

Solution Methodology: Newton Raphson


A system of n-nonlinear equations in n-unknowns Solution:
If x=x0 is the first initial guess

where,

Jacobian =
In Matrix form

Convergence: i) |xn+1-xn|<𝜀 ii) |f(xn)|< 𝜀.


A Function of Single Variable
MATLAB Syntax:
1. fzero: To solve the roots of single nonlinear equation
2. fsolve: To solve the roots of a system of nonlinear eqations
3. roots: If the equation is polynomial
4. solve: Symbolic solution of algebraic equations

Description
1. [x,fval,exitflag] = fzero(fun,x0,options); options = optimset('Display','iter','TolFun',1e-8)
2. [x,fval,exitflag,output,jacobian] = fzero(fun,x0,options);
options = optimset('Display','iter','TolFun',1e-8, 'Jacobian','on')
3. r=roots(c), where c is coefficients of polynomial ordered in descending order.

4. g= solve(eq1, eq2, ..., eqn, var1, var2, ..., varn); or sol(eq,var)


Examples
g= solve(eq1, eq2, ..., eqn, var1, var2, ..., varn); or sol(eq,var)

Example 1: Example 2: Solve the quadratic Example 2: System of equations:


equation for the variable b: syms x;
>>syms a b c x; >>syms a b c x; S = solve('x + y = 1','x - 11*y = 5');
>>solve('a*x^2 + b*x + c') >>solve('a*x^2 + b*x + c','b') S = [S.x S.y]

Example 4: r=roots(c).
>>g=inline('(x^2-4*x)*(x^2-4*x+1)-20');
>>sol=solve(g); 𝑝 𝑥 = 𝑐1 𝑥 𝑛 + 𝑐2 𝑥 𝑛−1 + ⋯ + 𝑐𝑛 𝑥 + 𝑐𝑛+1 = 0,
𝑐 = 𝑐1 , 𝑐2 , . . , 𝑐𝑛 , 𝑐𝑛+1 ;

Example 5
syms a b x y real Example 6: Solve 𝑥 3 − 6𝑥 2 − 72𝑥 − 27
f1='a*x+b*y-3'
f2='-x+2*a*y-5' >> c=[1 -6 -72 -27];
[x,y]=solve(f1,f2) >> r=roots(c);
Examples
[x,fval,exitflag,output,jacobian] = fzero(fun,x0,options);
[x,fval,exitflag] = fzero(fun,x0,options);
options = optimset('Display','iter','TolFun',1e-8, …
options = optimset('Display','iter','TolFun',1e-8)
'Jacobian','on'))
Example 1: Solution near 3
>>x = fzero(@sin,3); Example: Solve equations at x0=[-5.-5]
2𝑥1 − 𝑥2 = 𝑒 −𝑥1
Example 2: Solution between 1&2: −𝑥1 + 2𝑥2 = 𝑒 −𝑥2
>>x = fzero(@cos,[1 2])
Solution: Rewrite equation in the form F(X)=0
Example 3: Solution of 2𝑥1 − 𝑥2 − 𝑒 −𝑥1 = 0
>>f = @(x)x.^3-2*x-5; −𝑥1 + 2𝑥2 − 𝑒 −𝑥2 = 0
>>z = fzero(f,2) %near 2 %M-file function
function F = myfun(x,a)
Example 4: Solution of function F = [2*x(1) - x(2) - exp(-x(1));
%M-file function -x(1) + 2*x(2) - exp(-x(2))]
function f = myfun(x,a)
f = cos(a*x); %Script
%Script >>x0 = [-5; -5];
>>a=2; options=optimset('Display','iter');
>>x = fzero(@(x) myfun(x,a),0.1) [x,fval] = fsolve(@myfun,x0,options)
Exercise
Q1. Solve the following nonlinear problem (algebraic equations) simultaneously.

3X3+X2-1=0
X4-10X2+2=0
a) Write a function file for the above equations, solve individually and also
simultaneously those two equations.
b) Plot both these functions and find out approximate solution by looking at the
intersection points (to find initial guess).
c) Using initial guess solve for the exact solutions using ‘fsolve’ or ‘fzero’.
d) Also solve these equations using ‘solve’ command.

Q2. Using the function f(x)=x4-8x3+17x2-4x-20 do the following

a) Using inline command define the function and use ‘fplot’ to plot the function
over an approximate interval of x and locate the zeros of the graph
b) Use fzero to find the accurate value for the initial values obtained in a)
c) Write coefficient vector and find solution using roots
d) Use symbolic f(x) to solve the roots of f(x) using solve command
Breakout Sessions
Topic 1: Introduction to Numbers, Functions, Equation and systems of
equations, Matrix and their operations, Functions , Plots – 2D, 3D,
Visualization.

Topic 2: Equations with single variable and multivariable,


Linear and nonlinear forms of equations, and their solution
methodology.

Topic 3: Ordinary Differential Equation: Linear and Nonlinear Forms,


Analytical solution of ordinary differential equations.
Numerical solution of ordinary differential equations.

Topic 4: Continuation of Topic 3.


Solution of ODE
MATLAB Syntax:
1. dsolve: Symbolic solver for ODE
2. ode45: Numerical solver for ODE

Dsolve: Symbolic solution of ordinary differential equations


Syntax: dsolve('eq1','eq2',...,'cond1','cond2',...,'v')

Example 1: Example 5: Setting Initial and Boundary Conditions


>>y = dsolve('Dx = -a*x') >>y = dsolve('Dy = a*y', 'y(0) = b')
>> y = dsolve('Dy=1+y^2','y(0)=1')
Example 2: Specifying the dependent Variable
>> y=dsolve('D2y = -a^2*y', 'y(0) = 1', 'Dy(pi/a) = 0‘)
>>y = dsolve('Df = f + sin(t)')

Example 3: Specifying the independent Variable Example 6: Solving a System of Differential Equations
>>y = dsolve('(Dy)^2 + y^2 = 1','s') >> z = dsolve('Dx = y', 'Dy = -x')
>> y=dsolve('D2y = -a^2*y', 'y(0) = 1', 'Dy(pi/a) = 0‘)
Example 4: Specifying the independent Variable >>z.x
>>y = dsolve('(Dy)^2 + y^2 = 1', 'y(0) = 0') >>z.y
>>z
General Form of ODE
MATLAB Syntax:
1. dsolve: Symbolic solver for ODE

Example 10: Some more examples


Example 7: System of Differential equations
>>dsolve('Df = 3*f + 4*g', 'Dg = -4*f + 3*g')
>>f = S.f
>>g = S.g

Example 8: Vibration type problem


>>y = dsolve('D2y = cos(2*x) - y', 'y(0) = 1',
'Dy(0) = 0', 'x');

Example 3: Specifying the independent Variable


>>u = dsolve('D3u = u', 'u(0) = 1', 'Du(0) = -1',
'D2u(0) = pi', 'x')
Numerical Solution of ODE
IVP ODE

𝒚 = 𝒇 𝒕, 𝒚 ; 𝐭𝐬𝐩𝐚𝐧 = [𝒕𝟎 , 𝒕𝒇 ]; 𝒚 𝒕𝟎 = 𝒚𝟎

Solve initial value problems for ordinary differential


equations:

Solver:
ode23, ode45, ode113, ode15s, ode23s, ode23t, ode23tb:

Syntax:

[T,Y] = solver(odefun,tspan,y0)
[T,Y] = solver(odefun,tspan,y0,options)
options = odeset('RelTol',a,'AbsTol',b);

sol = solver(odefun,[t0 tf],y0...)


Description of ODE45
IVP ODE

𝒚 = 𝒇 𝒕, 𝒚 ; 𝐭𝐬𝐩𝐚𝐧 = [𝒕𝟎 , 𝒕𝒇 ]; 𝒚 𝒕𝟎 = 𝒚𝟎
ODE45 is an adaptive solver that integrates a system of ordinary differential equations using a
4th order Runge-Kutta formula (with a 5th order correction).

Command:[T, Y] = ODE45 (@F,TSPAN,Y0,OPTIONS)

Syntax:
'F' - is the name of the file with the state space differential equations.

TSPAN - Tspan = [T0, Tfinal], initial and final integrating times. If we look for a solution at
specific times (T0, T1, T2, …, Tfinal), define Tspan = [T0 T1 T2, … Tfinal], and Ti = t0:t:tf.

Y0 - is a column vector of initial conditions.

OPTIONS - contains the optional values for the desired accuracy like:
Relative error tolerance 'RelTol' (le-3 by default) and
Vector of absolute error tolerances 'AbsTol' (all components le-6 by default).

Omitting OPTIONS argument will choose default values .


Application to Vibration Problem
IVP ODE Convert to two first order equations
𝒙′′ + 𝜹𝒙′ + 𝜶𝒙 + 𝜷𝒙𝟑 = 𝜸 cos(𝝎𝒕) 𝒙𝟏 ′ = 𝒙𝟐 ;
𝒙′ 𝟎 = 𝟎; 𝒙 𝒕𝟎 = 𝟎. 𝟓 𝒙𝟐 ′ = 𝜸 cos(𝝎𝒕) − 𝜹𝒙𝟐 − 𝜶𝒙𝟏 − 𝜷𝒙𝟏 𝟑
𝐭𝐬𝐩𝐚𝐧 = [𝟎, 𝟏𝟓𝟎; 𝒙𝟏 𝟎 = 𝒙𝟏𝟎 = 𝟎. 𝟓; 𝒙𝟐 𝟎 = 𝒙𝟐𝟎 = 𝟎;
𝜶=-1.0; 𝜷=1.0; 𝜸=0.2; 𝜹=0.3; 𝝎=1.2
In order to solve the problem:

1. Create two separate external m-files:


(a) "system1.m": stores the information about the equation set structure.
(b) "solve.m": includes the remaining data and necessary commands.

2. Type "solve" from the MATLAB window and the file "system1" will be used automatically. The
results are stored in vector t and matrix x.

3.Plot solution graphs. The corresponding MATLAB command is "plot(x,y)" where x is an argument
column-vector (horizontal-axis), while y is a function column-vector (vertical axis). File "solve1.m"
includes all the necessary commands, which shows how to plot the graphs.
Time Response
%File "system1.m" - Dynamical System %File “solve1.m" - Dynamical System

function xprime = system1 (t,x) close all;


xprime=zeros(2,1); clear all; clc;
%----parameters ------------- t0=0; % initial time
alpha=-1.0; tfinal=150; % final time
beta=1.0;
gamma=0.2; x0=[0.5 0]'; % column vector of initial conditions
delta=0.3;
w=1.2; tspan=[t0 tfinal]'; % tspan
%----State space -------------
xprime(1)=x(2); option=odeset('RelTol', 1e-8, 'AbsTol', 1e-8);
xprime(2)=gamma*cos(w*t)-alpha*x(1)…
-delta*x(2)-beta*x(1)^3; [t,x]=ode45(@system1, tspan, x0, option);
Time Response
Free vibration:
γ = 0, α = −1,β =1,δ = 0.3, ω =1.2

figure(1)
subplot (2, 1, 1)
plot (t,x(:,1)); grid;
xlabel ('t [sec]'); ylabel ('x(1) [m]');
subplot (2, 1, 2)
plot (t,x(:,2)); grid;
xlabel ('t [sec]'); ylabel ('x(2) [m]');
Time Response and Phase Plane
Forced vibration: γ = 0.2, α = −1,β =1,δ = 0.3, ω =1.2
a) Time series

figure(2)
subplot (2, 1, 1)
plot (t,x(:,1)); grid;
xlabel ('t [sec]'); ylabel ('x(1) [m]');
% the steady state space is defined by the last 20
%percent of the solution vector.
% n is the total number of time nodes during
%integration a) Phase plane at steady state (120 sec<t<150 sec)
n=size(t);
subplot (2, 1, 2)
plot (x(round(0.8*n):n,1), x(round(0.8*n):n,2));
grid;
xlabel('x(1)[m]'); ylabel('x(2) [m/s]');
Poincare Map
• Poincare' Maps are used to characterize the stability of periodic system response
(e.g. whether the response is periodic with the same period as that of the excitation).

• The Poincare’ Map of a periodically excited dynamical system is constructed by


sampling system response at a fixed interval that equals the (minimal) period of the
excitation.

• A system with periodic response has a finite number of Poincare’ points in state space:
i) a single point: periodic response with the same period of excitation (T).
ii) m points: subharmonic response (of order m) corresponding to periodicity with an
integer multiple of the exciting period (e.g. mT, m>1).
iii) m points: ultrasubharmonic response (of order m/n) corresponding to periodicity
with an integer submultiple of the exciting period (e.g. mT/n, m,n>1).
• A system which exhibits aperiodic response has an infinite number of Poincare’ points
in its state space:
i) an infinite number of points organized along an invariant curve (or topology)
quasiperiodic response describing a beating like phenomena.
ii) an infinite number of points that are not! organized along an invariant curve describe
nonstationary response (and are a candidate for chaotic vibrations in deterministic
systems).
Poincare Map
Solve the system of two first order equations (equation 2), with
γ = 0.2, 0.28, 0.51, 0.46 , α = −1,β =1,δ = 0.3, ω =1.2

% File " poincare.m" , Poincare sampling procedure


clear all; close all; clc; format long;
%%%%%%%% initial conditions %%%%%%%%
t0=0;
tf=1000;
x0=[0.5 0]' ;
%%%%%%%%%%%%%%%%%%%%%%%%%
w=1.2; % input frequency
Te=2*pi/w; % cycle time
RES=1000; % resolution - number of sample points per cycle
Tspan=[t0:(Te/RES):tf];
option=odeset ('RelTol', 1e-8, 'AbsTol',1e-8); % option argument can be omitted
[t,X]=ode45 (@system1, Tspan, x0, option);
m=length(t);
Poincare Map
%%%%%% POINCARE SAMPLING %%%%%%%%%%%%

per=0.5; % beginning of steady state


poincare_x=X(round(m*per):RES:m , 1) ;
poincare_y=X(round(m*per):RES:m , 2) ;

figure (1);

subplot (3,1,1) , plot (t,X(:,1));


xlabel ('t');ylabel ('x1');grid;

subplot (3,1,2) , plot (X(round(m*per):m,1),X(round(m*per):m,2));


xlabel ('x1');ylabel ('x2');grid;

subplot (3,1,3) , plot (poincare_x, poincare_y,'+');


xlabel ('x1');ylabel ('x2');grid;
Poincare Map
I. Forced vibration response: γ = 0.2, α = −1,β =1,δ = 0.3, ω =1.2 .
a) Time series
b) Phase plane at steady state (120sec < t < 150sec)
c) Poincare’ Map at steady state (period 1)
Poincare Map
II. Forced vibration response: γ = 0.28, α = −1,β =1,δ = 0.3, ω =1.2 .
a) Time series
b) Phase plane at steady state (120sec < t < 150sec)
c) Poincare’ Map at steady state (period doubling)
Poincare Map
III. Forced vibration response: γ = 0.51, α = −1,β =1,δ = 0.3, ω =1.2 .
a) Time series
b) Phase plane at steady state (120sec < t < 150sec)
c) Poincare’ Map at steady state (period tripling)
Poincare Map
IV. Forced vibration response: γ = 0.46, α = −1,β =1,δ = 0.3, ω =1.2 .
a) Time series
b) Phase plane at steady state (120sec < t < 150sec)
c) Poincare’ Map at steady state (aperiodic with 760 points)
Nonlinear Frequency Response
Example: Find the frequency response of
𝒒
𝒂′ = −𝜷𝝎𝟎 𝒂 + 𝝎𝟐𝟎Time
a) 𝒙 sinseries
𝝋
𝟐𝝎𝟎
𝟑𝜸 𝟐 𝒒
𝝋′ = 𝝎 − 𝝎𝟎 − 𝒂 + cos 𝝋
𝟖𝝎𝟎 𝟐𝒂𝝎𝟎

𝒂 𝟎 = 𝟎. 𝟏; 𝝋 𝟎 = 𝟎. 𝟏, 𝐭𝐬𝐩𝐚𝐧 = [𝟎, 𝟐𝟎𝟎]; 𝒒=0.2; 𝜷=0.05; 𝜸=0.5;𝝎𝟎 =1;

%File “rigid.m" - Dynamical System

function dy=rigid(t,y,w)
global w w0 gamma1 beta1 q
dy=zeros(2,1);
dy(1)=-beta1*w0*y(1)+q/(2*w0)*sin(y(2));
dy(2)=(w-w0)-3*gamma1/(8*w0)*y(1)^2+q/(2*w0*y(1))*cos(y(2));
end
MATLAB Programing
Frequency Sweeping from 0.1 to 2.5
clc
clear all for i=1:1:length(ww)
w=ww(i)
global w w0 gamma1 beta1 q [T,Y] = ode45(@rigid,[0 200],Y0);
nn=length(Y(:,1));
gamma1=0.5; ymax=max(Y(nn-round(nn/4):nn,1));
beta1=0.05; q=0.2; ymax1=max(Y(nn-round(nn/4):nn,2));
w0=1; Y0=[ymax ymax1];
np=400; yy=[yy;ymax];
end
ww=linspace(.1,2.5,np);
ww1=linspace(2.5,.1,np); plot(ww,yy,‘b')
yy=[]; hold on
yy1=[];
Y0=[0.1 0.1];
MATLAB Programing
Frequency Sweeping from 2.5 to 0.1

ymax1=max(Y(nn-round(nn/4):nn,1));
ymax2=max(Y(nn-round(nn/4):nn,2));
for j=1:1:length(ww1)
w=ww1(j)
[T,Y1] = ode45(@rigid,[0 1000],[ymax1,ymax2]);
nn1=length(Y1(:,1));
ymax1=max(Y1(nn1-round(nn1/4):nn1,1));
ymax2=max(Y1(nn1-round(nn1/4):nn1,2));
yy1=[yy1;ymax1];
end
hold on
subplot(3,1,3)
plot(ww1,yy1, ‘r')
Thank you

References:
1. Rudra Pratap, “Introduction to MATLAB”
2. http://www.mathworks.in/help/matlab/math/partial-differential-
equations.html
3. http://www.math.tamu.edu/~efendiev/math647_spring05/pdemat.pdf
4. http://www.youtube.com/watch?v=fYSEY4Q10nk