Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Integration and Differentiation

1/8/15 3:08 PM

Newton Cotes Formulas Replace complicated function or tabulated data


with polynomial that is easy to integrate
Trapezoid Rule
o First order polynomial; requires two data points
o I=int[a,b] (f(a) + f(b)-f(a)/b-a * (x-a)) dx
o I=(b-a) * [f(a)+f(b)]/2
o Can be divided into equally spaced sub-intervals, then the
integral is the sum of the area of each trapezoid
! In that case, for int[0,n], f(0) is added in once, f(n) is
added in once, and all others are added in twice
I=(h/2) [f(xo)+2sum(fxj) +f(xn)]
Where h=range/number of intervals
o x=[xo x1 x2], y=[f(x0) f(x1) f(x2)]
! z=trapz(x,y) or z=step size*trapz(y)
! If you enter a matrix, it will do it by columns (trapz(y,2)
if you want to do rows)
! cumtrapz(y) shows you each step; the final number is
equal to trapz(y)
Simpsons Rules
o Simpsons One-Third
! Second order polynomial; requires three data points
! I=int[xo,x2] [(x-x1)(x-x2) / (xo-x1)(xo-x2)]*f(xo) + [(xx0)(x-x2) / (x1-x0)(x1-x2)]*f(x1) + [(x-xo)(x-x1) / (x2x0)(x2-x1)]*f(x2)
! I=(h/3) [f(xo)+4f(x1)+f(x2)]
Where h=range/number of intervals
! For more accurate, can divide into subintervals
" I=(b-a)/3n [f(xo) + 4sumf(xodds) + 2sumf(xevens)
+ f(xn)]
o Simpsons Three-Eighths
! Requires four points (for three subintervals)
" I=3h/8 [f(xo)+3f(x1)+3f(x2)+f(x3)]
Where h=range/number of intervals
o You can do a combination of methods in order to make a
guess that does not directly fit any of the required points
!

For example, if you are looking for the approximation


and you have 5 subintervals, you can do a combination
of Simpsons Three-Eights and Simpsons One-Third to
make your approximation

Adaptive Quadrature Method


Q=quad(@(x) fun,a,b)

ODEs

1/8/15 3:08 PM

ODEs

dy/dt=f(y,t)
Order of ODE is based on the highest derivative
Ex m d2x/dx2+c dx/dt + kx = 0
y=dx/dt
m dy/dt + cy + kx =0
ex dy/dt=y
dy/y = dt # integrate
ln(y) =t+c

PDEs

d2u/dx2+d2y/dx2

Eulers Method
Dy/dt=f(t,y)
Y(t)=y(to)+(t-to)y(to) + (t-to)2/2! Y(to)++(t-to)n/n! yn(to)
Y(t)=y(to)+(t-to)f(to,yo)
Y1=yo+(t-to)f(to,yo)
Y2=y1+(t-to)f(t1,y1)
Ex Dy/dt=t-2y y(0)=1 h=.2
Y(1)=1+.2(0-2(1)) = .6
Runge Kutta
Yi+1=YI-1+(-)h
(-)=f(xi,yi)
th
4 order RK: y1+1=yi+(1/6ki+1/3k2+1/3k3+1/6k4)h
k1=f(ti,yi)
k2=f(ti+.5h, yi+.5kih)
k3=f(ti+.5h, yi+.5k2h)
k4=f(ti+h,yi+k3h)
For same function in Eulers
K1=0-2(1) = -2
K2=.1-2(1+.5(-2)(.2)) = -1.5
K3=.1-2(1+.5(-1.5)(.2))= -1.6

K4= .2 2(1+(-1.6)(.2))= -1.16


Y1=1+[1/6 (-2) + 1/3 (-1.5) + 1/3 (-1.6) + 1/6 (-1.16)](.2) = .688
Built-Ins
ode45(function,integrationinterval,initialconditions)
o 4th and 5th RK, adaptive step size
ex for dy/dt=t-2y, y(0)=1
ode45(@(t,y) t-2*y,[0 .2 .4 .6],1)
ode23(func,intinv,intialcond)
o 2nd and 3rd order RK
ode113

1/8/15 3:08 PM

You might also like