Question

Throughout this homework, rz)-e-5s sin 릎 sin siIT, unless stated otherwise. Q1 The Booles quadrature rule is Use the midpoin

0 0
Add a comment Improve this question Transcribed image text
Answer #1

`Hey,

Note: Brother in case of any queries, just comment in box I would be very happy to assist all your queries

clc
clear all
f=@(x) exp(-5*x)*sin(1/x)*sin(1/sin(1/x));
a=0.19;
b=0.29;
If=0.02115910278025609;
n=5;
disp('Mid point inegral is');
I=0;
h=(b-a)/n;
for i=1:n
I=I+h*f(a+(2*i-1)*h/2);
end
disp(I)
disp('Error is');
abs(I-If)
disp('Trapezoidal inegral is');
I=trapezoid(f,a,b,n)
disp('Error is');
abs(I-If)
disp('Simpson inegral is');
I=SimpsonComp(f,a,b,n)
disp('Error is');
abs(I-If)
disp('Boole inegral is');
I=(b-a)/90*(7*f(a)+32*f((3*a+b)/4)+12*f((a+b)/2)+32*f((a+3*b)/4)+7*f(b))
disp('Error is');
abs(I-If)

function I = trapezoid(func,a,b,n)

% I = trap(func,a,b,n):

% multiple-application trapezoidal rule.

% input:

% func = name of function to be integrated

% a, b = integration limits

% n = number of segments

% output:

% I = integral estimate

x = a;

h = (b - a)/n;

s = feval(func,a);

for i = 1 : n-1

x = x + h;

s = s + 2*feval(func,x);

end

s = s + feval(func,b);

I = (b - a) * s/(2*n);
end

function int=SimpsonComp(f,a,b,n)
%takes in parameter as function handel f, starting interval a and ending
%interval b for integration and number of intervals as n
h=(b-a)/n;%step of integration
fa=f(a);%value of function at a
fb=f(b);%value of function at b
ff=0;%initialize ff to 0
for i=2:2:n%traversing on even numbers i
x=(a+(i-1)*h);%accessing even points in the intervals divided
fx=feval(f,x);%value of function at x
ff=ff+4*fx;%add 4*fx to ff
end
for i=3:2:n%traversing on odd numbers i
x=(a+(i-1)*h);%accessing odd points in the intervals divided
fx=feval(f,x);%value of function at x
ff=ff+2*fx;%add 4*fx to ff
end
int=(h/3)*(fa+fb+ff);%finally add first and last points tto all the sum and divide by 3
end

MATLAB R2018a EDITOR Search Documentation Log In Find Files Compare ▼ Print Run Section New Open Save Advance Run and Find In

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
Throughout this homework, rz)-e-5s sin 릎 sin siIT, unless stated otherwise. Q1 The Boole's quadr...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT