1 answer

Use matlab please. Exercise 2 Use the functions you coded in Exercise 1 to compute the...

Question:

Exercise 2 Use the functions you coded in Exercise 1 to compute the numerical approximation of the integral .1 cos e 30 To ththat returns the following items: em, et, es: row vectors with components the absolute values of the integration errors llref

Use matlab please.

Exercise 2 Use the functions you coded in Exercise 1 to compute the numerical approximation of the integral .1 cos e 30 To this end, write a Matlab/Octave function function [en,et , es] test-integration() =
that returns the following items: em, et, es: row vectors with components the absolute values of the integration errors llref-Inl n=2.3, . . . . 100 obtained with the midpont (vector em), trapezoidal (vector et) and Simpson (vector es) rules. Here, f 1.6851344770476 is the reference value of the integral (2) while In is the numerical approximation obtained by using the composite midpoint, trapezoidal, and Simpson rules with n nodes The function test integration) should also return the plot of the integrand function ap- pearing in (2) in figure(1), and the plots of the errors em, et and es versus n in a log-log scale in figure(2) (one figure with three plots). (Hint: use the Matlab command loglog)).

Answers

`Hey,

Note: Brother in case of any queries, just comment in box I would be very happy to assist all your queries

function [em,et,es]=test_integration()
[email protected](x) ((1./(1+x.^2)).*cos((3/2)*exp(-x.^2))-x.^3/30);
Iref=integral(f,-3,1);
em=[];
et=[];
es=[];
v=2:100;
a=-3;
b=1;
for n=2:100
em(n-1)=abs(int_midpoint_rule(f,a,b,n)-Iref);
et(n-1)=abs(int_trapezoidal_rule(f,a,b,n)-Iref);
es(n-1)=abs(int_Simpson_rule(f,a,b,n)-Iref);
  
end
loglog(v,em,v,es,v,et);
legend('Mid point','Trapezoidal','Simpsons');
function I = int_trapezoidal_rule(f,a,b,n)

hval = (b-a)/n;

%Calculate

x = [a+hval:hval:b-hval];

%feval point

xin=sum(feval(f,x));

I = hval/2*(feval(f,a)+2*xin+feval(f,b));

end
%int_Simpson_rule.m

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

hval = (b-a)/n;

xval1 = feval(f,a)+feval(f,b);

xval2 = 0;

xval3 = 0;

for i = 1:n-1

x = a+i*hval;

if mod(i,2) == 0

xval3 = xval3+feval(f,x);

else

xval2 = xval2+feval(f,x);

end

end

xival = hval*(xval1+2*xval3+4*xval2)/3;

I=xival;
end
function I = int_midpoint_rule(f,a,b,n)
I=0;


hval = (b-a)/(n+2);

%mid point function

xval = [a+hval:2*hval:b-hval];

I = 2*hval*sum(feval(f,xval));
end
end

Figure 1 Eile Edit Yew Insert 1ools Desktop 岦indow Help 10 -Mid point Trapezoidal Simpsons 101 10 10 10 10 10 10 10 10% 10 10

Kindly revert for any queries

Thanks.

.

Similar Solved Questions

1 answer
A 1.40 kΩ resistor is connected in series with a 0.800 kΩ resistor. This pair of...
A 1.40 kΩ resistor is connected in series with a 0.800 kΩ resistor. This pair of resistors is connected in parallel with a 7.00 kΩ resistor. That combination is then connected in series with a 0.700 kΩ resistor and a 9.0-V ideal battery (no internal resistance of course). A) ...
1 answer
A drop of water on a countertop reflects light from a flower held 3.10 cm directly...
A drop of water on a countertop reflects light from a flower held 3.10 cm directly above it. The flower's diameter is 1.90 cm, and the diameter of the flower's image is 0.115cm. What is the focal length of the water drop, assuming that it may be treated as a convex spherical mirror? = cm?...
1 answer
Show me what i did wrong 5. (8 pts) Make an accuwe graph of the piecewise-defined...
show me what i did wrong 5. (8 pts) Make an accuwe graph of the piecewise-defined function xe-2 - 25x24 17-2x, x24 2x. 4r you य Eye Y-72 3 417 6. For the quadratic function f(x) = x + 2x - 8: a) (5 pts.) Determine the coordinates of the vertex algebraically 1473--1)-865 (-1,-9) b) (4 pts. U...
1 answer
Suppose a study on the relationship between gender and political party included 200 men and 200...
Suppose a study on the relationship between gender and political party included 200 men and 200 women and found 180 Democrats and 220 Republicans. Is that information sufficient for you to construct a contingency table for the study? a. Yes b. No For a chi-squared test statistic of 5.02, we would re...
2 answers
How do you divide #(2x^2-3x+2)/(x - 1)#?
How do you divide #(2x^2-3x+2)/(x - 1)#?...
1 answer
QUESTION 8 The number of construction projects on a college campus follows a Poisson distribution with...
QUESTION 8 The number of construction projects on a college campus follows a Poisson distribution with a mean of 3. The probability that exactly four construction projects are currently taking place is (Choose the one that is closest to your answer, 0.2240 0.4230 O 0.16810 0.0000...
1 answer
Janet Garcia is considering expanding her business. She plans to hire a salesperson to cover trade...
Janet Garcia is considering expanding her business. She plans to hire a salesperson to cover trade shows. Because of compensation, travel expenses, and booth rental, fixed costs for a trade show are expected to be $10,120. The booth will be open 23 hours during the trade show. Ms. Garcia also plans ...
1 answer
Find the most general antiderivative of the function f(x) -r-1 +5V2 22 4 cscx
Find the most general antiderivative of the function f(x) -r-1 +5V2 22 4 cscx...
1 answer
3. A function f(x) that you do not know has the following properties. (6 points total)...
3. A function f(x) that you do not know has the following properties. (6 points total) The domain of the function is (-00,00), and the graph off has no discontinuities. • f'(0) = 0 and f'(9) = 0. . f"(x) > 0 on the interval (-0,3), and F"(x) < 0 on the interval (3,00). f&#...
1 answer
Let D be a region in the (a, y)-plane. If a, b, e>0, let Sa be the part of the hyperbolic parabol...
Let D be a region in the (a, y)-plane. If a, b, e>0, let Sa be the part of the hyperbolic paraboloid zary in R3 with (x,y) E D, and let Tb,e be the part of the elliptic paraboloid bz2 + суг in R3 with (z.J) D. For a given a > 0, find b, c > 0 such that Tb.c has the same ar...
1 answer
Linked list: 1) What are their respective logical and physical / storage structures .2) At least...
Linked list: 1) What are their respective logical and physical / storage structures .2) At least one application example combining data structure and algorithm should be given. please answer these two questions properly...
1 answer
Renforcement concrete design (ACI-code 2019) 2- Design the beam for the slab shown below. The beam...
Renforcement concrete design (ACI-code 2019) 2- Design the beam for the slab shown below. The beam is carrying a service moment of 450 kN.m. Take f = 21 MPa and fy = 414 MPa. hf=75mm 1.2m 7.3 m 540 mm 300mm...
1 answer
Why is interphase really not a stage of either type of cell division?
Why is interphase really not a stage of either type of cell division?...
1 answer
Find the value of (-2)^3×6^2?
Find the value of (-2)^3×6^2?...
1 answer
1 Balance the following chemical reaction
1 Balance the following chemical reaction...
1 answer
A circle's center is at #(3 ,3 )# and it passes through #(4 ,5 )#. What is the length of an arc covering #( pi ) /6 # radians on the circle?
A circle's center is at #(3 ,3 )# and it passes through #(4 ,5 )#. What is the length of an arc covering #( pi ) /6 # radians on the circle?...
1 answer
[0, 1, 4, 8, 12] Given the five number summary above, what is the interquartile range...
[0, 1, 4, 8, 12] Given the five number summary above, what is the interquartile range (IQR)?...