Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Evaluate the following integral using the techniques specified below (1-e*)dx a)

ID: 3216279 • Letter: E

Question

Evaluate the following integral using the techniques specified below (1-e*)dx a) b) Analytically using the symbolic algebra capability in MATLAB Single application of the trapezoid rule. To do this create a function called trapf that takes as input the following parameters Function handle to an anonvmous function Lower limit of integration . Upper limit of integration Number of segments c) Composite trapezoid rule with n-2. Use your function from part b d) Composite trapezoid rule with n-4. Use your function from part b e) Single application of Simpson's 1/3 rule. To do this create a function called simp13 that tak es as input the following parameters Function handle to an anonymous function Lower limit of integration Upper limit of integration Number of segments

Explanation / Answer

%This is the function trapf

function integral1=trapf(f,a,b,n)
h=(b-a)/n;
x=linspace(a,b,n+1);
integral1=0;
for i=1:n
%Trapezoid rule
integral1=integral1+(h/2)*(feval(f,x(i))+feval(f,x(i+1)));
end
end

%Simpson
%This is the function simp13

function integral1=simp13(f,a,b,n)
if rem(n,2)~=0
error('Please provide an even number of intervals')
end
h=(b-a)/n;
x=linspace(a,b,n+1);
integral1=0;
for i=1:2:n-1
%Simpson rule
integral1=integral1+(h/3)*(f(x(i))+4*f(x(i+1))+f(x(i+2)));
end
  
end

%%%This is the main program

%a)
%We define a symbolic variable and the limits of integration
syms x
f = 1-exp(-x);
a=0;
b=4;
%We use the function int to calculate the integral
disp(int(f,x,a,b))
%The integral is exp(-4) + 3
%b)
%We use the function we created, but firt we
% define our function as a function handle
g=@(x)(1- exp(-x));
integ=trapf(g,a,b,1);
fprintf('the integral using trapezoidal rule with n=1 is:%f ',integ)

%c)
int1=trapf(g,a,b,2);
%d)
fprintf('the integral using trapezoidal rule with n=2 is:%f ',int1)
int2=trapf(g,a,b,4);
fprintf('the integral using trapezoidal rule with n=4 is:%f ',int2)

%e) Single application of Simpson's 1/3 rule
int3=simp13(g,a,b,2);
fprintf('the integral using Simpson s 1/3 rule with n=2 is:%f ',int3)

%f) application of Simpson's 1/3 rule with n=4
int4=simp13(g,a,b,4);
fprintf('the integral using Simpson s 1/3 rule with n=4 is:%f ',int4)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote