Mathematics For Physicist: Adhi Harmoko Saputro
Mathematics For Physicist: Adhi Harmoko Saputro
Kuis
Adhi Harmoko Saputro
KUIS – 1 (5 menit)
1. Carilah integral persamaan
1
∫ f ( z ) dz = ∫ dz
C C (z 4
− 1,1)
dengan C
Solusi – 1
De Moivre’s formula
Solusi – 1
Solusi – 2
Solusi – 2
Hence
Numeric Analysis
Adhi Harmoko Saputro
Numerical Method
• Systematic methods that are suitable for solving, numerically, the problems on computers or
calculators
Numerical Steps
1. Modeling. We set up a mathematical model of our problem, such as an integral, a system
of equations, or a differential equation.
2. Choosing a numeric method and parameters (e.g., step size), perhaps with a preliminary
error estimation.
3. Programming. We use the algorithm to write a corresponding program in a CAS, such as
Maple, Mathematica, Matlab, or Mathcad, or, say, in Java, C or or FORTRAN, selecting
suitable routines from a software system as needed.
4. Doing the computation.
5. Interpreting the results in physical or other terms, also deciding to rerun if further
results are needed.
Iteration
Adhi Harmoko Saputro
f ( x) = 0
sin x = 0,5 x x3 + x =
1 tan x = x
• The solutions are called roots of the equation and the solution process is called finding roots
• There is no formula for the exact solution available
• approximation method iteration method
Iteration Method
1. Start from an initial guess xo (which may be poor)
2. Compute step by step approximations x1, x2, … of an unknown solution
Fixed-Point Iteration
• Using algebraic steps to transform f ( x ) = 0
• A fixed point of g
x = g ( x)
xn +1 = g ( xn )
Example
Example
Example
Example
Teorema
x = g ( x)
Example
Example
Example
Newton’s Method
• Newton–Raphson’s method is a iteration method for solving equations f(x) = 0, where f is
assumed to have a continuous derivative f’.
• Approximate the graph of f by suitable tangents
• An approximate value xo obtained from the graph of f
f ( xo ) f ( xo )
' ( xo )
tan β f=
= x= xo −
f ' ( xo )
1
xo − x1
f ( x1 )
x= x1 −
f ' ( x1 )
2
Newton’s Method
• Newton–Raphson’s method is a iteration method for solving equations f(x) = 0, where f is
assumed to have a continuous derivative f’.
• Approximate the graph of f by suitable tangents
• An approximate value xo obtained from the graph of f
f ( xo ) f ( xo ) f ( x1 )
' ( xo )
tan β f=
= x= xo − x= x1 −
f ' ( xo ) f ' ( x1 )
1 2
xo − x1
f ( xn +1 ) ≈ f ( xn ) + ( xn +1 − xn ) f ' ( xn ) =
0
Newton’s Method
Newton’s Method
Example
Example
• Solve the equation:
f(x) = x.^3 - 0.165*x.^2 + 3.993*10.^-4
• using Newton-Raphson Method with initial guess (xo = 0.05) to 3 iterations
• Plot the function.
Example
x = 0.05;
x_true = 0.0623776;
iter = 0;
for i=1:10
x = x - (x^3 - 0.165*x^2 + 3.993*10^-4)/(3*x^2 - 0.33*x);
iter = iter + 1;
err = abs(x_true-x);
fprintf('Iteration %d: x=%.20f, err=%.20f\n', iter, x, err);
if err < 10^-7
disp('Iteration Successfully');
x = -10:0.01:10;
f = x.^3 - 0.165*x.^2 + 3.993*10^-4;
figure;
plot(x,f)
grid on
break;
end
end
if i==10
disp('Iteration Failed');
end
Interpolation
Adhi Harmoko Saputro
Interpolation
• Find approximate values of the function f(x) for “new” x’s that lie between these points for
which the function values are given
Linear interpolation
Quadratic Interpolation
Example
• Computer Y’ on X’ X Y
• 1.5 1 0.841471
• 2.5 2 0.909297
• 3.5 3 0.14112
4 -0.7568
• 4.5
5 -0.95892
• 5.5
6 -0.27942
• 6.5
7 0.656987
• 7.5 8 0.989358
• 8.5 9 0.412118
• 9.5 10 -0.54402
Example
x=(1:10)'; 1
y=sin(x); 0.8
0.6
y1 = interp1q(x,y,x1); 0.2
figure; 0
hold on;
-0.4
-0.6
plot(x1,y1, 'bo');
-0.8
hold off;
-1
1 2 3 4 5 6 7 8 9 10
Spline Interpolation
Adhi Harmoko Saputro
Spline Interpolation
• Fitting the polynomials together into a single continuous curve passing through the data
points
g= ( xo ) f o , g=
( xo ) f= ( x1 ) f= ( xn ) f=
( x1 ) f1 , , g= ( xn ) f n
Spline Interpolation
• Spline interpolation is piecewise polynomial interpolation
Conditions
• Clamped Conditions
=g ' ( xo ) f=
' ( xo ) , g ' ( xn ) f ' ( xn )
• Natural Conditions
g '' ( xo ) 0=
= o, g '' ( xn ) 0
Example
Example
Example
Example
Example
Spline Interpolation of Sine Data
x = [0 1 2.5 3.6 5 7 8.1 10];
y = sin(x);
xx = 0:.25:10;
yy = spline(x,y,xx);
plot(x,y,'o',xx,yy)
Example
Spline Interpolation of Distribution with Specified Endpoint Slopes
x = -4:4;
y = [0 .15 1.12 2.36 2.36 1.46 .49 .06 0];
cs = spline(x,[0 y 0]);
xx = linspace(-4,4,101);
plot(x,y,'o',xx,ppval(cs,xx),'-');
Numeric Integration
• Numeric integration means the numeric evaluation of integrals
b
J = ∫ f ( x ) dx
a
b
=J ∫ f ( x=
a
) dx F (b ) − F ( a )
Rectangular Rule
• Subdivide the interval of integration a ≤ x ≤ b into n subintervals of equal length
h = (b – a)/n and in each subinterval approximate f by the constant f(xj*) the value of f at
the midpoint xj* of the jth subinterval
Rectangular Rule
• f is approximated by a step function (piecewise constant function), the n rectangles
b
=J ∫ f ( x ) dx ≈ h f ( x1* ) + f ( x2* ) + + f ( xn* )
a
b−a
h=
n
Trapezoidal Rule
• Take the same subdivision as before and approximate f by a broken line of segments
(chords) with endpoints [a, f(a)], [x1, f(x1)], …, [b, f(b)] on the curve of f
Trapezoidal Rule
• The area under the curve of f between a and b is approximated by n trapezoids of areas
1 1 1
f ( a ) + f ( x1 ) h, f ( x1 ) + f ( x2 ) h, , f ( xn −1 ) + f ( b ) h
2 2 2
• Trapezoidal rule
b
1 1
=J ∫ f ( x ) dx ≈ h f ( a ) + f ( x1 ) + + f ( xn −1 ) + f ( b )
a 2 2
Example
Example
Matlab Code
• fun = @(x) exp(-x.^2);
• q = integral(fun,0,1)
Numeric Differentiation
• The computation of values of the derivative of a function f from given values of f
• The difficulty with differentiation is tied in with the definition of the derivative, which is the
limit of the difference quotient, and, in that quotient, you usually have the difference of a
large quantity divided by a small quantity
f j ' = f '( x j )
f j '' = f '' ( x j )
f ( x + h) − f ( x)
f j ' = lim
h →0 h
Example
• fun = @(x) exp(-x.^2).*log(x).^2;
• q = integral(fun,0,Inf)
Example
• fun = @(x,c) 1./(x.^3-2*x-c);
• q = integral(@(x)fun(x,5),0,2)
Terima Kasih
Adhi Harmoko Saputro