Skip to content

Instantly share code, notes, and snippets.

@VincentTam
Last active January 29, 2018 00:30
Show Gist options
  • Save VincentTam/add7df0dd59037d2d21cc73f1844cdb5 to your computer and use it in GitHub Desktop.
Save VincentTam/add7df0dd59037d2d21cc73f1844cdb5 to your computer and use it in GitHub Desktop.
Nvec = 10000:10000:1000000; % no of intervals
rrsumvec = zeros(size(Nvec));
for ind = 1:length(Nvec)
N = Nvec(ind);
dx = 5 / N;
x = (1:N) * dx;
fx = sqrt(25 - x.^2);
rrsum(ind) = sum(fx * dx);
end
% plot the graph
figure
hold on
title("Numerical riemann sum vs theoretical value")
plot(Nvec,25*pi/4*ones(size(Nvec)),"-r");
plot(Nvec,rrsum,"-b");
legend("Theoretical","Numerical")
legend("location", "southeast")
hold off
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment