Question

In: Advanced Math

The Simpson numerical method tries to obtain a result closer to the analytic solution with and...

The Simpson numerical method tries to obtain a result closer to the analytic solution with and independent variable x, using the Simpson method (both 1/3 and 3/8 methods). Use a MATLAB script. The program should ask for the user to submit the function he wishes to integrate and the values of the a & b limits. Additionally it should ask the number of elements that would divide the function( sub-intervals).

Solutions

Expert Solution


clear all
close all
%function for which integration have to do
func=@(x) (sin(x.^2))./(1+x);
fprintf('function for which integration have to do f(x)=')
disp(func)
%all limits
a=0; b=1;
%number of subintervals
N=200;
val=simpson13(func,a,b,N);
fprintf('Integration using Simpson 1/3 method for N=20 with interval [0 1] is %f\n',val)

%number of subintervals
N=200;
val=simpson38(func,a,b,N);
fprintf('Integration using Simpson 3/8 method for N=20 with interval [0 1] is %f\n',val)

%%Matlab function for Simpson integration
function val=simpson13(func,a,b,N)
    % func is the function for integration
    % a is the lower limit of integration
    % b is the upper limit of integration
    % N number of rectangles to be used
    %splits interval a to b into N+1 subintervals
    xx=linspace(a,b,N+1);
    dx=xx(2)-xx(1); %x interval
    val=(dx/3)*(double(func(xx(1)))+double(func(xx(end))));
    %loop for Simpson integration
        for i=2:length(xx)-1
            xx1=xx(i);
            if mod(i,2)==0
                val=val+(dx/3)*4*double(func(xx1));
            else
                val=val+(dx/3)*2*double(func(xx1));     
            end
        end
end

%%Matlab function for Simpson 3/8 Method
function val=simpson38(f,a,b,n)
    % f is the function for integration
    % a is the lower limit of integration
    % b is the upper limit of integration
    % n is the number of trapizoidal interval in [a,b]
  
    %splits interval a to b into n+1 subintervals
    xx=linspace(a,b,n+1);
    dx=(xx(2)-xx(1)); %x interval
    val=f(a)+f(b);
    %loop for simpson integration
        for i=2:n
            if mod(i-1,3)==0
                val=val+2*double(f(xx(i)));
            else
                val=val+3*double(f(xx(i)));
            end
        end
    %result using simpson integration method
    val=(3/8)*dx*val;
end
  
%%%%%%%%%%%%%%%%%% End of Code %%%%%%%%%%%%%%%%%


Related Solutions

Use a numerical solver and Euler's method to obtain a four-decimal approximation of the indicated value....
Use a numerical solver and Euler's method to obtain a four-decimal approximation of the indicated value. First use h = 0.1 and then use h = 0.05 y' = y − y2, y(0) = 0.8;    y(0.5) y(0.5) ≈   ? (h = 0.1) y(0.5) ≈ ? (h = 0.05)
Brad Simpson is a farmer in the Moscow, Idaho area. Each year he tries to plant...
Brad Simpson is a farmer in the Moscow, Idaho area. Each year he tries to plant the crop that will make him the most money. He has a choice of three crops, barley, wheat or garbanzo beans. The amount he makes on each crop varies based on the amount of rain that comes during the season. A very rainy season is great for garbanzo beans but hurts the profit from barley. Wheat doesn’t vary much based on the rainfall. The...
Brad Simpson is a farmer in the Moscow, Idaho area. Each year he tries to plant...
Brad Simpson is a farmer in the Moscow, Idaho area. Each year he tries to plant the crop that will make him the most money. He has a choice of three crops, barley, wheat or garbanzo beans. The amount he makes on each crop varies based on the amount of rain that comes during the season. A very rainy season is great for garbanzo beans (called garbos) but hurts the profit from barley. Wheat doesn’t vary much based on the...
Euler’s method Consider the initial-value problem y′ = −2y, y(0) = 1. The analytic solution is...
Euler’s method Consider the initial-value problem y′ = −2y, y(0) = 1. The analytic solution is y(x) = e−2x . (a) Approximate y(0.1) using one step of Euler’s method. (b) Find a bound for the local truncation error in y1 . (c) Compare the error in y1 with your error bound. (d) Approximate y(0.1) using two steps of Euler’s method. (e) Verify that the global truncation error for Euler’s method is O(h) by comparing the errors in parts (a) and...
Write Matlab programs implementing the algorithms based on bisection,Newton, and secant method for numerical solution of...
Write Matlab programs implementing the algorithms based on bisection,Newton, and secant method for numerical solution of scalar nonlinear equa-tions. Use these programs to compute approximations to real roots of the following equations: exp(x)−3x^2=0, (1) x^3=x^2+x+1, (2) exp(x) =1/(0.1 +x^2), (3) and x= 1 + 0.3 cos(x). (4) Use an error tolerance tol=10^(−12). Display the obtained approximations to the roots of these equations, and compare the number of iterations, starting with the same initial values x0 for bisection and Newton methods,...
Describe the difference between "exact solution" and "numerical solution". Furthermore, please describe why we study "numerical...
Describe the difference between "exact solution" and "numerical solution". Furthermore, please describe why we study "numerical solution".
Using a brief numerical example, identify a numerical method for identifying the gains and costs to...
Using a brief numerical example, identify a numerical method for identifying the gains and costs to shareholders that can be expected in the event of a proposed takeover, when the terms are either a cash offer or share for share exchange.
The importance of numerical method and method of separation of variable in heat transfer
The importance of numerical method and method of separation of variable in heat transfer
using method of undetermined coefficients obtain real solution y''''+y''=12x^2+4sinx
using method of undetermined coefficients obtain real solution y''''+y''=12x^2+4sinx
A protein solution was placed in an analytic centrifuge and spun until equilibrium was reached. The...
A protein solution was placed in an analytic centrifuge and spun until equilibrium was reached. The measurement was then repeated. But it was realized, too late, that prior to the second run, the protein had been denatured. The average size of a denatured protein is larger than that of a native, compact protein. (a) Do you expect the distribution of molecules to be the same, at equilibrium, for the two different runs? Explain. (b) The time that it takes to...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT