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

Solve the following problem using the MATLAB environment. Do not use MATLAB\'s b

ID: 3782016 • Letter: S

Question

Solve the following problem using the MATLAB environment. Do not use MATLAB's built-in functions that execute the operations that are being asked in the problem. Write a user-defined MATLAB function that evaluates the definite integral of a function f(x) by using the Riemann sum (see Eq. (2.27)). For function name and arguments, use l = RiemannSum (Fun, a, b). Fun is a name for the function that calculates the value of f(X) for a given value of X. It is a dummy name for the function that is imported into RiemannSum. a and b are the limits of integration, and l is the value of the integral. The Riemann sum is calculated by dividing the integration interval [a, b] into ten subintervals. Use RiemannSum for evaluating the definite integral integral^1_0 xe^x dx. Compare the result with the exact value of the integral, 1. I = integral^b_a f(x) dx = lim_lambda x_1 rightarrow 0 sigma^n_i = 1 f(c_i) lambda x (2.27)

Explanation / Answer

THE MATLAB FUNCTION RiemannSum.m

function [ I ] = RiemannSum(Fun,a,b )
N = 10;% Number of subintervals
h = (b-a)/N;% subinterval size
x = a:h:b;% subintervals
I = 0;% initial value of sum
for i =1:N
    I = I+Fun((x(i)+x(i+1))/2)*h;% middle Riemann sum.
end
end

Testing the function

Fun = @(x) x.*exp(x);
a = 0;
b=1;
I = RiemannSum(Fun,a,b);
fprintf('The exact solution = 1 The approximated solution %f ',I);

OUTPUT/RESULT

The exact solution = 1
The approximated solution 0.998152

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