Lecture 4 - MATLAB Basics
Lecture 4 - MATLAB Basics
Basics of MATLAB
Outline
Basic commands
Representation of matrix
Solving PDE
File Code
Browse Editor
r
Workspac
e
Command
Window
Basic Numerical Operators(1-5) and logical operators(6-10)
1. Addition (+)
2. Subtraction (−)
3. Division (/)
4. Multiplication(∗)
5. Power (∧)
6. Greater than (>)
7. Less than (=)
8. Less than equal to (<=)
9. Not Equal (∼=)
10. Equality (==)
Some Basic commands
• linspace(X1, X2): Generates a row vector of 100 linearly equally spaced points between X1
and X2.
A = [1 2 3;4 5 6; 7 8 9]
Solving set of Linear Equation
Let’s take an example
Solving Partial differential equations in
MATLAB
A continuous system can be converted into a discretized
system with some approximations.
By using Taylor’s expansion series the derivatives can be
written as
• First order forward differencing
𝑑𝑦
= 2𝑥 + 1,
𝑑𝑥
Forward differencing: 𝑦 0 =0
Sol : 𝑦 = 𝑥 2 + 𝑥
Numerical solution Vs. analytical solution
For dx = 5 For dx = 1
Solving Partial differential equations in
MATLAB
A continuous system can be converted into a discretized
system with some approximations.
By using Taylor’s expansion series the derivatives can be
written as
• First order forward differencing
𝑡+1 𝑡 𝑡 𝑡−1
𝜕𝑇 𝑇𝑖,𝑗 −𝑇𝑖,𝑗 𝜕𝑇 𝑇𝑖,𝑗 −𝑇𝑖,𝑗
= =
𝜕𝑡 ∆𝑡 𝜕𝑡 ∆𝑡
Solving Partial differential equations in MATLAB
1
𝑇(𝑖,𝑗) = 2 2 *[∆𝑦 2
*(𝑇(𝑖−1,𝑗) +𝑇(𝑖+1,𝑗) )+ ∆𝑥 2 *(𝑇(𝑖,𝑗−1) + 𝑇(𝑖,𝑗+1) )]
2∗(∆𝑥 +∆𝑦 )
Steady state 2D in plate
1000 C
5000 C 2000 C
3000 C
Steady state 2D in plate
Steady state 2D in plate with iterations
Steady state 2D in plate with iterations
Thank you!!