Borrar filtros
Borrar filtros

Hello I need help with my left Riemann Sum loop

1 visualización (últimos 30 días)
Jesutofunmi Palmer
Jesutofunmi Palmer el 5 de Ag. de 2016
Respondida: MADISON OHARA el 17 de Nov. de 2020
I'm trying to find the left riemann sum of 3x^2 +4 on [0,5] where I have n = 10 (rectangles). I would appreciate it deeply if someone could take a look at my program and tell me why I keep getting the wrong answer. It should be 126.875, but I keep getting 52. I know that left Riemann sum is a+(k-1)Δx, for k=1,....n.
a = 0;
b = 5;
n = 5;
dx = (b-a)/n;
for k = 1:n-1
Lsum = a +dx*(3*(k)^2+4);
end
display(Lsum)

Respuestas (2)

Geoff Hayes
Geoff Hayes el 6 de Ag. de 2016
Jesutofunmi - look closely at your code
for k = 1:n-1
Lsum = a +dx*(3*(k)^2+4);
end
display(Lsum)
On each iteration of the for loop, you are ignoring what came previously so you end up with Lsum being assigned the a value from the last iteration of your for loop. You need to sum this value with what came previously as
Lsum = 0;
for k = 1:n-1
Lsum = Lsum + a +dx*(3*(k)^2+4);
end
display(Lsum)
This still won't give you the correct answer though. What is the function (curve) that you are calculating the area for? Define it as an anonymous function like
f = @(x)3*x^2 + 4;
The above is an example based upon what you have shown but it may not be the function that you are interested in. Then your sum would become
Lsum = Lsum + dx*f(k);
where k is an input. So what should that input be? Since this is homework, we can only give out hints. Review your class notes and try to figure out what it should be. See http://mathinsight.org/calculating_area_under_curve_riemann_sums for guidance as well.
  1 comentario
Jesutofunmi Palmer
Jesutofunmi Palmer el 8 de Ag. de 2016
Thank you so much for the hints. My calculus professor just dumped this on the class saying we can ask for help when it came to coding since most people in the class never used matlab before, but I understand the moral intgrity that has to be exercised on this forum. I'll get back on campus to work on it.

Iniciar sesión para comentar.


MADISON OHARA
MADISON OHARA el 17 de Nov. de 2020
for k = 1:n-1
Lsum = a +dx*(3*(k)^2+4);
end
display(Lsum)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by