Effacer les filtres
Effacer les filtres

Making a Riemann Sums function with multiple n values

1 vue (au cours des 30 derniers jours)
Gurinder Punni
Gurinder Punni le 12 Nov 2020
clc;clear;
fun = input('what is the function: ');
a = input('what is a: ');
b = input('what is b: ');
n = input('what is n: ');
N=length(n);
h = (b-a)/N;
sum = 0;
for j=1:N
h(j) = (b-a)/n(j);
sum(j) =fun(a+h(j)*(j-1));
end
sum(n) = sum(n).*h(n);
disp(sum)
So, I am trying to create a Riemann sums function and want the final value to be an array of the chosen n values, e.g. n = 1:10. So, the values as you increase should become more accurate to the actual integral. But, When I look at the results, they just get smaller over time not even close to the actual value. When I was trying to find the integral with just 1 n, I got a pretty close value to the actual integral. I am not sure what I did wrong in converting it to an array format.

Réponses (0)

Catégories

En savoir plus sur Mathematics dans Help Center et File Exchange

Tags

Produits


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by