Numerical Methods
Numerical Methods
D ITY f
IR S o l
AH ER o l
i c a
a l
o
B IV T ch an str g i
N IO S c h u in
U e d r
M In e e
d
n g i n
A n
A L
IC S
R
E O D e
M n l
U TH r
O c a
N E e t i d
t
M ap m a a n
h e n g .
C t h l i rs A
a de ro n
M o Er l i o
M il
M
3
Instructor information
Instructor Name: Mr.Million Asfaw
mechanics(MS.c)
Email: milliyardo@gmail.com
What are numerical methods and why should you study them?
Continued……..
2. Numerical methods allow you to use canned software
with insight. Matlab, Mathcad
3. Numerical methods are an efficient vehicle for learning to
use computers. Because numerical methods are expressly
designed for computer implementation. At the same time,
you will also learn to acknowledge and control the errors of
approximation that are part and parcel of large-scale
numerical calculations.
4. Numerical methods provide a vehicle for you to
reinforce your understanding of mathematics. Because one
function of numerical methods is to reduce higher
mathematics to basic arithmetic operations, they get at the
nuts and bolts of some otherwise obscure topics.
6
Continued……..
The equation is a model that relates the acceleration of a
falling object to the forces acting on it.
It is a differential equation because it is written in terms of
the differential rate of change (dv/dt)of the variable that we
are interested in predicting.
Rather,more advanced techniques such as those of calculus
must be applied to obtain an exact or analytical solution. For
example, if the jumper is initially at rest (v=0at t =0), calculus
can be used to solve the above Equ for
12
Continued……..
• where tanh is the hyperbolic tangent that can be
either computed directly or via the more
elementary exponential function as in
Continued…..
15
Continued…….
Or
17
Continued………
18
Continued………..
• Equation (1.11) is called a finite-difference approximation of
the derivative at time ti It can be substituted into Eq. (1.8) to
give
Continued……
• Thus, the equation can be rewritten more concisely as
• If you are given an initial value for velocity at some time ti,
you can easily compute velocity at a later time ti+1.This
new value of velocity at ti+1can in turn be employed to
extend the computation to velocity at ti+2and so on. Thus
at any time along the way,
20
NumercialSou
l to
i ntotheBungeeJumperProbe
lm
Continued…..
22
Conclusion
• The results are plotted in Fig. 1.4 along with the exact solution.
We can see that the numerical method captures the essential
features of the exact solution. However, because we have
employed straight-line segments to approximate a continuously
curving function, there is some discrepancy between the two
results. One way to minimize such discrepancies is to use a
smaller step size. For example, applying Eq. (1.12) at 1-s
intervals results in a smaller error, as the straight-line segments
track closer to the true solution. Using hand calculations, the
effort associated with using smaller and smaller step sizes
would make such numerical solutions impractical. However,
with the aid of the computer, large numbers of calculations can
be performed easily. Thus, you can accurately model the
velocity of the jumper without having to solve the differential
equation exactly
23
Formatted output
• fprintf('Hello')
• Output:
• Hello
• Arrays
• a = [3 6 7];
• b = [1 9 4];
•c = a + b
• Output:
• 4 15 11
27
Continued……
• Remarks: (1) Both a and b are given as a three-
element array. In the third line, the operation of
"a+b" results in element-by-element addition
Extracting an individual element of an array
a = [3 6 7];
b = [1 9 4 5];
c = a(2) + b(4)
Output:
c = 11
Remark: If b is a one-dimensional array, b(n) is the n-
th element of that array. Since a(2) is 6 and b(4) is 5,
the 3rd statement leads to c = 6+5 = 11
28
Comment
•%
• % This program demonstrates how to "comment out"
• % a segment of code
•%
• A = 3;
• B = A*A;
•%
• % B = 2*B <--- This statement is not executed
•%
• C = A+B
• Output:
• c = 12
29
Basic looping
• The for loop
• Loop: Using for command
• b = 3;
• for k = 1:5
• b
• end
• Output:
• 3
• 3
• 3
• 3
• 3
• Remark: The blue-colored segment in lines 2-4 forms a "for-
loop". The statement sandwiched between "for k = 1:5" and "end"
is repeated 5 times, with the "k" index going from 1 to 5 step 1.
33
• sum1 = 0;
• for k = 1:9
• sum1 = sum1+k;
• end
• Sum1
• Output:
• 45
• Remark: this program performs the summation of
1+2+3+4+5+6+7+8+9 (= 45).
35
• sum1 = 0;
• for k = 1:2:9
• sum1 = sum1+k;
• end
• sum1
• Output:
• 25
• Remark: this program performs the summation of
1+3+5+7+9 (= 25). The command "for k = 1:2:9" means
we go through the loop only 5 times. First time with k = 1,
second time with k = 1+2 (=3), third time with k = 1+2+2
(=5), and so on. The looping stops once k reaches 9.
36
• b = [3 8 9 4 7 5];
• sum1 = 0;
• for k = 1:4
• sum1 = sum1+b(k);
• end
• sum1
• Output:
• 24
• Remark: This program performs the summation of sum1
= b(1)+b(2)+b(3)+b(4) = 3+8+9+4 = 24
37
• b = [3 8 9 4 7 5];
• sum1 = 0;
• for k = 1:2:5
• sum1 = sum1+b(k);
• end
• sum1
• Output:
• 19
• Remark: This program performs the summation of sum1
= b(1)+b(3)+b(5) = 3+9+7 = 19
38
Double loop
• sum1 = 0;
• for n = 1:2
• for m = 1:3
• sum1 = sum1+n*m;
• end
• end
• sum1
• Output:
• 16
• Remark: this program performs the summation of Sum1 =
1*1+1*2+1*3 +2*1+2*2+2*3 = 18
39
The if command
• num1 = 7;
• if(num1 > 5)
• fprintf('%4u is greater than 5 \r', num1)
• else
• fprintf('%4u is less than or equal to 5 \r', num1)
• end
• Output:
• 7 is greater than 5
• Same program, but change first line to "num1 = 3;"
• Output:
• 3 is less than or equal to 5
• Remark: In this program, if (num1 > 5) (num1 is greater than 5) is true, the
statement
• "fprintf('%4u is greater than 5 \r', num1)" is executed. Otherwise, the
statement
• "fprintf('%4u is less than or equal to 5 \r', num1)" is executed.
41
Continued…..
• There are 6 commonly used expressions to compare two
numbers in an if command:
• A > B A is greater than B
• A < B A is less than B
• A >= B A is greater than or equal to B
• A <= B A is less than or equal to B
• A == B A equals B
• A ~= B A does not equal B
42
Thank U !!!!
God Bless
Ethiopia !!!