Cambié un poco el código, pero casi nada.
clearvars;
a = 0; b = 2;
n_rec = 100;
delta_x = (b-a)/n_rec;
x = 0:delta_x:2;
f=funcion(x);
area_Integral = integral(f,0,2);
area_R = 0;
area_L = 0;
for i = 1:n_rec
area_R = area_R + f(x(i + 1))*delta_x;
area_L = area_L + f(x(i))*delta_x;
end
resultados = table(area_Integral,area_L,area_R)
function f=funcion(x)
f=@ (x) x.^3 - 3*x.^2 + 3*x;
end
Espero que te sirva :D
2 Comments
Direct link to this comment
https://uk.mathworks.com/matlabcentral/answers/676898-need-help-with-a-riemann-sum#comment_1181943
Direct link to this comment
https://uk.mathworks.com/matlabcentral/answers/676898-need-help-with-a-riemann-sum#comment_1181943
Direct link to this comment
https://uk.mathworks.com/matlabcentral/answers/676898-need-help-with-a-riemann-sum#comment_1182003
Direct link to this comment
https://uk.mathworks.com/matlabcentral/answers/676898-need-help-with-a-riemann-sum#comment_1182003
Sign in to comment.