How to plot Left - Rigth - Mid riemman sum of this code?
2 ビュー (過去 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 で Annotations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!