Function for Riemann Sum
Function calculator offers excellent extensibility in calculations, not only providing basic arithmetic operations but also allowing users to create mathematical functions through programming.
In this example, we'll utilize this outstanding extensibility to calculate the definite integral or Riemann sum of a quadratic function.
We'll assume the quadratic function takes the general form ax2+bx+c
You can program code as bellows in the factory page of Function Calculator.
def RiemannSum(a,b,c,start,end,n){
var Sn=0;
var delta=(end-start)/n;
var k=1;
while(k<=n){
var x=start+delta*(k-0.5);
var h=a*x*x+b*x+c;
var s=delta*abs(h);
Sn=Sn+s;
k=k+1;
}
return Sn;
}
After write code click 'run' button to execute the code and click 'save' button to save the function in DB.
Return to the Calculator page and click 'F2' button to use the function we just created in calculation.
In the parameters, a is the coefficient of the quadratic term, b is the coefficient of the linear term, c is the constant term, start is the starting point of the definite integral, end is the endpoint, and n is the number of subdivisions. As mentioned in high school math textbooks, the more subdivisions we make, the closer the calculated value gets to the actual area.
Sn represents the total area we're trying to calculate, and delta will be the width of each subdivided rectangle. k is the index exponent, running from 1 to n, sweeping through each subdivided small rectangle, with h being the height at each point. At this time, s becomes the instantaneous area of the subdivided small rectangle. The brilliant idea of past mathematical geniuses was that summing up all these small areas as k sweeps through would result in an area very close to the actual total area.
Now, we can calculate the Riemann sum on the calculator as follows:
Try calculating the areas of various quadratic functions using the function calculator as shown above.
Comments
Post a Comment