0% found this document useful (0 votes)
10 views21 pages

Lecture 4 - MATLAB Basics

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views21 pages

Lecture 4 - MATLAB Basics

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

ME-460 Solid State Joining

Basics of MATLAB
Outline

 User interface of MATLAB

 Basic numerical and logical operators in MATLAB

 Basic commands

 Graphical representation of variables

 Representation of matrix

 Solving linear simultaneous equation

 Numerical solution Vs. analytical solution

 Solving PDE

 Solution to 2 D steady state conduction problem

 Solution to 2 D transient conduction problem


User Interface of MATLAB

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.

• linspace(X1, X2, N) :Generates N points between X1 and X2.


Some Basic commands

Meshgrid : Cartesian rectangular grid in 2-D or 3-D.

[X,Y] = meshgrid (x,y) returns 2-D grid coordinates


based on the coordinates contained in vectors x and y.
X is a matrix where each row is a copy of x, and Y is a
matrix where each column is a copy of y. The grid
represented by the coordinates X and Y has length(y)
rows and length(x) columns.
Graphical representation of relationship between
two variable
Defining the Matrix and its inverse

 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

𝜕𝑇 𝑇𝑖+1,𝑗 −𝑇𝑖,𝑗 𝜕𝑇 𝑇𝑖,𝑗+1 −𝑇𝑖,𝑗


= =
𝜕𝑥 ∆𝑥 𝜕𝑦 ∆𝑦

• First order Backward differencing

𝜕𝑇 𝑇𝑖,𝑗 − 𝑇𝑖−1,𝑗 𝜕𝑇 𝑇𝑖,𝑗 − 𝑇𝑖,𝑗−1


= =
𝜕𝑥 ∆𝑥 𝜕𝑦 ∆𝑦
• First order central differencing

𝜕𝑇 𝑇𝑖−1,𝑗 − 𝑇𝑖+1,𝑗 𝜕𝑇 𝑇𝑖,𝑗−1 − 𝑇𝑖,𝑗+1


= =
𝜕𝑥 2∆𝑥 𝜕𝑦 2∆𝑦
Numerical solution Vs. analytical solution

𝑑𝑦
= 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 −𝑇𝑖,𝑗


= =
𝜕𝑥 ∆𝑥 𝜕𝑦 ∆𝑦

• First order Backward differencing

𝜕𝑇 𝑇𝑖,𝑗 − 𝑇𝑖−1,𝑗 𝜕𝑇 𝑇𝑖,𝑗 − 𝑇𝑖,𝑗−1


= =
𝜕𝑥 ∆𝑥 𝜕𝑦 ∆𝑦
• First order central differencing

𝜕𝑇 𝑇𝑖−1,𝑗 − 𝑇𝑖+1,𝑗 𝜕𝑇 𝑇𝑖,𝑗−1 − 𝑇𝑖,𝑗+1


= =
𝜕𝑥 2∆𝑥 𝜕𝑦 2∆𝑦
Solving Partial differential equations in MATLAB
 2nd order central difference
𝜕2 𝑇 𝑇(𝑖−1,𝑗) −2𝑇(𝑖,𝑗) +𝑇(𝑖+1,𝑗)
=
𝜕𝑥 2 ∆𝑥 2

𝜕2 𝑇 𝑇(𝑖,𝑗−1) −2𝑇(𝑖,𝑗) +𝑇(𝑖,𝑗−1)


=
𝜕𝑦 2 ∆𝑦 2
 In time domain

𝑡+1 𝑡 𝑡 𝑡−1
𝜕𝑇 𝑇𝑖,𝑗 −𝑇𝑖,𝑗 𝜕𝑇 𝑇𝑖,𝑗 −𝑇𝑖,𝑗
= =
𝜕𝑡 ∆𝑡 𝜕𝑡 ∆𝑡
Solving Partial differential equations in MATLAB

Lets consider a square plate as shown in fig. The temp. at


the edges are shown, Determine the temp at the nodes
considering a 7*7 grid mesh.

We know 2D heat conduction equation will be the


governing equation for the case.

So as problem has to be solved for steady state , then


equation reduces to
𝜕2 𝑇 𝜕2 𝑇
+ 2 = 0……………..(1)
𝜕𝑥 2 𝜕𝑦
𝜕2 𝑇 𝑇(𝑖−1,𝑗) −2𝑇(𝑖,𝑗) +𝑇(𝑖+1,𝑗) 𝜕2 𝑇 𝑇(𝑖,𝑗−1) −2𝑇(𝑖,𝑗) +𝑇(𝑖,𝑗−1)
= and =
𝜕𝑥 2 ∆𝑥 2 𝜕𝑦 2 ∆𝑦 2
Solving Partial differential equations in MATLAB

 So the equation 1 turns to

𝑇(𝑖−1,𝑗) −2𝑇(𝑖,𝑗) +𝑇(𝑖+1,𝑗) 𝑇(𝑖,𝑗−1) −2𝑇(𝑖,𝑗) +𝑇(𝑖,𝑗+1)


+ =0
∆𝑥 2 ∆𝑦 2

upon simplifying and making 𝑇𝑖,𝑗 as subject

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!!

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy