# MATLAB - Suranaree University of Technology MATLA B Week 7 Numerical Integration and Differentiation x h f x1 dy f lim 1 dx h 0

h y=f(x) dy f(x1) h=dx x1 x1+h x

MATLAB diff(x) element x [x(2)-x(1), x(3)-x(2),x(2)-x(1), x(3)-x(2), ,x(n)-x(n-1)] diff(x,n) element x n A

A MATLAB 1 x d cos x + sinsin(x) cos(x) dx x

x y d f x, y MATLAB 2x y 2 dx 2

x y MATLAB polyder(A) A

a Q f x dx b f(x) a

b x (Trapezoidal rule) h Q f x f x 2 f x 2

k1 0 n k k 1 f(x) b

a x0 x1 xi xn b a h n x

(Trapezoidal rule) trapz(x,y) y cumtrapz(x,y) y

(Trapezoidal rule) trapezodalc (Symsons rule) n n 1 n 2 h Q f x0 f xn 4 f xk 2 f xk 3 b a

h n k 1, 3, 5 k 2 , 4 , 6 (Symsons rule) Q=quad(F,a,b) F

a b Symsons rule (Symsons rule) -

Q=quad8(F,a,b) F a b Newton-Cotes error = 10-3 () Q=quadl(F,a,b) F a b Newton-Cotes error = 10-6 -

- int symbolic int(E) E int(E,v) E

v int(E,a,b) E a b int(E,v,a,b) E v a b

A t 3 t 1. 2. A(t) t=1.85 A(t) 1 pi

2 0.8-1.2 2t x 1 x e 0 cos 3t 3

0 1. 2. 2t 2

e cos 3t x 1 x 1. 2. sin xt 3.