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

PLEASE SOLVE PROBLEM 4 NOT 2. PROBLEM 2 IS JUST FOR REFERENCE, DON\'T SOLVE IT.

ID: 3812945 • Letter: P

Question

PLEASE SOLVE PROBLEM 4 NOT 2. PROBLEM 2 IS JUST FOR REFERENCE, DON'T SOLVE IT.

PLEASE SOLVE PROBLEM 4 USING MATLAB PROGRAM.

Problem 4 Write a user-defined MATLAB function for integration with the composite Simpson's method of a function f(x) that is given in a set of n discrete points that are spaced equally. For the function name and arguments use SimpsonPoints(x,y), where the input arguments x and y are vectors with the values of x and the corresponding values of f(x), respectively. The output argument I is the value of the integral. If the number of intervals in the data points is divisible by 3, the integration is done with the composite Simpson's 38 method. If the number of intervals in the data points is one more than a number divisible by 3, the integration in the first interval is done with the trapezoidal method and the integration over the rest of the intervals is done with the composite Simpson's 38 method. If the number of intervals in the data points is two more than a number divisible by 3, then the integration over the first two intervals is done with Simpsons's 1/3 method and the integration over the rest of the intervals is done with the composite Simpson's 3/8 method. Use SimpsonPoints to solve Problem 2.

Explanation / Answer

Code:

function f = simson(a,b)
h=a(2)-a(1);
n=length(a)-1;
if mod(n,3) == 0
s=0
for i = 1:n/3
s=s+b(i*3-2)+3*b(i*3-1)+3*b(i*3)+b(i*3+1);
end
f=3*h*s/8;
else if mod(n,3)==1
f=h*(b(1)+b(2))/2+simson(a(2:n+1),b(2:n+1));
else
f=h/3*(b(1)+4*b(2)+b(3))+simson(a(3:n+1),b(3:n+1));
end
end

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