Question

In: Advanced Math

17. Integrate the function sin(x) from 0 to π using Riemann and Simpson integration methods with...

17. Integrate the function sin(x) from 0 to π using Riemann and Simpson integration methods with N subintervals, where N increases by factors of 2 from 2 to 256 (i.e. N = 2, N = 4, etc.). Plot the relative error ∆I/I = [| estimated value - true value |/(true value)], assuming the

highest value of N gives the ‘true’ value. Which method converges the fastest?

Solutions

Expert Solution

17.Matlab code

x1 = 0;
x2 = pi;
f=@(x) sin(x);
%N=128;
for N=2:2:256
dx=(x2-x1)/N;
summe=0.0;
for i=1:N
summe=summe+f(x1+dx*(i-1));
end
summe=summe*dx
z=integral(f,x1,x2);%true value
rel_error=abs(summe-z)/z
plot(N,rel_error,'*')
pause(0.5)
end

Output

summe =

    2.0000


rel_error =

   1.2550e-05

Simpson integration

function I = simpsons(f,a,b,n)

f=@(x)sin(x);
a=0;b=pi;
for n=2:2:256

h=(b-a)/n; xi=a:h:b;
    I= h/3*(f(xi(1))+2*sum(f(xi(3:2:end-2)))+4*sum(f(xi(2:2:end)))+f(xi(end)))
    Z=integral(f,a,b);%true value
    relative_error=abs(Z-I)/Z
    plot(n,relative_error,'*')
    pause(0.5)
end

Output

relative_error =

   1.2600e-10


ans =

    2.0000

clearly from the output we see that Simpsons Integration converges faster than the riemann integration methods with N subintervals.

   

   





Related Solutions

(a) Find the Riemann sum for f(x) = 4 sin(x), 0 ≤ x ≤ 3π/2, with...
(a) Find the Riemann sum for f(x) = 4 sin(x), 0 ≤ x ≤ 3π/2, with six terms, taking the sample points to be right endpoints. (Round your answers to six decimal places.) R6 = (b) Repeat part (a) with midpoints as the sample points. M6 = If m ≤ f(x) ≤ M for a ≤ x ≤ b, where m is the absolute minimum and M is the absolute maximum of f on the interval [a, b], then m(b...
Function  f ( x) = a - x/π for (0, π}, Determinate transformation Fourier
Function  f ( x) = a - x/π for (0, π}, Determinate transformation Fourier
Integrate the following values of y from x = 0 to x = 130 using (a)...
Integrate the following values of y from x = 0 to x = 130 using (a) The midpoint rule using intervals of [0 10], [10 30], [30 70], and [70 130] (b) The trapezoid rule using the same intervals (c) Simpson’s rule using the same intervals x y 0 6 5 12 10 18 20 30 30 42 50 36 70 24 100 18 130 6 Integrate the differential equation dydt = y from t = 0 to t =...
f(x,y)=sin(2x)sin(y) intervals for x and y: -π/2 ≤ x ≤ π/2 and -π ≤ y ≤...
f(x,y)=sin(2x)sin(y) intervals for x and y: -π/2 ≤ x ≤ π/2 and -π ≤ y ≤ π find extrema and saddle points In the solution, I mainly interested how to findcritical points in case of the system of trigonometric equations (fx=0 and fy=0). ,
Find the Fourier series for the function on the interval (-π,π) f(x) = 1 -sin(x)+3cos(2x) f(x...
Find the Fourier series for the function on the interval (-π,π) f(x) = 1 -sin(x)+3cos(2x) f(x )= cos2(x) f(x) = sin2(x)
Evaluate the Riemann sum for f ( x ) = 0.9 x − 1.5 sin (...
Evaluate the Riemann sum for f ( x ) = 0.9 x − 1.5 sin ( 2 x ) over the interval [ 0 , 2.5 ] using five subintervals, taking the sample points to be right endpoints. step by step and answer please. can u also show me how to enter in ti 83.
integrate from infinity to 1: (1+(sin^2(x))/sqrt (x)) dx
integrate from infinity to 1: (1+(sin^2(x))/sqrt (x)) dx
Consider the given function. Evaluate the Riemann sum for 0 ≤ x ≤ 3, with n...
Consider the given function. Evaluate the Riemann sum for 0 ≤ x ≤ 3, with n = 6, taking the sample points to be right endpoints.
The function F(x) = x2 - cos(π x) is defined on the interval 0 ≤ x...
The function F(x) = x2 - cos(π x) is defined on the interval 0 ≤ x ≤ 1 radians. Explain how the Intermediate Value Theorem shows that F(x) = 0 has a solution on the interval 0 < x < .
rotate around the z -axis the region :T ={(x,z)'∈ R^2:sin z<x<π -z,0<z<π} to obtain the solid...
rotate around the z -axis the region :T ={(x,z)'∈ R^2:sin z<x<π -z,0<z<π} to obtain the solid Ω.find its volume and center of mass.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT