How to plot Left - Rigth - Mid riemman sum of this code?
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Monisha Nalluru
2020-10-30
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Discrete Data Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!