Vous êtes sur la page 1sur 24

KOMPUTASI NUMERIK

(Numerical Computing)

Referensi:
1. Applied Numerical Methods with MATLAB For Engineers and Scientists 4th Edition,
2018 - Steven C. Chapra
2. Numerical Computing with MATLAB Revised Reprint Edition 2004 – Cleve B Moler
3. Introduction to Scientific Computing and Data Analysis 2016 - Mark H. Holmes

Topik:
1. Modeling, Computers, and Error Analysis
2. Roots and Optimization
3. Linear Systems
4. Curve Fitting
5. Integration and Differentiation
6. Ordinary Differential Equations

Kriteria Penilaian:
1. UTS
2. UAS
3. Quiz & Tugas
4. Absensi (?)
Mathematical Modeling, Numerical Methods, and Problem Solving
Newton’s Law:
…. Note: m is the mass of the object (constant)

…differential equation
exact solution,
analytical or closed-form solution:
υ = 0 at t = 0
Unfortunately, there are many mathematical models that cannot be solved exactly. In many
of these cases, the only alternative is to develop a numerical solution that approximates the
exact solution
the time rate of change of velocity can be approximated by:

…………finite-difference approximation

or ………Euler’s method

υo = 0 at to = 0
Drag Force

more detailed representation:


in terms of the lumped drag:
differential equation:

…..assumes that upward distance is positive

Assume that the jumper’s initial position is defined as x(0) = 0,


the velocity and distance at t = 2 s:
Matlab Function:

function vend = velocity1(dt, ti, tf, vi)

dt = time step (s)


ti = initial time (s)
tf = final time (s)
vi = initial value of dependent variable (m/s)
This function can be invoked from the command window with the result:
>> velocity1(0.5,0,12,0)
ans =
50.9259
function vend = velocity1(dt, ti, tf, vi)
% velocity1: Euler solution for bungee velocity
% vend = velocity1(dt, ti, tf, vi)
% Euler method solution of bungee
% jumper velocity
% input:
% dt = time step (s)
% ti = initial time (s)
% tf = final time (s)
% vi = initial value of dependent variable (m/s)
% output:
% vend = velocity at tf (m/s)
t = ti;
v = vi;
n = (tf - ti) / dt;
for i = 1:n
dvdt = deriv(v);
v = v + dvdt * dt;
t = t + dt;
end
vend = v;
end

function dv = deriv(v)
dv = 9.81 - (0.25 / 68.1) * v*abs(v);
end
Test:

>> velocity1(0.5,0,12,0)
ans =
50.9259

>> velocity1(0.001,0,12,0)
ans =
50.6181

the true value from the analytical solution is 50.6175

it will not work if the computation interval is not evenly divisible by the time step.

Test:
>> velocity2(0.35,0,12,0)
ans =
?

Solution:

function vend = velocity2(dt, ti, tf, vi)


t = ti;
v = vi;
h = dt;
while(1)
if t + dt > tf, h = tf - t; end
dvdt = deriv(v);
v = v + dvdt * h;
t = t + h;
if t >= tf, break, end
end
vend = v;
end

function dv = deriv(v)
dv = 9.81 - (0.25 / 68.1) * v*abs(v);
end

Test:

>> velocity2(0.35,0,12,0)
ans =
50.8348
Roundoff and Truncation Errors
True Error (Absolute Error):

Approximate Error:

For Iterative methods, the computation is repeated until the absolute value of
the percent relative error is lower than a prespecified tolerance s
stopping criterion

If the following criterion is met, it can be assured that the result is correct to at
least n significant figures

correct to at least three significant figures:


Computer Algorithm for Iterative Calculations:
TOTAL NUMERICAL ERROR:

The total numerical error is the summation of the truncation and roundoff
errors.
Roundoff error: digital computers have magnitude and precision limits
on their ability to represent numbers.
Truncation errors are those that result from using an approximation in
place of an exact mathematical procedure.

For example,
ROUNDOFF ERRORS:
Examples:
function sout = sumdemo()
s = 0;
for i = 1:10000
s = s + 0.0001;
end
sout = s;

the result is
>> format long
>> sumdemo
ans =
0.99999999999991

TRUNCATION ERRORS:

Truncation errors are those that result from using an approximation in place of
an exact mathematical procedure.

The Taylor Series:


any smooth function can be approximated as a polynomial
remainder term:

This relationship has two major drawbacks:


- ξ is not known exactly but merely lies somewhere between xi and xi+1
- need to determine the (n + 1)th derivative of f (x) need to know f (x)
the derivative mean-value theorem:
if a function f(x) and its first derivative are continuous over an interval from xi
to xi+1, then there exists at least one point on the function that has a slope,
designated by f ʹ (ξ)

The Remainder for the Taylor Series Expansion


zero-order term:

Using the Taylor Series to Estimate Truncation Errors:


to predict velocity of bungee jumper as a function of time
first derivative term:

….. from derivative mean-value theorem

the error of derivative approximation should be proportional to the step size

Numerical Differentiation:

finite difference

in general:
Forward Difference Approximation, because it utilizes data at i and i+1 to estimate the
derivative

Backward Difference Approximation

Centered Difference Approximation

the centered difference is a more accurate representation of the derivative


Finite-Difference Approximations of Higher derivatives

Vous aimerez peut-être aussi