Integrating using sums(riemann sums)

Hi, i want to find the integral of function f without using the int function with the limits 5 and 17 . I want to find the riemann sum of the function f.
I tried solving it by using the int function but now i want to find the area withou using int. below is my code but n should represent the number of divisions that gives an accuracy of 10^-4 , i am not sure if my value of n is correct or not? how do i find n and the area (c) ?please help.
format longG
syms x
f = 2*pi*(0.16*(0.25-(x-1)^2)+44.52)*(1+(-0.32*x - 0.32)^2)^1/2;
a = int(f,5,17.688);
b = sym(a);
c = double(b);
n = (17.688-5)/0.0001;
SurfaceArea = [c n]

 Accepted Answer

You may use rsums. It allows you to interactively calculate the riemann sum integral:
rsums(f,5,17.688)

10 Comments

Thank you for your answer
but this works exactly the same as int function, cant we form a loop that calculates the area of each rectangle under the graph and then sum up to give us the overall area without using functions like int or rsums? Please help.
f=@(x) 2*pi*(0.16*(0.25-(x-1)^2)+44.52)*(1+(-0.32*x - 0.32)^2)^1/2;
dt=0.0001;
N=5:dt:17.688;
riemannSumIntegral=0;
for i=1:numel(N)
riemannSumIntegral=riemannSumIntegral+f(N(i))*dt;
end
it works perfectly fine, at least i will have to find the number of divisions(n) required for the area to have an accuracy of 10^-4 . Thank you honourable
Is that possible to do? Sure.
If you're asking us to write it and post, I'm hesitant to do so as that feels like a fairly common homework assignment in a numerical analysis course.
If you've written such a function and need help diagnosing and fixing a problem with it, post your function, the problem you're trying to solve, and an explanation of the problem you're experiencing and we may be able to offer some guidance.
From the code that i wrote above as part of the question, the number of divisions is represented by n. And i took the difference between the interval and divided it by 0.0001 but i still get a wrong answer. So i also need help diagnosing and fixing the problem with finding the number of divisions, apologies for not being more clear when posting the question.
You got an answer from your own code ? Where is this code ?
this was my initial code that was part of the question and i am trying to figure out the number of divisions required to get an accuracy of 10^-4
format longG
syms x
f = 2*pi*(0.16*(0.25-(x-1)^2)+44.52)*(1+(-0.32*x - 0.32)^2)^1/2;
a = int(f,5,17.688);
b = sym(a);
c = double(b);
n = (17.688-5)/0.0001;
SurfaceArea = [c n]
Take the result from int as the correct value for the integral.
Then test which values you get for the integral for h=1e-2,1e-3,1e-4,... using Riemann sums and compare with the value you got from int. As soon as the difference between the values is smaller than1e-4, you got the adequate step size. Note that it's usually not possible to determine the h in advance,only by testing.
Noted. Thank you Honourable
I tried this but it says "unrecognized function"

Sign in to comment.

More Answers (0)

Categories

Find more on Mathematics in Help Center and File Exchange

Products

Asked:

on 1 Apr 2020

Commented:

on 20 Jul 2023

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!