1 Practice Evaluate the following integrals by using the tra
1. (Practice) Evaluate the following integrals by using the trapezoidal rule Example of a Trapezoidal Rule Calculation To illustrate this section\'s concepts, the following integral is used: Evaluate To for one panel by using Equation l4.6. Compute Ti by using the value of To and Equation 14.11. Continue the calculation through T The function f(x) 1/a can, of course, be integrated analytically to give In(x), and because Collect your results in the form of a table. (Be careful: Errors in one ste ln(1)- 0, the value of the integral is ln(2)- 0.69314718. The trapezoidal rule approximation to the next the integral with a 1 and b 2 begins with Equation 14.6 to obtain To (Exact result 170.667) To 5 (2-1) 0.75 Repeated use of Equation 14.11 then yields the following: Exact result 6553.6) I re (average value of f over interval) width of interval) 0,708333 or (Equation 14.6) T2- TI/2 (1/1.25 1/1.75) This is the trapezoidal rule for one panel, identified as T- 0.6970238 (Equation 14.11) Ax T3 T2/2 (1/1.25 1/1.375 1/1.625 1/1.875) odd only where 0.69412185
Solution
choice = input(\'a or b: \');
if choice == a
y = (@x) x^2;
a = 0;
b = 8;
n = 4;
h = (b-a)/n;
ys = [];
xs = [];
for i=a:b
xs(end+1) = i;
ys(end+1) = y(i);
end
l = length(x);
answer = (h/2)*((ys(1)+ys(l))+2*(sum(ys)-ys(1)-ys(l)))
else
y = (@x) x^4;
a = 0;
b = 8;
n = 4;
h = (b-a)/n;
ys = [];
xs = [];
for i=a:b
xs(end+1) = i;
ys(end+1) = y(i);
end
l = length(x);
answer = (h/2)*((ys(1)+ys(l))+2*(sum(ys)-ys(1)-ys(l)))
