clearvars
est1=0; est2 = 0;
dx= (.00000001);
for x= (1):dx:2+dx/2 % doesn't really do 2+dx/2;
f=exp(x*(x+sqrt(x^2-1))); % the extra just guards
if x>1 % against rounding error that might
est2=est2+f*dx; % prevent 2 from being done
end
if x<2-dx/3
est1=est1+f*dx;
end
end
est1
est2
(est1+est2)/2
fun = @(x) exp(x.*(x+sqrt(x.^2-1)));
integral(fun,1,2)
Produces the left- and right-side Riemann sums, the average of those two and the results of the integral function built in to Matlab.
The left and right hand sums are
est1 =
232.33110438164
est2 =
232.331121797335
These are the lower and upper bounds on the correct answer as the curve is concave up over the range given.
The average of those is
ans =
232.331113089488
and Matlab's integral function gives
ans =
232.331113089477
Wolfram Alpha gives only
integral_1^2 e^(x (x + sqrt(-1 + x^2))) dx = 232.331
without an option to ask for more digits.
Edited on May 16, 2025, 1:27 pm
|
Posted by Charlie
on 2025-05-16 13:26:33 |