SlideShare a Scribd company logo
Chapter 08 & 09
NUMERICAL INTEGRATION
NUMERICAL INTEGRATION OF ORDINARY DIFFERENTIAL
EQUATION (ODE)
4/5/2016 DR. MOHAMMED DANISH/ UNIKL-MICET 1
Numerical Integration
Integration is a common mathematical operation used to
calculate area and volume, velocity from acceleration, and work
from force and displacement.
In calculus courses the integrand (the quantity to be integrated)
is usually a function. In application of science and engineering
the integrand can be a function or a set of data points.
In MATLAB built-in integration functions such as quad,
quadl and trapz are used to integrate.
The quad and quad1 commands are used for integration when
f(x) is a function, and Trapz is used when f(x) is given by data
points.
4/5/2016 DR. MOHAMMED DANISH/ UNIKL-MICET 2
The quad command
The form of the quad commend, which uses the adaptive Simpson
method of integration, is:
>>q=quad(function,a,b) or
>>q=quadl(function,a,b)
q=the value of the integral
function-the function to be integrated.
a & b, the integration limit.
4/5/2016 DR. MOHAMMED DANISH/ UNIKL-MICET 3
The quad command
The function f(x) must be written for an argument x that is a vector
(use element-by-element operations) such that it calculates the value of
the function for each element x.
The user have to make sure that the function does not have a vertical
symptote between a and b.
Quad calculates the integral with an absolute error that is smaller
than 0.0001. this number can be changed by adding an optional tol
argument to the command.
tol is a number that defines the maximum error. With larger tol
the integral is calculated less accurately but faster.
4/5/2016 DR. MOHAMMED DANISH/ UNIKL-MICET 4
Example 1
Use the numerical integration to calculate the following integral.
Sol.:
>>quad(‘x.*exp(-x.^0.8)+0.2’,0,8)
0.8
8
0
( 0.2)x
xe dx

4/5/2016 DR. MOHAMMED DANISH/ UNIKL-MICET 5
The trapz command
The trapz command can be used for integrating a function that is
given as data points.it uses the numerical trapezoidal method of
integration. The form of the command is
q=trapz(x,y)
x and y are vectors with the x and y coordinates of the points,
respectively. The two vectors must be of the same length.
4/5/2016 DR. MOHAMMED DANISH/ UNIKL-MICET 6
Ordinary differential
equations(ODE)
ODE’s describe a function y in terms of its derivatives.
The goal is to solve for y
3
2dy t y
dt t


4/5/2016 DR. MOHAMMED DANISH/ UNIKL-MICET 7
Numerical solution to ode
In general, only simple (linear) ODEs can be solved analytically.
Most interesting ODEs are nonlinear, must solve numerically.
The idea is to approximate the derivatives by subtraction.
4/5/2016 DR. MOHAMMED DANISH/ UNIKL-MICET 8
Steps for solving first order
ode
Step 1: write the problem in standard form,
3
2
1 3 4.2 1
dy t y
for t with y at t
dt t

    
4/5/2016 DR. MOHAMMED DANISH/ UNIKL-MICET 9
Steps for solving first order
ode
Step 2: Create a user-defined function (in a function file) or an
anonymous function.
Create function in .m file, for example, the user defined function
is:
function dydt=ODEexpl(t,y)
dydt=(t^3-2*y)/t;
When anonymous function is used, it can be defined in the
command window, or within the script file.
>>ode1=@(t,y)(t^3-2*y)/t
ode1 =
@(t,y)(t^3-28y)/t
4/5/2016 DR. MOHAMMED DANISH/ UNIKL-MICET 10
Steps for solving first order
ode
Step 3: select a method of solution,
Many numerical methods have been developed to solve the
first order ODEs, and several of the methods are available
in as built-in functions in MATLAB.
Examples: ode45, ode23, ode113, ode15s,
ode23s, ode23t,ode23tb
4/5/2016 DR. MOHAMMED DANISH/ UNIKL-MICET 11
Steps for solving first order
ode
Step 4: Solve the ODE
The form of the command that is used to solve an initial
value ODE problem is the same for all the solvers and for
all the equations that are solved. The form is:
>>[t,y]=solver_name(ODEfun,tspan,yo)
Solver_name: Is the name of solver such as, ode45 or ode23
ODEfun:The function that calculates the dy/dt.
tspan: A vector that specify the interval of solution.
yo: Intial value of y
[t,y]:The output which is the solution of the ODE.
4/5/2016 DR. MOHAMMED DANISH/ UNIKL-MICET 12
Example 2
Solve the following ODE,
3
2
1 3 4.2 1
dy t y
for t with y at t
dt t

    
4/5/2016 DR. MOHAMMED DANISH/ UNIKL-MICET 13
solution
function dydt=ODEexpl(t,y)
dydt=(t^3-2*y)/t;
>>[t,y]=ode45(@ODEexp1,[1:0.5:3],4.2)
t =
1.0000
1.5000
2.0000
2.5000
3.0000
y =
4.2000
2.4528
2.6000
3.7650
5.8444
4/5/2016 DR. MOHAMMED DANISH/ UNIKL-MICET 14
solution
The name of the user defined function in step 2 is
ODEexp1. to show the solution, the problem is solved
again below using tspan with smaller spacing, and the
solution is plotted with the plot command.
>>[t,y]=ode45(@ODEexp1,[1:0.01:3],4.2)
>>plot(t,y)
>>xlabel(‘t’), ylabel(‘y’)
4/5/2016 DR. MOHAMMED DANISH/ UNIKL-MICET 15
Slide ends here
Dr. Mohammed Danish
Senior lecturer, Malaysian Institute of Chemical and Bioengineering Technology (MICET), UniKL, Alor
Gajah, 78000 Melaka.
4/5/2016 DR. MOHAMMED DANISH/ UNIKL-MICET 16

More Related Content

PPTX
Interpolation and its applications
PDF
2. polynomial interpolation
PDF
Algorithm of some numerical /computational methods
PPT
Numerical Methods
PPTX
Classificationand different algorithm
PPT
Math Functions in C Scanf Printf
PPT
Recursion - Algorithms and Data Structures
PPTX
Asymptotic Notation and Data Structures
Interpolation and its applications
2. polynomial interpolation
Algorithm of some numerical /computational methods
Numerical Methods
Classificationand different algorithm
Math Functions in C Scanf Printf
Recursion - Algorithms and Data Structures
Asymptotic Notation and Data Structures

What's hot (19)

PPTX
APPLICATION OF NUMERICAL METHODS IN SMALL SIZE
DOC
algorithm Unit 3
PPT
multi threaded and distributed algorithms
PPT
CS8451 - Design and Analysis of Algorithms
PPT
Chapter 7 ds
PPTX
Programming in python
PPTX
Signal Processing Assignment Help
PPT
Chapter 4 ds
PPTX
February 10 2016
PDF
design and analysis of algorithm
KEY
Function Basics Math Wiki
PPTX
Lectue five
PPTX
Recursion(Advanced data structure)
PPTX
Divide and Conquer - Part II - Quickselect and Closest Pair of Points
PPT
DESIGN AND ANALYSIS OF ALGORITHMS
PPTX
Big o notation
PPT
Chapter 5 ds
PPTX
Greedy Algorithms
PDF
QUESTION BANK FOR ANNA UNNIVERISTY SYLLABUS
APPLICATION OF NUMERICAL METHODS IN SMALL SIZE
algorithm Unit 3
multi threaded and distributed algorithms
CS8451 - Design and Analysis of Algorithms
Chapter 7 ds
Programming in python
Signal Processing Assignment Help
Chapter 4 ds
February 10 2016
design and analysis of algorithm
Function Basics Math Wiki
Lectue five
Recursion(Advanced data structure)
Divide and Conquer - Part II - Quickselect and Closest Pair of Points
DESIGN AND ANALYSIS OF ALGORITHMS
Big o notation
Chapter 5 ds
Greedy Algorithms
QUESTION BANK FOR ANNA UNNIVERISTY SYLLABUS
Ad

Similar to 08-09 Chapter numerical integration (20)

DOCX
MATLAB sessions Laboratory 4MAT 275 Laboratory 4MATLAB .docx
PDF
Problem solving using computers - Unit 1 - Study material
PPT
MATLAB ODE
DOCX
Signals And Systems Lab Manual, R18 Batch
PPT
Chapter 2 ds
PPT
Basic concept of MATLAB.ppt
PPTX
03 Chapter MATLAB finite precision arithmatic
PDF
Dsp manual completed2
PDF
A MATLAB project on LCR circuits
PPTX
Runge Kutta Method
PDF
Recursion in Java
PPTX
Ch3(1).pptxbbbbbbbbbbbbbbbbbbbhhhhhhhhhh
PPTX
PPTX
02 MATLAB programming
PPT
Introduction to matlab
PDF
Book.pdf01_Intro.ppt algorithm for preperation stu used
PPTX
VCE Unit 01 (2).pptx
PPT
Matlab II
PPTX
Intro to super. advance algorithm..pptx
DOC
Digital Signal Processing Lab Manual
MATLAB sessions Laboratory 4MAT 275 Laboratory 4MATLAB .docx
Problem solving using computers - Unit 1 - Study material
MATLAB ODE
Signals And Systems Lab Manual, R18 Batch
Chapter 2 ds
Basic concept of MATLAB.ppt
03 Chapter MATLAB finite precision arithmatic
Dsp manual completed2
A MATLAB project on LCR circuits
Runge Kutta Method
Recursion in Java
Ch3(1).pptxbbbbbbbbbbbbbbbbbbbhhhhhhhhhh
02 MATLAB programming
Introduction to matlab
Book.pdf01_Intro.ppt algorithm for preperation stu used
VCE Unit 01 (2).pptx
Matlab II
Intro to super. advance algorithm..pptx
Digital Signal Processing Lab Manual
Ad

More from Dr. Mohammed Danish (15)

PPTX
Instrumental method of analysis Oil and Fat(Unit 7 b)
PPTX
Analysis of oil and Fat(Unit 7)
PPTX
Non edible application of oil and Fat (Unit 6 b)
PPTX
Oil and Fat edible applications (Unit 6 a)
PPTX
Fatty acid reaction and derivatives (Unit 5 b)
PPTX
Fatty acid clusters (Unit 5 a)
PPTX
Production of Glycerin (Unit 4 b)
PPTX
Fatty Acid Isolation (Unit 4 a)
PPTX
Processing of edible oil (Unit 3)
PPTX
Chemical and Physical properties of Oil and Fat (Unit 2)
PPTX
Introduction of Edible oils (Unit 1)
PPTX
01 Chapter MATLAB introduction
PPTX
06-07 Chapter interpolation in MATLAB
PPTX
05 Chapter MATLAB Differntial equations
PPTX
04 Chapter MATLAB linear algebra review
Instrumental method of analysis Oil and Fat(Unit 7 b)
Analysis of oil and Fat(Unit 7)
Non edible application of oil and Fat (Unit 6 b)
Oil and Fat edible applications (Unit 6 a)
Fatty acid reaction and derivatives (Unit 5 b)
Fatty acid clusters (Unit 5 a)
Production of Glycerin (Unit 4 b)
Fatty Acid Isolation (Unit 4 a)
Processing of edible oil (Unit 3)
Chemical and Physical properties of Oil and Fat (Unit 2)
Introduction of Edible oils (Unit 1)
01 Chapter MATLAB introduction
06-07 Chapter interpolation in MATLAB
05 Chapter MATLAB Differntial equations
04 Chapter MATLAB linear algebra review

Recently uploaded (20)

PPTX
Database Infoormation System (DBIS).pptx
PDF
BF and FI - Blockchain, fintech and Financial Innovation Lesson 2.pdf
PPTX
Acceptance and paychological effects of mandatory extra coach I classes.pptx
PPTX
advance b rammar.pptxfdgdfgdfsgdfgsdgfdfgdfgsdfgdfgdfg
PPTX
Qualitative Qantitative and Mixed Methods.pptx
PPTX
IBA_Chapter_11_Slides_Final_Accessible.pptx
PDF
Mega Projects Data Mega Projects Data
PPT
Quality review (1)_presentation of this 21
PDF
TRAFFIC-MANAGEMENT-AND-ACCIDENT-INVESTIGATION-WITH-DRIVING-PDF-FILE.pdf
PDF
Lecture1 pattern recognition............
PPTX
climate analysis of Dhaka ,Banglades.pptx
PPTX
Microsoft-Fabric-Unifying-Analytics-for-the-Modern-Enterprise Solution.pptx
PPTX
Supervised vs unsupervised machine learning algorithms
PPTX
Introduction to machine learning and Linear Models
PDF
Clinical guidelines as a resource for EBP(1).pdf
PPTX
iec ppt-1 pptx icmr ppt on rehabilitation.pptx
PPT
Miokarditis (Inflamasi pada Otot Jantung)
PPTX
1_Introduction to advance data techniques.pptx
PDF
22.Patil - Early prediction of Alzheimer’s disease using convolutional neural...
PPTX
mbdjdhjjodule 5-1 rhfhhfjtjjhafbrhfnfbbfnb
Database Infoormation System (DBIS).pptx
BF and FI - Blockchain, fintech and Financial Innovation Lesson 2.pdf
Acceptance and paychological effects of mandatory extra coach I classes.pptx
advance b rammar.pptxfdgdfgdfsgdfgsdgfdfgdfgsdfgdfgdfg
Qualitative Qantitative and Mixed Methods.pptx
IBA_Chapter_11_Slides_Final_Accessible.pptx
Mega Projects Data Mega Projects Data
Quality review (1)_presentation of this 21
TRAFFIC-MANAGEMENT-AND-ACCIDENT-INVESTIGATION-WITH-DRIVING-PDF-FILE.pdf
Lecture1 pattern recognition............
climate analysis of Dhaka ,Banglades.pptx
Microsoft-Fabric-Unifying-Analytics-for-the-Modern-Enterprise Solution.pptx
Supervised vs unsupervised machine learning algorithms
Introduction to machine learning and Linear Models
Clinical guidelines as a resource for EBP(1).pdf
iec ppt-1 pptx icmr ppt on rehabilitation.pptx
Miokarditis (Inflamasi pada Otot Jantung)
1_Introduction to advance data techniques.pptx
22.Patil - Early prediction of Alzheimer’s disease using convolutional neural...
mbdjdhjjodule 5-1 rhfhhfjtjjhafbrhfnfbbfnb

08-09 Chapter numerical integration

  • 1. Chapter 08 & 09 NUMERICAL INTEGRATION NUMERICAL INTEGRATION OF ORDINARY DIFFERENTIAL EQUATION (ODE) 4/5/2016 DR. MOHAMMED DANISH/ UNIKL-MICET 1
  • 2. Numerical Integration Integration is a common mathematical operation used to calculate area and volume, velocity from acceleration, and work from force and displacement. In calculus courses the integrand (the quantity to be integrated) is usually a function. In application of science and engineering the integrand can be a function or a set of data points. In MATLAB built-in integration functions such as quad, quadl and trapz are used to integrate. The quad and quad1 commands are used for integration when f(x) is a function, and Trapz is used when f(x) is given by data points. 4/5/2016 DR. MOHAMMED DANISH/ UNIKL-MICET 2
  • 3. The quad command The form of the quad commend, which uses the adaptive Simpson method of integration, is: >>q=quad(function,a,b) or >>q=quadl(function,a,b) q=the value of the integral function-the function to be integrated. a & b, the integration limit. 4/5/2016 DR. MOHAMMED DANISH/ UNIKL-MICET 3
  • 4. The quad command The function f(x) must be written for an argument x that is a vector (use element-by-element operations) such that it calculates the value of the function for each element x. The user have to make sure that the function does not have a vertical symptote between a and b. Quad calculates the integral with an absolute error that is smaller than 0.0001. this number can be changed by adding an optional tol argument to the command. tol is a number that defines the maximum error. With larger tol the integral is calculated less accurately but faster. 4/5/2016 DR. MOHAMMED DANISH/ UNIKL-MICET 4
  • 5. Example 1 Use the numerical integration to calculate the following integral. Sol.: >>quad(‘x.*exp(-x.^0.8)+0.2’,0,8) 0.8 8 0 ( 0.2)x xe dx  4/5/2016 DR. MOHAMMED DANISH/ UNIKL-MICET 5
  • 6. The trapz command The trapz command can be used for integrating a function that is given as data points.it uses the numerical trapezoidal method of integration. The form of the command is q=trapz(x,y) x and y are vectors with the x and y coordinates of the points, respectively. The two vectors must be of the same length. 4/5/2016 DR. MOHAMMED DANISH/ UNIKL-MICET 6
  • 7. Ordinary differential equations(ODE) ODE’s describe a function y in terms of its derivatives. The goal is to solve for y 3 2dy t y dt t   4/5/2016 DR. MOHAMMED DANISH/ UNIKL-MICET 7
  • 8. Numerical solution to ode In general, only simple (linear) ODEs can be solved analytically. Most interesting ODEs are nonlinear, must solve numerically. The idea is to approximate the derivatives by subtraction. 4/5/2016 DR. MOHAMMED DANISH/ UNIKL-MICET 8
  • 9. Steps for solving first order ode Step 1: write the problem in standard form, 3 2 1 3 4.2 1 dy t y for t with y at t dt t       4/5/2016 DR. MOHAMMED DANISH/ UNIKL-MICET 9
  • 10. Steps for solving first order ode Step 2: Create a user-defined function (in a function file) or an anonymous function. Create function in .m file, for example, the user defined function is: function dydt=ODEexpl(t,y) dydt=(t^3-2*y)/t; When anonymous function is used, it can be defined in the command window, or within the script file. >>ode1=@(t,y)(t^3-2*y)/t ode1 = @(t,y)(t^3-28y)/t 4/5/2016 DR. MOHAMMED DANISH/ UNIKL-MICET 10
  • 11. Steps for solving first order ode Step 3: select a method of solution, Many numerical methods have been developed to solve the first order ODEs, and several of the methods are available in as built-in functions in MATLAB. Examples: ode45, ode23, ode113, ode15s, ode23s, ode23t,ode23tb 4/5/2016 DR. MOHAMMED DANISH/ UNIKL-MICET 11
  • 12. Steps for solving first order ode Step 4: Solve the ODE The form of the command that is used to solve an initial value ODE problem is the same for all the solvers and for all the equations that are solved. The form is: >>[t,y]=solver_name(ODEfun,tspan,yo) Solver_name: Is the name of solver such as, ode45 or ode23 ODEfun:The function that calculates the dy/dt. tspan: A vector that specify the interval of solution. yo: Intial value of y [t,y]:The output which is the solution of the ODE. 4/5/2016 DR. MOHAMMED DANISH/ UNIKL-MICET 12
  • 13. Example 2 Solve the following ODE, 3 2 1 3 4.2 1 dy t y for t with y at t dt t       4/5/2016 DR. MOHAMMED DANISH/ UNIKL-MICET 13
  • 15. solution The name of the user defined function in step 2 is ODEexp1. to show the solution, the problem is solved again below using tspan with smaller spacing, and the solution is plotted with the plot command. >>[t,y]=ode45(@ODEexp1,[1:0.01:3],4.2) >>plot(t,y) >>xlabel(‘t’), ylabel(‘y’) 4/5/2016 DR. MOHAMMED DANISH/ UNIKL-MICET 15
  • 16. Slide ends here Dr. Mohammed Danish Senior lecturer, Malaysian Institute of Chemical and Bioengineering Technology (MICET), UniKL, Alor Gajah, 78000 Melaka. 4/5/2016 DR. MOHAMMED DANISH/ UNIKL-MICET 16