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

Code in MATLAB to get points award only: Write MATLAB code for the Simpson Rule

ID: 2965975 • Letter: C

Question

Code in MATLAB to get points award only: Write MATLAB code for the Simpson Rule using the function: f(x) = 2sin(x)cos(x), evaluating the integral between 0 and pi/2. Iterate until achieve a relative error of 10 (-8). Do the Script procedure following: The resulting integral. The final relative error in two ways: The final trapezoidal result relative to the exact result. The final trapezoidal result relative to the previous iteration's result Iterate until the relative error in # 2 above falls below the required tolerance. Cutting h in 1/2 for each major iteration (outer loop) and recalculate the entire Simpson rule on each occurrence.

Explanation / Answer

clc
clear all
%e= actual value of integral
e=1;
re1=.00001;
re2=1;
sum(1)=0;
i=3;
%re2=relative error with respect to previous iteration
%re2 requirement can be changed in while statement

while abs(re2)>.0001
x=zeros(i,1);
y=zeros(i,1);

% Computing functional values at grid points

for j=2:i
x(j)=((j-1)*(pi/2))/(i-1);
y(j)=sin(2*x(j));
end
%Simpsons 1/3rd rule
%Value of integral=(h/3)*(y0 + 4y1 + 2y2 + 4y3 + 2y4 +

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