How to plot Left - Rigth - Mid riemman sum of this code?

1 visualización (últimos 30 días)
David Araujo
David Araujo el 20 de Oct. de 2020
Respondida: Monisha Nalluru el 30 de Oct. de 2020
I have this code, its for the left riemman sum
how can i plot this?
x1 = 1;
x2 = 4;
f=@(x)x;
n=500;
dx=(x2-x1)/n;
leftSum=0.0;
for i=1:n
leftSum=leftSum+f(x1+dx*(i-1));
end
leftSum=leftSum*dx;
x = linspace(0,11);
y = linspace(0,11);
xa = linspace(0,10,11);
z=integral(f,x1,x2);

Respuestas (1)

Monisha Nalluru
Monisha Nalluru el 30 de Oct. de 2020
You can use bar and plot function and achieve the required output
As an example
lowerlimit = 1;
upperlimit = 4;
bins = 10;
x = linspace(lowerlimit,upperlimit); % points for function
y = x;
xa = linspace(lowerlimit,upperlimit,bins); % for bar plot points
ya = xa;
bar(xa,ya,'histc')
hold on
plot(x,y);
hold off
You can change the xa,ya values according to your function handle inputs!

Categorías

Más información sobre Discrete Data Plots 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