Question

2.4 2.

Modify the given code below which uses Simpson's 3/8 method with 6 subintervals to answer the question above.

if a==b
I=0
else
N=3;
h=(b-a)/N;

x=a:h:b;
y=Fun(x);
I=3*h/8*(y(1)+2*sum(y(4:3:(N-2)))+y(N+1));
N=2*N;
check=0;
% Calculating subsequent valus of I
while check==0;
h=(b-a)/N;
x=a:h:b;
y=Fun(x);
% Composite Simpson's 3/8 method, Eq. (9.22)
I_new=3*h/8*(y(1)+2*sum(y(4:3:(N-2)))+y(N+1));
I_new=I_new+3*h/8*3*(sum(y(2:3:(N-1)))+sum(y(3:3:N)));
% Compare solution with that calculated in the previous iteration
error=abs((I-I_new)/I)*100; % (*)
if error>0.1 % continue iteration
check=0;
N=N*2;
I=I_new;
elseif error<=0.1 % end iteration
check=1;
I=I_new;
end
end
end

0 0
Add a comment Improve this question Transcribed image text
Answer #1

------------------------simpson_three_eight_rule.m--------------------

function [simp_val] = simpson_three_eight_rule(y , h)

    % store the value of y3 + y6 + ... + y(n-3)

    sum3 = 0;

   

    % calculate the value of y3 + y6 + ... + y(n-3)

    for i = 4 : 3 : length(y) - 3

       

        sum3 = sum3 + y(i);

       

    end

   

    % store the value of y1 + y2 + y3 + ... + y(n-1)

    sum1 = 0;

    % calculate the value of y1 + y2 + y3 + ... + y(n-1)

    for i = 2 : length(y) - 1

       

        sum1 = sum1 + y(i);

       

    end

   

    % store the value of y1 + y2 + y4 + y5 + ... + y(n-1)

    sum2 = sum1 - sum3;

   

    simp_val = ( 3 * h / 8 ) * ( ( y(1) + y( length(y) ) ) + 3 * sum2 + 2 * sum3 );

   

end

----------------------main.m---------------------

%                               3h

% Simpson 1/3 rd Integration = -----[ ( y0 + yn ) + 3 * ( y1 + y2 + y4 + y5 + ... + y(n-1) ) + 2 * ( y3 + y6 + ... + y(n - 3) ) ) ]

%                                8

%               2x

% Integrate --------- in [0 , 2.4] with 6 intervals

%             1 + x^2

l_bound = 0;

r_bound = 2.4;

% store the number of intervals

n = 5;

% create a vector for x in [0 , 2.4] with 6 intervals

x = linspace( l_bound , r_bound , n + 1 );

% create a vector of size 1 x length(x) initilized to 0

y = zeros(1 , length(x));

% create a vector of values of ( sinx - logx + e^x )

for i = 1 : length(x)

   

   y(i) = 2 * x(i) / ( 1 + ( x(i) ^ 2 ) );

   

end

% the integration is fom 0 to 6 where no of interval is n

h = ( r_bound - l_bound ) / n;

simp_val = simpson_three_eight_rule( y , h );

fprintf('Simpson Integration : %f\n', simp_val);

Sample Output

Simpson Integration : 2.037146

Add a comment
Know the answer?
Add Answer to:
Modify the given code below which uses Simpson's 3/8 method with 6 subintervals to answer the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I'm working on the newton's method on matlab, could someone help me and show what two...

    I'm working on the newton's method on matlab, could someone help me and show what two lines are needed to be added in the codes in order to make this function work? function sample_newton(f, xc, tol, max_iter) % sample_newton(f, xc, tol, max_iter) % finds a root of the given function f over the interval [a, b] using Newton-Raphson method % IN: % f - the target function to find a root of % function handle with two outputs, f(x), f'(x)...

  • 3. Assume we have Simpson's Rule: to = a, 13 = , h = (b-a)/2 =...

    3. Assume we have Simpson's Rule: to = a, 13 = , h = (b-a)/2 = a +h. (20) + 47(01) + f(x)]- ()where do < < Let fe .b), be even, h= (b-a)/n, and = a + jh, for each j = 0,1...... Show that there exists a l E (a,b) for which the Composite Simpson's rule for n subintervals can be written with its crror term as n/2 bar (n/2) - 1 f(a) +2 =1 (12) + 4...

  • 4. This question is about using the composite Simpson's Rule to estimate the integral 1 =...

    4. This question is about using the composite Simpson's Rule to estimate the integral 1 = (exp() dr to ten decimal places. (a) Enter and save the following Matlab function function y = f(x) y =exp(x/2); end [O marks) (b) Now complete the following Matlab function function y = compSR (a,b,N) end The function is to return the estimate of I found by applying Simpson's Rule N times. The Matlab function from the previous part of the question should be...

  • MATLAB Create a function that provides a definite integration using Simpson's Rule Problem Summar This example demo...

    MATLAB Create a function that provides a definite integration using Simpson's Rule Problem Summar This example demonstrates using instructor-provided and randomized inputs to assess a function problem. Custom numerical tolerances are used to assess the output. Simpson's Rule approximates the definite integral of a function f(x) on the interval a,a according to the following formula + f (ati) This approximation is in general more accurate than the trapezoidal rule, which itself is more accurate than the leftright-hand rules. The increased...

  • Looking for Muller Method MatLab coding for these following equations: This is the code I currently...

    Looking for Muller Method MatLab coding for these following equations: This is the code I currently have but is not working fun = @(x) x.^2-2; x1 = 0; x2 = 1; tol = 0.0001; kmax = 100; function [x, y] = Muller(fun, x1, x2, tol, kmax) x(1) = x1; x(2) = x2; x(3) = (x(2)+x(1))/2; y(1) = feval(fun, x1); y(2) = feval(fun, x2); y(3) = feval(fun, x(3)); c(1) = (y(2)-y(1))/(x(2)-x(1)); for k = 3 : kmax c(k-1) = (y(k)-y(k-1))/(x(k)-x(k-1)); d(k-2)...

  • Modify the code for Jacobi_vs_GS.m to implement the Symmetric Gauss-Seidel iteration.

    % Set number of iterations to be performednk = 300% Set parameters alpha and betaalpha = 2;beta  = 3;% Set the number of meshpoints so the interior has N x N such pointsN = 50;% Compute the distance between mesh points, in each directionh = 1/(N+1);% We will have arrays that capture the boundary as well as the interior% meshpoints.  As a result, we need those arrays to be of size (N+2) x% (N+2) so that those indexed 2:N+1, 2:N+1...

  • % Bisection.m Lines of code 17-26 and 43-47 are bold % This code finds the root...

    % Bisection.m Lines of code 17-26 and 43-47 are bold % This code finds the root of a function f(x) in the interval [a, b] using the Bisection method % % It uses f.m to define f(x), and assumes f(x) is continuous % It requires specification of a, b and the maximum error % It defines error using |f(xnew)| % Define inputs for problem a=0; %Defines lower limit of initial bracketing interval b=1; %Defines upper limit of initial bracketing interval...

  • Runge-Kutta method R-K method is given by the following algorithm. o y(xo)- given k2-f(xi5.yi tk,...

    Runge-Kutta method R-K method is given by the following algorithm. Yo = y(xo) = given. k1-f(xy) k4-f(xi +h,yi + k3) 6 For i = 0, 1, 2, , n, where h = (b-a)/n. Consider the same IVP given in problem 2 and answer the following a) Write a MATLAB script file to find y(2) using h = 0.1 and call the file odeRK 19.m b) Generate the following table now using both ode Euler and odeRK19 only for h -0.01....

  • upson's Rule with n=4 #5 (9) Use Simpson's Rule wi intervals to estimate ex-l at 16...

    upson's Rule with n=4 #5 (9) Use Simpson's Rule wi intervals to estimate ex-l at 16 Find the exact value - A the error. drant of the integral linpartas) and the =0: #5, Use integration by. Seť Int de #7 (a) Evaluate St sin x cos x dic (6) If g(x) = 5 Je tidt, find g'(x) and g'(o). |#8 use partial fractions to find substitution to evaluate $3x(x-3) dx #0 (a). Find 52 sin o do (6) Find the...

  • Exercise 6: Given the table of the function f(x)-2" 2 X 0 3 2 f(x) 1 2 4 8 a) Write down the Newton polynomial...

    Exercise 6: Given the table of the function f(x)-2" 2 X 0 3 2 f(x) 1 2 4 8 a) Write down the Newton polynomials P1(x), P2(x), Pa(x). b) Evaluate f(2.5) by using Pa(x). c) Obtain a bound for the errors E1(x), E2(x), Es(x) Exercise 7: Consider f(x)- In(x) use the following formula to answer the given questions '(x) +16-30f+16f,- 12h a) Derive the numerical differentiation formula using Taylor Series and find the truncation error b) Approximate f'(1.2) with h-0.05...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT