0% found this document useful (0 votes)
37 views2 pages

Matlab Program PDF

The document describes three numerical integration methods: 1) The trapezoidal rule for approximating definite integrals using trapezoids under the curve. 2) Simpson's 1/3 rule for approximating definite integrals using a weighted average of function values at equally spaced points. 3) The Newton-Raphson method for finding the zeros of a function iteratively using the derivative of the function.

Uploaded by

Dipu Chakraborty
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views2 pages

Matlab Program PDF

The document describes three numerical integration methods: 1) The trapezoidal rule for approximating definite integrals using trapezoids under the curve. 2) Simpson's 1/3 rule for approximating definite integrals using a weighted average of function values at equally spaced points. 3) The Newton-Raphson method for finding the zeros of a function iteratively using the derivative of the function.

Uploaded by

Dipu Chakraborty
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Trapezoidal Rule:

function [ ] = trap1( f,a,b,n )


f=input('Enterthe function: \n');
a=input('Enter the lowe limit: \n');
b=input('Enter the upper limit: \n');
n=input('Enter the subintervals: \n');
clc;
h=(b-a)/n;
sum=0;
for i=0:n-1
sum=sum+f(a+i*h)+f(a+(i+1)*h);
end
sum=(h/2)*sum;
fprintf('The integration value by Trapezoidal rule=%f',sum);

Simpson’s 1/3rd Rule:


function [ ] = simpson( f,a,b,n )
f=input('Enterthe function: \n');
a=input('Enter the lowe limit: \n');
b=input('Enter the upper limit: \n');
n=input('Enter the subintervals: \n');
clc;
h=(b-a)/n;
sum=0;
for i=0:2:n-1
sum=sum+f(a+i*h)+4*f(a+(i+1)*h)+f(a+(i+2)*h);
end
sum=(h/3)*sum;
fprintf('The integration value by Simpson,s 1/3 rd rule=%f \n',sum);

Neton-Raphson method:

function [ ] = newrap( f,f1,x0 )


f=input('Enter the function \n');
f1=input('Enter the derivative of f \n');
x0=input('initial value \n');
while(abs(f(x0))/0.0001)
x1=x0-f(x0)/f1(x0);
x0=x1;
end
fprintf('The root is =%f \n',x0);

You might also like