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]

 採用された回答

Birdman
Birdman 2020 年 4 月 1 日

0 投票

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

10 件のコメント

WILLBES BANDA
WILLBES BANDA 2020 年 4 月 1 日
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.
Birdman
Birdman 2020 年 4 月 1 日
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
WILLBES BANDA
WILLBES BANDA 2020 年 4 月 1 日
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
Steven Lord
Steven Lord 2020 年 4 月 1 日
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.
WILLBES BANDA
WILLBES BANDA 2020 年 4 月 1 日
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.
Torsten
Torsten 2020 年 4 月 1 日
You got an answer from your own code ? Where is this code ?
WILLBES BANDA
WILLBES BANDA 2020 年 4 月 1 日
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]
Torsten
Torsten 2020 年 4 月 1 日
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.
WILLBES BANDA
WILLBES BANDA 2020 年 4 月 1 日
Noted. Thank you Honourable
Elvin
Elvin 2023 年 7 月 20 日
I tried this but it says "unrecognized function"

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMathematics についてさらに検索

製品

タグ

質問済み:

2020 年 4 月 1 日

コメント済み:

2023 年 7 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by