I am calculating the absolute error of a summation compared to an integral (summation answer – integral answer):
integral of e^x from 0 to 1, compared to (1/n)*summation(e^rand()) from i = 1 to n.
I have to plot the error vs n in matlab. I can’t wrap my head around how to do this. I am able to calculate the error from 1 to an arbitrary number like 50 by using a for loop from 1 to 50. But, how would I plot this? I would need to do multiple summations to different values of n correct?
So what you want to do is calculate the area with the integral and the error function at the same time and store them in an array:
Then you can plot like this: