EE407 - Chap1
EE407 - Chap1
EMAIL: BARHOUMI_NABIL@YAHOO.FR
Textbook:
Chapra and Canale, Numerical Methods for Engineers, 7th
Edition, McGraw-Hill, 2015.
Any Questions?
LECTURES:
A mathematical model is an
equation/function that expresses a
physical system. We may write:
𝐷𝑒𝑝𝑒𝑛𝑑𝑒𝑛𝑡
𝑣𝑎𝑟𝑖𝑎𝑏𝑙𝑒
𝑖𝑛𝑑𝑒𝑝𝑒𝑛𝑑𝑒𝑛𝑡 𝑓𝑜𝑟𝑐𝑖𝑛𝑔
=𝑓 , 𝑝𝑎𝑟𝑎𝑚𝑒𝑡𝑒𝑟𝑠,
𝑣𝑎𝑟𝑖𝑎𝑏𝑙𝑒𝑠 𝑓𝑢𝑛𝑐𝑡𝑖𝑜𝑛𝑠
The dependent variable represents the
state of the system.
Independent variables includes time and
space.
Parameters represent the system’s
properties and composition.
Forcing functions are external influences.
Numerical Methods for EE (EE407) | Main
Example 1
17
Substituting yields
𝑐
𝑣 𝑡𝑖+1 = 𝑣ถ
𝑡𝑖 + 𝑔 − 𝑣 𝑡𝑖 𝑡𝑖+1 − 𝑡𝑖
𝑚
new value old value step size
slope
g = 9.81;
c = 12.5;
m = 68.1;
T = [0 15];
dt = 0.001;
t = T(1):dt:T(2);
Nt = length(t);
v = zeros(1,Nt);
for n = 2:Nt
v(n) = v(n-1)+(g-c/m*v(n-1))*dt;
end
plot(t,v,'b');
Conservation of momentum:
Any Questions?
Recall example 1.
Start
Input
𝑴𝟏, 𝑴𝟐, 𝑴𝟑, 𝑴𝟒
Detailed Algorithm
Step 1: Input
𝑮(𝑴𝟏 + 𝑴𝟐 + 𝑴𝟑 + 𝑴𝟒)/𝟒
𝑀1, 𝑀2, 𝑀3, 𝑀4
Step 2: G ← (𝑀1 + 𝑀2
+ 𝑀3 + 𝑀4)/4
N Is Y
𝑮 < 𝟓𝟎 Step 3: if (G < 50) then
Print “FAIL”
Print
“PASS”
Print
“FAIL”
else
Print “PASS”
end if
Stop
Recall the logical data type from the previous lecture (true =
1, or false = 0).
Matlab provides a range of logical operators, including:
Operator Sign Example
Logical AND & if (.. & ..)
Logical AND with short-circuiting && if (.. && ..)
Logical OR | if (.. | ..)
Logical OR with short-circuiting || if (.. || ..)
Logical NOT ~ if (~x)
Logical exclusive or (XOR) xor if (.. xor ..)
True if all elements are nonzero all B = all(A);
True if any element is nonzero any B = any(A);
Examples:
x = [1, 2; 3, 4];
y = x * 3;
z = x / 2;
Results: y = [3, 6; 9, 12];
z = [0.5, 1; 1.5, 2];
𝑚 𝑨 x =𝑚 𝑪
𝑘=𝑛 𝑩
Main
The FOR Loop
45
Main
Functions
49
Any Questions?
Types of error.
Significant figures.
Accuracy and precision
Maclaurin series.
Number representation in computers.
Taylor series.
Truncation error.
𝑓 ′ 𝑥 = −0.4𝑥 3 − 0.45𝑥 2
−𝑥 − 0.25
𝑓 ′′ 𝑥 = −1.2𝑥 2 − 0.9𝑥 − 1
𝑓 3 𝑥 = −2.4𝑥 − 0.9
𝑓 4 𝑥 = −2.4
𝒏 Derivative Approx 𝜀𝒕
0 𝑓 𝑥𝑖+1 ≅ 0.707106781 −41.4%
1 𝑓 ′ 𝑥 = − sin 𝑥 𝑓 𝑥𝑖+1 ≅ 0.521986659 −4.4%
2 𝑓 ′′ 𝑥 = − cos 𝑥 𝑓 𝑥𝑖+1 ≅ 0.497754491 0.449%
3 𝑓 3
𝑥 = sin 𝑥 𝑓 𝑥𝑖+1 ≅ 0.499869147 2.62 × 10−2 %
4 𝑓 4 𝑥 = cos 𝑥 𝑓 𝑥𝑖+1 ≅ 0.500007551 −1.51 × 10−3 %
5 𝑓 5
𝑥 = − sin 𝑥 𝑓 𝑥𝑖+1 ≅ 0.500000304 −6.08 × 10−5 %
6 𝑓 6
𝑥 = − cos 𝑥 𝑓 𝑥𝑖+1 ≅ 0.499999988 2.44 × 10−6 %
Any Questions?