How to plot Left - Rigth - Mid riemman sum of this code?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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);
0 Kommentare
Antworten (1)
Monisha Nalluru
am 30 Okt. 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!
0 Kommentare
Siehe auch
Kategorien
Mehr zu Annotations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!