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

DOCX
Faisal
PPTX
Formalization Machines and Sastes
DOCX
Monte-carlo sim pricing EU call
DOCX
PYTHON. AM CALL Pricing Trees
DOCX
Matlab code for secant method
DOCX
Maple Code for Steepest Descent
PDF
A formalization of complex event stream processing
Faisal
Formalization Machines and Sastes
Monte-carlo sim pricing EU call
PYTHON. AM CALL Pricing Trees
Matlab code for secant method
Maple Code for Steepest Descent
A formalization of complex event stream processing

What's hot (19)

DOCX
Euler method in c
PPTX
V34 numeric function-c
PDF
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
DOCX
New microsoft office word document (2)
PPT
Comp102 lec 5.0
PPTX
Program presentation
DOC
Palindrome number program c
PDF
Functions
PDF
Bcsl 033 data and file structures lab s1-4
DOC
Infix to-postfix examples
DOC
Add digits of number in c
DOCX
Tercer Punto
DOCX
1 (1)
Euler method in c
V34 numeric function-c
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
New microsoft office word document (2)
Comp102 lec 5.0
Program presentation
Palindrome number program c
Functions
Bcsl 033 data and file structures lab s1-4
Infix to-postfix examples
Add digits of number in c
Tercer Punto
1 (1)
Ad

Similar to Newton cotes method (20)

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

Recently uploaded (20)

PPTX
Lesson notes of climatology university.
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPTX
GDM (1) (1).pptx small presentation for students
PDF
O7-L3 Supply Chain Operations - ICLT Program
PPTX
Cell Types and Its function , kingdom of life
PDF
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
PDF
A systematic review of self-coping strategies used by university students to ...
PPTX
master seminar digital applications in india
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
Orientation - ARALprogram of Deped to the Parents.pptx
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
Lesson notes of climatology university.
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
FourierSeries-QuestionsWithAnswers(Part-A).pdf
GDM (1) (1).pptx small presentation for students
O7-L3 Supply Chain Operations - ICLT Program
Cell Types and Its function , kingdom of life
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
A systematic review of self-coping strategies used by university students to ...
master seminar digital applications in india
Abdominal Access Techniques with Prof. Dr. R K Mishra
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Orientation - ARALprogram of Deped to the Parents.pptx
human mycosis Human fungal infections are called human mycosis..pptx
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
202450812 BayCHI UCSC-SV 20250812 v17.pptx
Final Presentation General Medicine 03-08-2024.pptx
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx

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