Beruflich Dokumente
Kultur Dokumente
Examples
Simple Pendulum
ⅆ𝟐 𝜽 𝒈
𝟐
+ 𝐬𝐢𝐧 𝜽 = 𝟎
ⅆ𝒕 𝒍
Cycloid
Wiener process
𝟐
𝟒𝝅
𝒑𝟐 = 𝒂𝟑
𝑮 𝑴𝟏 + 𝑴𝟐
Double Pendulum
ⅆ𝟐 𝜽𝟏 ⅆ𝟐 𝜽𝟐
𝒎𝟏 + 𝒎𝟐 𝒍𝟏 𝟐
+ 𝒎𝟐 𝒍𝟐 𝟐
𝐜𝐨𝐬 𝜽𝟐 − 𝜽𝟏
ⅆ𝒕 ⅆ𝒕
ⅆ𝟐 𝜽𝟐
= 𝒎𝟐 𝒍𝟐 − 𝒎𝟏 + 𝒎𝟐 𝒈 𝐬𝐢𝐧 𝜽𝟏
ⅆ𝒕𝟐
--------------- (1)
ⅆ𝟐 𝜽𝟐 ⅆ𝟐 𝜽𝟏
𝒍𝟐 𝟐 + 𝒍𝟏 𝟐 𝐜𝐨𝐬 𝜽𝟐 − 𝜽𝟏 =
ⅆ𝒕 ⅆ𝒕
ⅆ𝒔
= −𝜷𝒔𝑰
ⅆ𝒕 • Rabies
ⅆ𝑰 • Tuberculosis
= 𝜷𝒔𝑰 − 𝜸𝑰
ⅆ𝒕 • Small pox
ⅆ𝑹 • Rubella
= 𝜸𝑰
ⅆ𝒕 • Measles
Epidemic Models
Anderson & May 1975, 1991
𝟏 N: Bacterial density
ⅆ𝑵 𝑪
= 𝜶𝟏 𝑵−𝑵
ⅆ𝒕 𝟏+𝑪
C : Nutrient concentration
ⅆ𝑪 𝑪
=− 𝑵 − 𝑪 + 𝜶𝟐
ⅆ𝒕 𝟏+𝑪
Red Blood Cell Production Model
𝑹𝒏+𝟏 = 𝟏 − 𝒇 𝑹𝒏 + 𝑴𝒏
𝑴𝒏+𝟏 = 𝜸𝒇𝑹𝒏
ⅆ𝒙
= 𝒑𝒚 − 𝒑𝒙
ⅆ𝒕
ⅆ𝒚
= −𝒙𝒛 + 𝒓𝒙 − 𝒚
ⅆ𝒕
ⅆ𝒛
= 𝒙𝒚 − 𝒃𝒛
ⅆ𝒕
Basics of MATLAB Programming
MATLAB: Salient features
MATLAB desktop
MATLAB desktop
Main Area
Current working
directory
Tool bar
Command
window
workspace
Command
history
MATLAB data types
• Integer.
• Real (double and single precision).
• Complex number.
• Character strings.
• Structures: mixed data types.
+ : summation
- : subtraction
* : multiplication
/ :division
= :equal
^ :power
sqrt :square root
Important MATLAB built-in operators & functions
Arithmetic operators Relational operators
+ : summation == : equal
- : subtraction ~= : not equal
* : multiplication < : less than
/ :division > : greater than
<= : less than or equal
= :equal
>= : greater than or equal
^ :power
sqrt :square root
Important MATLAB built-in operators & functions
Arithmetic operators Relational operators
+ : summation == : equal
- : subtraction ~= : not equal
* : multiplication < : less than
> : greater than
/ :division
<= : less than or equal
= :equal
>= : greater than or equal
^ :power
sqrt :square root Logical operators
& : logical AND
~ : logical NOT
! : logical OR
all : determine if all array elements are nonzero
any : determine if any array elements are nonzero
false : logical FALSE
true : logical TRUE
find : find indices and values of nonzero elements
islogical : determine if input is logical
logical : converts numeric values to logical
Important MATLAB built-in operators & functions
Trigonometric functions
Arithmetic operators Relational operators
sin : sine function in radian
cos : cosine function in radian + : summation == : equal
asin : inverse sin - : subtraction ~= : not equal
acos : inverse cosine * : multiplication < : less than
sinh : Hyperbolic sin > : greater than
/ :division
cosh : Hyperbolic cosine <= : less than or equal
= :equal
asinh : inverse hyperbolic sin >= : greater than or equal
^ :power
acosh : inverse hyperbolic cosine
deg2rad : convert angle from degree to radian
sqrt :square root
1. Manual entry
2. using built-in functions
3. Passing output from user defined/built-in function.
Variable Naming
Scalar variable
creation
1. Manual entry
Row vector
creation
1. Manual entry
Column vector
creation
1. Manual entry
Matrix creation
1. Manual entry MATLAB reserves i and j for
representing complex numbers
Try i^2
Matrix with
complex
elements
2. Matrix creation using built-in functions
Vector/Matrix creation using built-in functions
Applications
o Array operations
o Finding part of vector
o 2D array indexing
o Getting a row
o Getting a column
o Using indexing to assign values to rows and columns
Vector Operators
Symbol Operation
.* Element-by-element multiplication
./ Element-by-element “right” division
.\ Element-by-element “left” division
.^ Element-by-element power
a .* b and a * b operations?
Colon Notation
It is a powerful and important tool in the effective use of MATLAB
Default increment = 1
Syntax But start value,
start value : increment : end value increment, and end
value need not to be
integers
examples x = 0 : 0.1 : 1 % create an 11 element row vector
x = (1 : 5)’ % create a 5 element column vector
‘ --- MATLAB operator to calculate transpose
Find out the difference between (1 : 5)’ and 1:5’
Use colon notation to refer to an entire column or row
x =[ 1 2 3; 4 5 6; 7 8 9];
a = x( :, 1 ) % extract entire first column
b = x( :, 2 ) % extract entire 2nd column
c = x( 3, : ) % extract entire 3rd row
y = rand(6, 8);
y(:, 7:8) = [];
x =[ 1 2 3; 1 4 2;4 3 1];
x(4,:) = [6 8 1]; try
x = -2*pi : pi/10 : 2*pi;
x=x’;
y = [ 2 3; 4 5; 6 7]; [x sin(x) cos(x)]
y(:,3)=[1; 2; 3];
Linear Algebra: Built-in MATLAB functions
6x + 5y + 3z = 4 --------- (1)
2x + 4y + 7z = 2.3 --------- (2)
9x + 2y + 5z = 6.7 --------- (3)
6x + 5y + 3z = 4 --------- (1)
2x + 4y + 7z = 2.3 --------- (2)
9x + 2y + 5z = 6.7 --------- (3)
a = [ 6 5 3; 2 4 7; 9 2 5];
b = [4; 2.3; 6.6];
c = inv(a)* b
2) Gaussian elimination
c = a\b
It returns a column vector x, y, & z