SlideShare a Scribd company logo
1 of 8
University of Engineering & Technology LHR
(FAISALABAD CAMPUS) by FAISAL SAEED
Trapezoidal Rule
function trapezoidalrule
x0=input('Enter the value of initial input: ');
xn=input ('Enter the value of final input: ');
n=input ('Enter the total no of intervals : ');
h=(xn-x0)/n
f=input('Enter the function to be evaluated:');
sum=0;
for i=x0:h:xn
if(i==x0 || i==xn)
continue;
end
sum=sum +f(i);
end
sum=sum*2;
trapezoidal=h/2*(f(x0)+f(xn)+sum)
end
Output:-
Simpsons 1/3 Rule
function simpsonsrule
x0=input('Enter the value of initial input: ');
xn=input ('Enter the value of final input: ');
n=input ('Enter the total no of intervals : ');
h=(xn-x0)/n
f=input('Enter the function to be evaluated:');
sum=f(x0)+f(xn)+4*f(xn-h);
for count=1:2:n-3;
sum=sum+4*f(x0+count*h)+2*f(x0+(count+1)*h);
A=h*sum/3;
end
fprintf('integration is %d n ',A);
end
Output:-
Simpsons 3/8 Rule
function simpsonsrule
x0=input('Enter the value of initial input: ');
xn=input ('Enter the value of final input: ');
n=input ('Enter the total no of intervals : ');
h=(xn-x0)/n
f=input('Enter the function to be evaluated:');
sum=f(x0)+f(xn);
for count=1:n-1;
if (mod(count,3)==0)
sum=sum+2*f(x0+count*h);
else
sum=sum+3*f(x0+count*h);
end
end
A=sum*3*h/8;
fprintf('integration is %d n ',A);
end
Output:-
Booles Rule
function boolesrule
x0=input('Enter the value of initial input: ');
xn=input ('Enter the value of final input: ');
n=input ('Enter the total no of intervals : ');
h=(xn-x0)/n
f=input('Enter the function to be evaluated:');
sum=7*(f(x0)+f(xn))+32*f(xn-h);
for count=1:2:n-3;
sum=sum+32*f(x0+count*h)+12*f(x0+(count+1)*h);
A=2*h*sum/45;
end
fprintf('integration is %d n ',A);
end
Output:-
Weddles Rule
function weddlesrule
x0=input('Enter the value of initial input: ');
xn=input ('Enter the value of final input: ');
n=input ('Enter the total no of intervals : ');
h=(xn-x0)/n
f=input('Enter the function to be evaluated:');
sum=0;
sum1=0;
sum2=0;
for count=0:2:n;
sum=sum +f(count*h);
end
for count=1:4:n-1;
sum1=sum1+5*f(count*h);
end
for count=3:4:n-1;
sum2=sum2+6*f(count*h);
end
integrationis=3*h*(sum+sum1+sum2)/10
end
Output:-
Rectangular Rule
function rectangularrule
x0=input('Enter the value of initial input: ');
xn=input ('Enter the value of final input: ');
n=input ('Enter the total no of intervals : ');
h=(xn-x0)/n
f=input('Enter the function to be evaluated:');
sum=0;
for i=x0:h:xn
sum=f(i);
end
A=h*sum
end
Output:-
Newton cotes method

More Related Content

What's hot (19)

week-18x
week-18xweek-18x
week-18x
 
week-10x
week-10xweek-10x
week-10x
 
week-11x
week-11xweek-11x
week-11x
 
week-1x
week-1xweek-1x
week-1x
 
Euler method in c
Euler method in cEuler method in c
Euler method in c
 
V34 numeric function-c
V34  numeric function-cV34  numeric function-c
V34 numeric function-c
 
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
 
New microsoft office word document (2)
New microsoft office word document (2)New microsoft office word document (2)
New microsoft office word document (2)
 
Comp102 lec 5.0
Comp102   lec 5.0Comp102   lec 5.0
Comp102 lec 5.0
 
week-17x
week-17xweek-17x
week-17x
 
Program presentation
Program presentationProgram presentation
Program presentation
 
Palindrome number program c
Palindrome number program cPalindrome number program c
Palindrome number program c
 
week-4x
week-4xweek-4x
week-4x
 
Functions
FunctionsFunctions
Functions
 
Bcsl 033 data and file structures lab s1-4
Bcsl 033 data and file structures lab s1-4Bcsl 033 data and file structures lab s1-4
Bcsl 033 data and file structures lab s1-4
 
Infix to-postfix examples
Infix to-postfix examplesInfix to-postfix examples
Infix to-postfix examples
 
Add digits of number in c
Add digits of number in c Add digits of number in c
Add digits of number in c
 
Tercer Punto
Tercer PuntoTercer Punto
Tercer Punto
 
1 (1)
1 (1)1 (1)
1 (1)
 

Similar to Newton cotes method

L25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptxL25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptxhappycocoman
 
I wrote the following change it to having a header, main and cpp fi.pdf
I wrote the following change it to having a header, main and cpp fi.pdfI wrote the following change it to having a header, main and cpp fi.pdf
I wrote the following change it to having a header, main and cpp fi.pdfrishteygallery
 
Interpolation graph c++
Interpolation graph c++Interpolation graph c++
Interpolation graph c++rpiitcbme
 
Go: It's Not Just For Google
Go: It's Not Just For GoogleGo: It's Not Just For Google
Go: It's Not Just For GoogleEleanor McHugh
 
import java.util.Scanner;public class HornersPolynomial {   .pdf
import java.util.Scanner;public class HornersPolynomial {   .pdfimport java.util.Scanner;public class HornersPolynomial {   .pdf
import java.util.Scanner;public class HornersPolynomial {   .pdfaptex1
 
Assignment on Numerical Method C Code
Assignment on Numerical Method C CodeAssignment on Numerical Method C Code
Assignment on Numerical Method C CodeSyed Ahmed Zaki
 
Programming ppt files (final)
Programming ppt files (final)Programming ppt files (final)
Programming ppt files (final)yap_raiza
 
TI1220 Lecture 6: First-class Functions
TI1220 Lecture 6: First-class FunctionsTI1220 Lecture 6: First-class Functions
TI1220 Lecture 6: First-class FunctionsEelco Visser
 
Shapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop conceptShapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop conceptkinan keshkeh
 
Operator overloading (binary)
Operator overloading (binary)Operator overloading (binary)
Operator overloading (binary)Ramish Suleman
 
introduction to c programming and C History.pptx
introduction to c programming and C History.pptxintroduction to c programming and C History.pptx
introduction to c programming and C History.pptxManojKhadilkar1
 
#include stdio.h #include string.h Function swaps to po.pdf
#include stdio.h #include string.h  Function swaps to po.pdf#include stdio.h #include string.h  Function swaps to po.pdf
#include stdio.h #include string.h Function swaps to po.pdfgalagirishp
 
Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...Mario Fusco
 
Please need help on C++ language.Infix to Postfix) Write a program.pdf
Please need help on C++ language.Infix to Postfix) Write a program.pdfPlease need help on C++ language.Infix to Postfix) Write a program.pdf
Please need help on C++ language.Infix to Postfix) Write a program.pdfpristiegee
 
Shapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop conceptShapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop conceptkinan keshkeh
 
C++ QUICK REFERENCE.pdf
C++ QUICK REFERENCE.pdfC++ QUICK REFERENCE.pdf
C++ QUICK REFERENCE.pdffqerwqdfad
 

Similar to Newton cotes method (20)

L25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptxL25-L26-Parameter passing techniques.pptx
L25-L26-Parameter passing techniques.pptx
 
I wrote the following change it to having a header, main and cpp fi.pdf
I wrote the following change it to having a header, main and cpp fi.pdfI wrote the following change it to having a header, main and cpp fi.pdf
I wrote the following change it to having a header, main and cpp fi.pdf
 
Interpolation graph c++
Interpolation graph c++Interpolation graph c++
Interpolation graph c++
 
Go: It's Not Just For Google
Go: It's Not Just For GoogleGo: It's Not Just For Google
Go: It's Not Just For Google
 
import java.util.Scanner;public class HornersPolynomial {   .pdf
import java.util.Scanner;public class HornersPolynomial {   .pdfimport java.util.Scanner;public class HornersPolynomial {   .pdf
import java.util.Scanner;public class HornersPolynomial {   .pdf
 
Assignment on Numerical Method C Code
Assignment on Numerical Method C CodeAssignment on Numerical Method C Code
Assignment on Numerical Method C Code
 
Programming ppt files (final)
Programming ppt files (final)Programming ppt files (final)
Programming ppt files (final)
 
TI1220 Lecture 6: First-class Functions
TI1220 Lecture 6: First-class FunctionsTI1220 Lecture 6: First-class Functions
TI1220 Lecture 6: First-class Functions
 
Shapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop conceptShapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop concept
 
Operator overloading (binary)
Operator overloading (binary)Operator overloading (binary)
Operator overloading (binary)
 
introduction to c programming and C History.pptx
introduction to c programming and C History.pptxintroduction to c programming and C History.pptx
introduction to c programming and C History.pptx
 
#include stdio.h #include string.h Function swaps to po.pdf
#include stdio.h #include string.h  Function swaps to po.pdf#include stdio.h #include string.h  Function swaps to po.pdf
#include stdio.h #include string.h Function swaps to po.pdf
 
Es84
Es84Es84
Es84
 
Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...Laziness, trampolines, monoids and other functional amenities: this is not yo...
Laziness, trampolines, monoids and other functional amenities: this is not yo...
 
VTU Data Structures Lab Manual
VTU Data Structures Lab ManualVTU Data Structures Lab Manual
VTU Data Structures Lab Manual
 
Please need help on C++ language.Infix to Postfix) Write a program.pdf
Please need help on C++ language.Infix to Postfix) Write a program.pdfPlease need help on C++ language.Infix to Postfix) Write a program.pdf
Please need help on C++ language.Infix to Postfix) Write a program.pdf
 
C Language Lecture 17
C Language Lecture 17C Language Lecture 17
C Language Lecture 17
 
Struct examples
Struct examplesStruct examples
Struct examples
 
Shapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop conceptShapes and calculate (area and contour) / C++ oop concept
Shapes and calculate (area and contour) / C++ oop concept
 
C++ QUICK REFERENCE.pdf
C++ QUICK REFERENCE.pdfC++ QUICK REFERENCE.pdf
C++ QUICK REFERENCE.pdf
 

Recently uploaded

Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 

Recently uploaded (20)

Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 

Newton cotes method

  • 1. University of Engineering & Technology LHR (FAISALABAD CAMPUS) by FAISAL SAEED Trapezoidal Rule function trapezoidalrule x0=input('Enter the value of initial input: '); xn=input ('Enter the value of final input: '); n=input ('Enter the total no of intervals : '); h=(xn-x0)/n f=input('Enter the function to be evaluated:'); sum=0; for i=x0:h:xn if(i==x0 || i==xn) continue; end sum=sum +f(i); end sum=sum*2; trapezoidal=h/2*(f(x0)+f(xn)+sum) end
  • 2. Output:- Simpsons 1/3 Rule function simpsonsrule x0=input('Enter the value of initial input: '); xn=input ('Enter the value of final input: '); n=input ('Enter the total no of intervals : '); h=(xn-x0)/n f=input('Enter the function to be evaluated:'); sum=f(x0)+f(xn)+4*f(xn-h); for count=1:2:n-3; sum=sum+4*f(x0+count*h)+2*f(x0+(count+1)*h); A=h*sum/3; end fprintf('integration is %d n ',A); end
  • 4. Simpsons 3/8 Rule function simpsonsrule x0=input('Enter the value of initial input: '); xn=input ('Enter the value of final input: '); n=input ('Enter the total no of intervals : '); h=(xn-x0)/n f=input('Enter the function to be evaluated:'); sum=f(x0)+f(xn); for count=1:n-1; if (mod(count,3)==0) sum=sum+2*f(x0+count*h); else sum=sum+3*f(x0+count*h); end end A=sum*3*h/8; fprintf('integration is %d n ',A); end Output:-
  • 5. Booles Rule function boolesrule x0=input('Enter the value of initial input: '); xn=input ('Enter the value of final input: '); n=input ('Enter the total no of intervals : '); h=(xn-x0)/n f=input('Enter the function to be evaluated:'); sum=7*(f(x0)+f(xn))+32*f(xn-h); for count=1:2:n-3; sum=sum+32*f(x0+count*h)+12*f(x0+(count+1)*h); A=2*h*sum/45; end fprintf('integration is %d n ',A); end Output:-
  • 6. Weddles Rule function weddlesrule x0=input('Enter the value of initial input: '); xn=input ('Enter the value of final input: '); n=input ('Enter the total no of intervals : '); h=(xn-x0)/n f=input('Enter the function to be evaluated:'); sum=0; sum1=0; sum2=0; for count=0:2:n; sum=sum +f(count*h); end for count=1:4:n-1; sum1=sum1+5*f(count*h); end for count=3:4:n-1; sum2=sum2+6*f(count*h); end integrationis=3*h*(sum+sum1+sum2)/10 end
  • 7. Output:- Rectangular Rule function rectangularrule x0=input('Enter the value of initial input: '); xn=input ('Enter the value of final input: '); n=input ('Enter the total no of intervals : '); h=(xn-x0)/n f=input('Enter the function to be evaluated:'); sum=0; for i=x0:h:xn sum=f(i); end A=h*sum end Output:-