n = input('number of intervals:');
ar = zeros(1,n+1);
b = input('upper limit:');
a = input('lower limit:');
f = @(x) sin(x.^3)./(x + 2);
h = (b - a)/n;
ar(1) = a;
% for loop to create array of points
for i=1:n
ar(i+1) = ar(1) + h*i;
end
% following is the composite trapezoidal rule
T = @(h, ar) h./2.*(f(ar(1)) + f(ar(n+1))) +
h.*sum(f(ar(2:n)));
% evaluating result
answer = T(h, ar);
disp('the answer is');
disp(answer);
disp('the global error is');
q = integral(f, 0, 2);
disp(abs((answer - q)));
ANSWERS:
>> cheg_composite_rule
number of intervals:10
upper limit:2
lower limit:0
the answer is
0.1546
the global error is
0.0015
>> cheg_composite_rule
number of intervals:20
upper limit:2
lower limit:0
the answer is
0.1557
the global error is
4.1113e-04
>> cheg_composite_rule
number of intervals:40
upper limit:2
lower limit:0
the answer is
0.1560
the global error is
1.0362e-04
>> cheg_composite_rule
number of intervals:10
upper limit:2
lower limit:0
the answer is
0.1546
the global error is
0.0015
How would you code this on matlab? Wirite a code to find an approximation for the composite trapezoidal rule. dr witiferent mumber of sabintervals using Use the following number of subintervals na...
2 Problem 3 (25 points) Let I = ïrdz. a) [by hand] Use a composite trapezoidal rule to evaluate 1 using N = 3 subintervals. b) MATLAB] Use a composite trapezoidal rule to evaluate I using N - 6 subinterval:s c) by hand] Use Romberg extrapolation to combine your results from a) and b) and obtain an improved approximation (you may want to compare with a numerical approximation of the exact value of the integral 2 Problem 3 (25 points)...
3. Find the value of V1+r3dr, using the composite trapezoidal rule, to 5 decimal places. How many subintervals do you need to use to attain this accuracy? Make a convergence plot to show that the composite trapezoidal rule is second order in this case 3. Find the value of V1+r3dr, using the composite trapezoidal rule, to 5 decimal places. How many subintervals do you need to use to attain this accuracy? Make a convergence plot to show that the composite...
Calculate , and apply the composite trapezoidal rule to numerically compute it with evenly spaced nodes where n = 10, 20, 40, 80. Compute absolute numerically errors. Please post your code in MATLAB and present your results in the table below: 1 0 We were unable to transcribe this imagen Result by the composite trapezoidal rule Absolute error Absolute errorxn2 10 20 40 80 1 0 n Result by the composite trapezoidal rule Absolute error Absolute errorxn2 10 20 40...
Show work by hand and also using MATLAB code. Model 1 Given a polynomial f(x) Write a first-order approximation of f(x), given the value of f(x) at two points Plot the polynomial and the first-order approximation on a graph Write a second-order approximation of f(x), given the value at three points. Plot the polynomial, the first-order and second-order approximations on a graph Find the integral Exactly Using trapezoidal rule Using composite trapezoidal rule Using Simpson's 1/3 rule . Calculate the...
Integration and Romberg 「c"dr Find: For ) Simple Simpson's Use composite trapezoidal and Romberg integration to find R,, RIA Compsite trapvz odial Rule (CTR) a+(2, -Dh,),ad where n the row Integration and Romberg 「c"dr Find: For ) Simple Simpson's Use composite trapezoidal and Romberg integration to find R,, RIA Compsite trapvz odial Rule (CTR) a+(2, -Dh,),ad where n the row
please include matlab code!! [Computer Exercises 5.3.1] Find approximate values for the two integrals 1 dr 0 0 Use composite Simpson's rule with an error-Ί 10-5 [Computer Exercises 5.3.1] Find approximate values for the two integrals 1 dr 0 0 Use composite Simpson's rule with an error-Ί 10-5
Use Matlab code Consider the following function sin(x) Using the following parameters in your functions: -func: the function/equation that you are required to integrate -a, b: the integration limits n: the number of points to be used for the integration I:Integral estimate a) Write a function capable of performing numerical integration of h(x) using the composite trapezoidal rule. Use your function to integration the equation with 9 points. Write a function capable of performing numerical integration of h(x) using the...
PLEASE use MATLAB only to write the code 100 10 Assume -18.79829683678703 is the "exact" value of the integral. Estimate this integral by the composite trapezoid rule with 3, 5, and 7 points. Calculate the percent difference from the exact value in each case using PD-100 abs(exact-trap)Vexact)
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...
Can you please do this in matlab Consider the following function: 4 0 Using the following parameters in your functions: func: the function/equation that you are required to integrate a, b: the integration limits n: the number of points to be used for the integration : Integral estimate A. Write a function capable of performing numerical integration of h(x) using the composite B. write a function capable of performing numerical integration of h(x) using the composite C. Calculate the absolute...