SlideShare a Scribd company logo
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

Euler method in c
Euler method in cEuler method in c
Euler method in c
Subir Halder
 
V34 numeric function-c
V34  numeric function-cV34  numeric function-c
V34 numeric function-c
Dhirendra Chauhan
 
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 ...
DR B.Surendiran .
 
New microsoft office word document (2)
New microsoft office word document (2)New microsoft office word document (2)
New microsoft office word document (2)
Syed Umair
 
Program presentation
Program presentationProgram presentation
Program presentation
MdAlauddinRidoy
 
Palindrome number program c
Palindrome number program cPalindrome number program c
Palindrome number program c
mohdshanu
 
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
Dr. Loganathan R
 
Infix to-postfix examples
Infix to-postfix examplesInfix to-postfix examples
Infix to-postfix examplesmua99
 
Add digits of number in c
Add digits of number in c Add digits of number in c
Add digits of number in c
mohdshanu
 
1 (1)
1 (1)1 (1)
1 (1)
Krish Na
 

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.pptx
happycocoman
 
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
rishteygallery
 
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 Google
Eleanor 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 {   .pdf
aptex1
 
Assignment on Numerical Method C Code
Assignment on Numerical Method C CodeAssignment on Numerical Method C Code
Assignment on Numerical Method C Code
Syed 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 concept
kinan 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.pptx
ManojKhadilkar1
 
#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
galagirishp
 
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
 
VTU Data Structures Lab Manual
VTU Data Structures Lab ManualVTU Data Structures Lab Manual
VTU Data Structures Lab Manual
Nithin Kumar,VVCE, Mysuru
 
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
pristiegee
 
C Language Lecture 17
C Language Lecture 17C Language Lecture 17
C Language Lecture 17
Shahzaib Ajmal
 
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
kinan keshkeh
 
CppQuickRef.pdf
CppQuickRef.pdfCppQuickRef.pdf
CppQuickRef.pdf
kurimaru1
 

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
 
CppQuickRef.pdf
CppQuickRef.pdfCppQuickRef.pdf
CppQuickRef.pdf
 

Recently uploaded

Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
Celine George
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
Fundacja Rozwoju Społeczeństwa Przedsiębiorczego
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
AzmatAli747758
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
Vivekanand Anglo Vedic Academy
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
Excellence Foundation for South Sudan
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 

Recently uploaded (20)

Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 

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:-