Question
MATLAB code for Simpson's Rule. Please help fix my code. I am trying to use the example to verify my code, but my code is
MATLAB code for Simpson's Rule.
Please help fix my code. I am trying to use the example to verify my code, but my code is wrong.
clc
clear all
close all
%Equation = input('Enter Function: ');
a = input('Enter lower limit: ');
b = input('Enter upper limit: ');
n = input('Enter number of sub-intervals: ');
f = @(x) 1/(x+1);
T = a:n:b;
w = (b-a);
j = f(a);
k = f(b);
area1 = 1;
c = a + w;
while (c
area1 = area1 + 4 * f(c);
c = c + w + w;
end
area2 = 0;
e = a + w + w;
while (e
area2 = area2 + 2 * f(e);
e = e + w + w;
end
g = (j + area1 + area2 + k);
fprintf('Area using Simpsons Rule = %f ', g);
Example. Use Simpson's rule with n 6 to estimate 1 +x3 dx. Solution. For n = 6, we have ?x = 461 = 0.5. We compute the values of yo, y?, ??, . . . , 16. 11.5 2 2.5 3.5 24.375 3 16.62528 43.875 65 Therefore, ???? dz 0.5(V2 + 4v 4.375+2(3) + 4v 16.625 + 2v 28 +A/43 875 + 35 12.871
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started