Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 51

CHE620 Modeling &

Simulation
Linear Algebra
Power Series
Generate a graph of cosθ (-3π
to 3π) 1

0.8

Can this graph be presented by 0.6

a polynomial? 0.4

0.2

cosTHETA
cosθ = C1+ C2θ + C3θ2+ C4θ3+….. 0

-0.2

Write a code to program: -0.4

-0.6

cosθ = 1-θ2/2!+θ4/4!-θ6/6!+….n -0.8

-1
-10 -8 -6 -4 -2 0 2 4 6 8 10
Theta
Homework problem
Develop sinθ series and program it!
Euler’s Formula
Jacob Bernoulli

He was working on compound interest

If capital is 1 and rate is 100% then program

We can write the compound interest formula for one


year as:

A=exp(r) and for ‘y’ years as exp(ry) so exp(x) is an


important function
Power series for e x

Let us develop a polynomial for ex

Program the expression

Maclaurin series (All the series can be presented by the


following form:)
Euler’s Formula

Add the two


1 2 1 1 1
cos 𝑥+ sin 𝑥 =1+ 𝑥 − 𝑥 − 𝑥3+ 𝑥4 + 𝑥5
2 6 24 120

𝑖𝑥 1 2 1 3 1 4 1 5
𝑒 ¿ 1+ 𝑥𝑖+ 𝑥 + 𝑥 𝑖+ 𝑥 + 𝑥 𝑖
2 6 24 120
1 2 1 3 1 4 1 5
cos 𝑥+ 𝑖sin 𝑥=1+ 𝑥𝑖+ 𝑥 + 𝑥 𝑖+ 𝑥 + 𝑥 𝑖
2 6 24 120

eiθ = cosθ + i sinθ


Euler’s Identity
eiπ + 1 = 0

Exponential is related to compound interest growth

Iota is a complex number representation

Pi is related to the circles (circumference/diameter)

Sin and cosine are the trigonometric functions

Via simulation researcher in early 17th century related all


these quantities!
Linear System of
Algebraic Equations

Solution is X = A\b
(A\ = inverse of matrix)
Complex Number
Z = a + ib

Conjugate of complex number

Ž = a – ib

Modulus of complex number

|Z|= √(ŽZ) = √(a2 + b2) ≥ 0

Complex number in polar notation

Z = a + ib = |Z|(cosθ + i sinθ) ; θ = tan-1(b/a)

Euler identity

eiθ = cosθ + i sinθ; Z = |Z|eiθ


Coordinate Vector
Vectors
Vector can be row or column matrix

In 3-D space vector is defined by coordinate system

For N-D coordinate system


Vectors
Addition of two real vectors

Multiplication of a vector by a real scalar

Null vector
Vectors
Dot product of the vectors

For parallel vectors dot product is maximum and equal


to the summation of the product of their lengths

For perpendicular vectors it is equal to 0


Vectors
When vectors are perpendicular

Dot product = 0; v . w = 0; v and w are termed as


orthogonal

If the vectors are normalized to unit length they are


called orthonormal

It provides how different the two vectors are


Vectors
P-norm

2-norm is the length of the vector (Euclideain norm)

∞-norm extracts the largest value of the vector


component
Matrices
Addition of matrices

Multiplication of matrices
Gaussian Elimination
Method

1 1 1 X1 4
2 1 3 X2 = 7
3 1 6 X3 2

Augmented matrix
Gaussian Elimination
Method
Perform Row operation: Add two rows after multiplying with a
constant to eliminate first member of the row “a(r,c) = 0

Perform the same procedure to make all members equal to


zero below diagonal
Gaussian Elimination
Method

Three nested loops, increases the work of the


computer by N3.
Gaussian-Jordan
Elimination Method
In Gaussian-Jordan method the matrix is converted to
upper triangular with zeros
Matrices Multiplication
Columns of the first matrix must be equal to the rows
of the second matrix
Orthogonalization

When by row operation we are making members of a


matrix equal to zero. We are actually getting the dot
product between that member with an orthogonal
vector at that space point
Gram-Schmidt
Orthogonalization
Gram-Schmidt
Orthogonalization
Determinant
If determinant = 0 matrix is singular, and no unique
solution exist

If determinant ≠ 0 matrix is non-singular and Ax=B has


a unique solution
Determinant

If A = 2 x 2 matrix then determinant = a11a22 – a12a21

If A = 3 x3 it can be distributed into its minors


Properties of Determinant
|A| = |AT|

If all the members in a row or column = 0 then |A| = 0

If two rows or columns are swapped then |A| = -|B|

If two rows or columns are same then |A| = 0

|AB| = |A| x |B|

If A is upper or lower triangular then |A| = a11 x a22 x ..


Inverse of a matrix
Inverse of A = A-1

If A is singular i.e |A| = 0 then A-1 does not exist

In simulation this has limited value


Matrix Factorization
A = LU Where LU are the Lower and Upper matrices
obtained through Gaussian eliminations

As Ax = B

LUx = B

If pivoting is used to arrange the rows then each


swapping changes the sign of the determinant

PA = LU

Where P is the permutation matrix obtained by doing


the same operation on an identity matrix

|I| = 1 but |P| = ± 1, This will adjust the sign


Solution of Equations
PAx = PB

PA = LU

LUx = PB

x = U-1(L-1(PB))
UL Matrices
UL Matrices
UL matrices are created to find the inverse of the
matrix
UL Matrices

Backward substitution can compute the inverse


MATLAB CODE

This is equal to

x = A\B
Cholesky Decomposition
A = LLT

First column
Cholesky Decomposition

Second column
Algorithm
MATLAB Code
Problem
Solution
MATLAB Code
A = zeros(3,3); % set matrix of coefficients

A(1,:) = [ 1 1 1];

A(2,:) = [0.04 0.54 0.26];

A(3,:) = [0.93 0.24 0];

b = [10; 2; 6]; % set right hand side vector

x = A\b; % solve for unknown and display results


Sparse and Banded
Matrices

Boundary Conditions
Discretization
Central difference approximation
Matrix Formation
Matrix Formation
Sparse Matrix
Matrix having most of its elements equal to zero
Banded Matrix
If all the non zero members are located along at
diagonal
MATLAB Code
Spy plot for sparse
matrix
MATLAB Code
MATLAB
Code

You might also like