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]

 Respuesta aceptada

Birdman
Birdman el 1 de Abr. de 2020
You may use rsums. It allows you to interactively calculate the riemann sum integral:
rsums(f,5,17.688)

10 comentarios

WILLBES BANDA
WILLBES BANDA el 1 de Abr. de 2020
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
WILLBES BANDA
WILLBES BANDA el 1 de Abr. de 2020
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 el 1 de Abr. de 2020
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 el 1 de Abr. de 2020
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 el 1 de Abr. de 2020
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]
Torsten
Torsten el 1 de Abr. de 2020
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 el 1 de Abr. de 2020
Noted. Thank you Honourable
Elvin
Elvin el 20 de Jul. de 2023
I tried this but it says "unrecognized function"

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Mathematics en Centro de ayuda y File Exchange.

Productos

Etiquetas

Preguntada:

el 1 de Abr. de 2020

Comentada:

el 20 de Jul. de 2023

Community Treasure Hunt

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

Start Hunting!

Translated by