You are on page 1of 68

1

Mathematics for Physicist


Adhi Harmoko Saputro

Mathematics for Physicist


2

Kuis
Adhi Harmoko Saputro

Mathematics for Physicist


3

KUIS – 1 (5 menit)
1. Carilah integral persamaan
1
∫ f ( z ) dz = ∫ dz
C C (z 4
− 1,1)

sepanjang lintasan suatu unit circle berlawanan arah jarum jam

2. Carilah integral persamaan


2z −1
∫
C
2
z −2
dz

dengan C

Mathematics for Physicist


4

Solusi – 1
De Moivre’s formula

Mathematics for Physicist


5

Solusi – 1

Mathematics for Physicist


6

Solusi – 2

Mathematics for Physicist


7

Solusi – 2
Hence

The integrand is not analytic at z = 0 and z = 1, which clearly lie inside C.


Note that z0 = 0, in the first integral, and then z0 = 1 in the second.
Hence we get

Mathematics for Physicist


8

Numeric Analysis
Adhi Harmoko Saputro

Mathematics for Physicist


9

Numerical Method
• Systematic methods that are suitable for solving, numerically, the problems on computers or
calculators

Mathematics for Physicist


10

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.

Mathematics for Physicist


11

Floating-Point Form of Numbers


• Every real number is represented by a finite or an infinite sequence of decimal digits
• A fixed-point system all numbers are given with a fixed number of decimals after the
decimal point
• 62.358, 0.014, 1.000
• A floating-point
• 6.247.102, 1.735.1014, 2.000.10-2.

Mathematics for Physicist


12

Iteration
Adhi Harmoko Saputro

Mathematics for Physicist


13

Solution of Equations by Iteration


• How to find solutions of a single equation

f ( x) = 0

• An algebraic equation  the corresponding f is a polynomial

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

Mathematics for Physicist


14

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

Mathematics for Physicist


15

Fixed-Point Iteration
• Using algebraic steps to transform f ( x ) = 0
• A fixed point of g

x = g ( x)

• choose an xo and compute


x1 = g ( xo ) x2 = g ( x1 )

xn +1 = g ( xn )

Mathematics for Physicist


16

Example

Mathematics for Physicist


17

Example

Mathematics for Physicist


18

Example

Mathematics for Physicist


19

Example

Mathematics for Physicist


20

Teorema

x = g ( x)

Mathematics for Physicist


21

Example

Mathematics for Physicist


22

Example

Mathematics for Physicist


23

Example

Mathematics for Physicist


24

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

Mathematics for Physicist


25

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

• Algebraically solve Taylor’s formula

f ( xn +1 ) ≈ f ( xn ) + ( xn +1 − xn ) f ' ( xn ) =
0

Mathematics for Physicist


26

Newton’s Method

Mathematics for Physicist


27

Newton’s Method

Mathematics for Physicist


28

Example

Mathematics for Physicist


29

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.

Mathematics for Physicist


30

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

Mathematics for Physicist


31

Interpolation
Adhi Harmoko Saputro

Mathematics for Physicist


32

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

Mathematics for Physicist


33

Linear interpolation

Mathematics for Physicist


34

Quadratic Interpolation

Mathematics for Physicist


35

General Lagrange Interpolation Polynomial

Mathematics for Physicist


36

Example (Quick 1-D linear interpolation)


• yi = interp1q(x,Y,xi) returns the value of the 1-D function Y at the points of column vector
xi using linear interpolation. The vector x specifies the coordinates of the underlying
interval. The length of output yi is equal to the length of xi.

Mathematics for Physicist


37

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

Mathematics for Physicist


38

Example
x=(1:10)'; 1

y=sin(x); 0.8

0.6

x1 = x+0.5; x1 = x1(1:9); 0.4

y1 = interp1q(x,y,x1); 0.2

figure; 0

plot(x,y, 'ro'); -0.2

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

Mathematics for Physicist


39

Example (Quick 1-D linear interpolation)


x = (0:10)';
y = sin(x);
xi = (0:.25:10)';
yi = interp1q(x,y,xi);
plot(x,y,'o',xi,yi)

Mathematics for Physicist


40

Spline Interpolation
Adhi Harmoko Saputro

Mathematics for Physicist


41

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

• over the entire interval


a = xo < x1 <  < xn = b

Mathematics for Physicist


42

Spline Interpolation
• Spline interpolation is piecewise polynomial interpolation

Mathematics for Physicist


43

Conditions
• Clamped Conditions
=g ' ( xo ) f=
' ( xo ) , g ' ( xn ) f ' ( xn )

• Natural Conditions

g '' ( xo ) 0=
= o, g '' ( xn ) 0

Mathematics for Physicist


44

Example

Mathematics for Physicist


45

Example

Mathematics for Physicist


46

Example

Mathematics for Physicist


47

Example

Mathematics for Physicist


48

Spline Interpolation Matlab


• spline = spapi(knots,x,y) returns the spline f (if any) of order
• k = length(knots) - length(x)
• with knot sequence knots for which
• (*) f(x(j)) = y(:,j), all j.

Mathematics for Physicist


49

Cubic Spline Data Interpolation


• s = spline(x,y,xq) returns a vector of interpolated values s corresponding to the query points
in xq. The values of s are determined by cubic spline interpolation of x and y.
• pp = spline(x,y) returns a piecewise polynomial structure for use by ppval and the spline
utility unmkpp.

Mathematics for Physicist


50

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)

Mathematics for Physicist


51

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),'-');

Mathematics for Physicist


52

Numeric Integration and Differentiation


Adhi Harmoko Saputro

Mathematics for Physicist


53

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 )

Mathematics for Physicist


54

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

Mathematics for Physicist


55

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

Mathematics for Physicist


56

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

Mathematics for Physicist


57

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 

Mathematics for Physicist


58

Example

Mathematics for Physicist


59

Example

Mathematics for Physicist


60

Matlab Code
• fun = @(x) exp(-x.^2);
• q = integral(fun,0,1)

Mathematics for Physicist


61

Simpson’s Rule of Integration


• Divide the interval of integration a ≤ x ≤ b into an even number of equal subintervals (n =
2m)
x2
1 4 1  b−a
=J ∫ f ( x ) dx ≈ h  f o + f1 + f 2  h=
xo 3 3 3  2m

Mathematics for Physicist


62

Simpson’s Rule of Integration


b
h
∫ f ( x ) dx ≈ [ f o + 4 f1 + 2 f 2 + 4 f 3 +  + 2 f 2 m − 2 + 4 f 2 m −1 + f 2 m ]
a
3

Mathematics for Physicist


Mathematics for Physicist 63
64

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

Mathematics for Physicist


65

Numerical Integration Matlab


• q = integral(fun,xmin,xmax) numerically integrates function fun from xmin to xmax using
global adaptive quadrature and default error tolerances.
• q = integral(fun,xmin,xmax,Name,Value) specifies additional options with one or more
Name,Value pair arguments. For example, specify 'WayPoints' followed by a vector of real
or complex numbers to indicate specific points for the integrator to use.

Mathematics for Physicist


66

Example
• fun = @(x) exp(-x.^2).*log(x).^2;
• q = integral(fun,0,Inf)

Mathematics for Physicist


67

Example
• fun = @(x,c) 1./(x.^3-2*x-c);
• q = integral(@(x)fun(x,5),0,2)

Mathematics for Physicist


68

Terima Kasih
Adhi Harmoko Saputro

Mathematics for Physicist

You might also like