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

You want to find the integral from -5 to 5 of y(x) = exp(-x^2) This integral is

ID: 2080532 • Letter: Y

Question

You want to find the integral from -5 to 5 of y(x) = exp(-x^2) This integral is very difficult to find analytically, so we are going to solve for it numerically. We will use a step size (sub-interval size) of 0.01. Save your program as integral_yourlastname.m Write a program that finds the integral of the function using the following methods Rectangular using the left hand value (I1) Rectangular using the right hand value (I2) Trapezoidal (I3) You may not use any of MATLAB's built in functions for integrals. Your program should output I1, I2, and I3.

Explanation / Answer

% name of code file "integral_yourlastname.m"
% this code will calculate the integral of "exp(-x^2)" in the period of -5
% to 5 by using 3 different rules they are 1). rectangular using left hand
% & right hand value, and 2). Trapezoidal

format long
dt=0.01; % step size
t=-5:dt:5; % create time range
N=length(t);

% Rectangular using left hand value
L=0; % Initiate sum to '0'
for i=1:1:N-1;
x=t(i); % left hand time value
f=exp(-x^2); % left hand value of function
L=L+f*dt; % adding the SUM to the previous SUM
end
I1=L % Final value of integration using rectangular using left hand value

L=0;
for i=2:1:N;
x=t(i); % right hand time value
f=exp(-x^2); % right hand value of function
L=L+f*dt; % adding the SUM to the previous SUM
end
I2=L % Final value of integration using rectangular using Right hand value

L=0;
for i=1:1:N-1;
x1=t(i);x2=t(i+1); % left hand time value and right hand value
f1=exp(-x1^2); % left hand value of function
f2=exp(-x2^2); % right hand value of function
f=(f1+f2)/2; % trapezoidal value of function
L=L+f*dt; % adding the SUM to the previous SUM
end
I3=L % Final value of integration using trapezoidal

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