You are on page 1of 15

Microcity College of Business and Technology

A Project in Integral Calculus:


Making an Application in Visual Basic for Computing the Area on a Certain
Function Using Left and Trapezoidal Method of Riemann Sums

Aldrin John V. Rativo


Christian John Napa
John Patrick Yco

Introduction

A Riemann sum is an approximation that takes the form


. It is
named after German mathematician Bernhard Riemann. One very common application is
approximating the area of functions or lines on a graph, but also the length of curves and
other approximations.
The sum is calculated by dividing the region up into shapes
(rectangles, trapezoids, parabolas, or cubics) that together form a region that is similar to
the region being measured, then calculating the area for each of these shapes, and finally
adding all of these small areas together. This approach can be used to find a numerical
approximation for a definite integral even if the fundamental theorem of calculus does not
make it easy to find a closed-form solution.
Because the region filled by the small shapes is usually not exactly the same shape
as the region being measured, the Riemann sum will differ from the area being measured.
This error can be reduced by dividing up the region more finely, using smaller and
smaller shapes. As the shapes get smaller and smaller, the sum approaches the Riemann
integral.
The four methods of Riemann summation are usually best approached with partitions
of equal size. The interval [a, b] is therefore divided into n subintervals, each of length

The points in the partition will then be

Left Riemann Sum


For the left Riemann sum, approximating the function by its value at the left-end
point gives multiple rectangles with base x and height f(a + ix). Doing this for i = 0,
1, ..., n 1, and adding up the resulting areas gives

The left Riemann sum amounts to an overestimation if f is monotonically


decreasing on this interval, and an underestimation if it is monotonically increasing.
Right Riemann Sum
f is here approximated by the value at the right endpoint. This gives multiple
rectangles with base x and height f(a + ix). Doing this for i = 1, ..., n, and adding up the
resulting areas produces

The right Riemann sum amounts to an underestimation if f is monotonically


decreasing, and an overestimation if it is monotonically increasing. The error of this
formula will be

where

is the maximum value of the absolute value of

on the interval.

Middle sum
Approximating f at the midpoint of intervals gives f(a + x/2) for the first interval,
for the next one f(a + 3x/2), and so on until f(b x/2). Summing up the areas gives

The error of this formula will be

where

is the maximum value of the absolute value of

on the interval.

Trapezoidal Rule
In this case, the values of the function f on an interval are approximated by the
average of the values at the left and right endpoints. In the same manner as above, a
simple calculation using the area formula

for a trapezium with parallel sides b1, b2 and height h produces

The error of this formula will be

where

is the maximum value of the absolute value of

The approximation obtained with the trapezoid rule for a function is the same as
the average of the left hand and right hand sums of that function.

Graphical Illustrations of the Riemann Sums methods:


Riemann sum methods of x3 over [0,2] using 4 subdivisions

Left

Right

Middle

Trapezoidal

Abstract
The developers created an application in Visual Basic for computing the area on a
certain function using Left and Trapezoidal method of Riemann Sums. This application
would help a lot of people to approximate the area of functions or lines on a graph while
considering the efficiency of the application. It is done by analyzing and simplifying the
formulas given in Riemann Sums that could be written as a code. The methods used by
the developers were the Left and Trapezoidal Method. The developers found some
solutions and alternatives to maximize the capability of the application in computing the
area while eliminating bugs and errors. The interface of the application was also simple
and informative, therefore making it more approachable and user-friendly.

Body and Content of the Application

Interface
Left Method:

a.) Textbox 1 to 4- The box that will guide the user to input his/her desired equation.

b.) Combobox 1 to 3- The combobox that can help the user to decide wether the certain
part of the equation would be + or -.
c.) Button 1- The button that will make the users choice to become an equation.
d.) Labelbox- The box that will show the whole equation.
e.) Textbox 5- The user can decide where will be the computation of the area starts.
f.) Textbox 6- The user can decide where will be the computation of the area ends.
g.) Textbox 7- The user can decide how many rectangles will be using for computation.
h.) Button 2-The button that will analyze and solve for the given problem.

i.) Labelbox- The box that will show the answer in square units.

Trapezoidal Method:

a.) Textbox 1 to 4- The box that will guide the user to input his/her desired equation.
b.) Combobox 1 to 3- The combobox that can help the user to decide wether the certain
part of the equation would be + or -.
c.) Button 1- The button that will make the users choice to become an equation.

d.) Labelbox- The box that will show the whole equation.
e.) Textbox 5- The user can decide where will be the computation of the area starts.
f.) Textbox 6- The user can decide where will be the computation of the area ends.
g.) Textbox 7- The user can decide how many trapezoids will be using for computation.
h.) Button 2-The button that will analyze and solve for the given problem.

i.) Labelbox- The box that will show the answer in square units.

Code
Left Method:
Public Class Form1
Dim equation, plusmin1, plusmin2, plusmin3 As Integer
Dim interval, start, ends, rect, area, norect, yans, yans2, yans3, yans4, yansf, val1, val2, val3,
val4 As Double
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
ComboBox1.Items.Add("+")
ComboBox1.Items.Add("-")
ComboBox1.SelectedIndex = 0
ComboBox2.Items.Add("+")
ComboBox2.Items.Add("-")
ComboBox2.SelectedIndex = 0
ComboBox3.Items.Add("+")
ComboBox3.Items.Add("-")
ComboBox3.SelectedIndex = 0
End Sub
Private Sub Button2_Click_1(sender As Object, e As EventArgs) Handles Button2.Click
interval = (TextBox6.Text - TextBox5.Text) / TextBox7.Text
yansf = 0
While norect < TextBox7.Text
yans = ((TextBox5.Text ^ 3) * TextBox1.Text)
If ComboBox1.Text = "+" Then
yans2 = yans + ((TextBox5.Text ^ 2) * TextBox2.Text)
Else
yans2 = yans - ((TextBox5.Text ^ 2) * TextBox2.Text)
End If
If ComboBox2.Text = "+" Then
yans3 = yans2 + (TextBox5.Text * TextBox3.Text)
Else
yans3 = yans2 - (TextBox5.Text * TextBox3.Text)
End If
If ComboBox3.Text = "+" Then

yans4 = yans3 + TextBox4.Text


Else
yans4 = yans3 - TextBox4.Text
End If
yansf = yansf + yans4
TextBox5.Text = TextBox5.Text + interval
norect = norect + 1
area = yansf * interval
End While
TextBox5.Clear()
TextBox6.Clear()
TextBox7.Clear()
Label10.Text = Label10.Text & area & " u."
Dim msgRslt As MsgBoxResult = MsgBox("Would you like to solve another problem?",
MsgBoxStyle.YesNo, "Greetings from the Developer!")
If msgRslt = MsgBoxResult.Yes Then
Application.Restart()
ElseIf msgRslt = MsgBoxResult.No Then
MsgBox("Thank you for using our application!", MsgBoxStyle.Information, "Greetings
from the Developer!")
Application.Exit()
End If
End Sub
Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles Button1.Click
Label6.Text = TextBox1.Text & "x " & ComboBox1.Text & TextBox2.Text & "x " &
ComboBox2.Text & TextBox3.Text & "x " & ComboBox3.Text & TextBox4.Text
End Sub
Private Sub TextBox6_Click(sender As Object, e As EventArgs) Handles TextBox6.Click
MsgBox("Ending point must be greater than starting point!", MsgBoxStyle.Information,
"Ending point > Starting Point")
End Sub
End Class

Trapezoidal Method:
Public Class Form1
Dim equation, plusmin1, plusmin2, plusmin3 As Integer
Dim interval, area, notrap, yans, yans2, yans3, yans4, yansf, yval, start, ends As Double
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
ComboBox1.Items.Add("+")
ComboBox1.Items.Add("-")
ComboBox1.SelectedIndex = 0
ComboBox2.Items.Add("+")
ComboBox2.Items.Add("-")
ComboBox2.SelectedIndex = 0

ComboBox3.Items.Add("+")
ComboBox3.Items.Add("-")
ComboBox3.SelectedIndex = 0
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Label6.Text = TextBox1.Text & "x " & ComboBox1.Text & TextBox2.Text & "x " &
ComboBox2.Text & TextBox3.Text & "x " & ComboBox3.Text & TextBox4.Text
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
interval = (TextBox6.Text - TextBox5.Text) / TextBox7.Text
yansf = 0
yval = 0
notrap = 0
While notrap <= TextBox7.Text
yans = ((TextBox5.Text ^ 3) * TextBox1.Text)
If ComboBox1.Text = "+" Then
yans2 = yans + ((TextBox5.Text ^ 2) * TextBox2.Text)
Else
yans2 = yans - ((TextBox5.Text ^ 2) * TextBox2.Text)
End If
If ComboBox2.Text = "+" Then
yans3 = yans2 + (TextBox5.Text * TextBox3.Text)
Else
yans3 = yans2 - (TextBox5.Text * TextBox3.Text)
End If
If ComboBox3.Text = "+" Then
yans4 = yans3 + TextBox4.Text
Else
yans4 = yans3 - TextBox4.Text
End If
If notrap = TextBox7.Text Then
yansf = yans4
yval += yansf
ElseIf notrap = 0 Then
yansf = yans4
yval += yansf
Else
yansf = yans4 * 2
yval += yansf
End If
TextBox5.Text = TextBox5.Text + interval
notrap = notrap + 1
End While

area = ((yval / 2) * interval)


TextBox5.Clear()
TextBox6.Clear()
TextBox7.Clear()
Label10.Text = Label10.Text & area & " u. "
Dim msgRslt As MsgBoxResult = MsgBox("Would you like to solve another problem?",
MsgBoxStyle.YesNo, "Greetings from the Developer:")
If msgRslt = MsgBoxResult.Yes Then
Application.Restart()
ElseIf msgRslt = MsgBoxResult.No Then
MsgBox("Thank you for using our application!", MsgBoxStyle.Information, "Greetings
from the Developer:")
Application.Exit()
End If
End Sub
Private Sub TextBox6_Click(sender As Object, e As EventArgs) Handles TextBox6.Click
MsgBox("Ending point must be greater than starting point!", MsgBoxStyle.Information,
"Ending point > Starting Point")
End Sub
End Class
Note: All of the codes were owned by the developers. Manipulating, plagiarizing and selling this application without the consent of
the developers would violate copyright laws. Thank you for your cooperation.

Procedures and Proofs


Left Method:
Equation: 2x+3x+4x+5
Start: 2
End: 6

No. Of Rectangles: 2

Solution: (emathhelp.net/calculators/calculus-2/riemann-sum-calculator/)

The Application:

Trapezoidal Method:
Equation: 4x+5x+6x+7
Start: 2
End: 10

No. Of Trapezoids: 4

Solution:(emathhelp.net/calculators/calculus-2/riemann-sum-calculator/)

The Application:

Note: For more detailed proof of the application, just go to:


(https://www.youtube.com/watch?v=wJ2Q4jKqBnY)

Limitations and Conclusion:


The application deals with the computation of the area in a certain function that
would be filled by the user. Thus, making it more limited to compute a more specific
user-defined function.The speed for computing the area was great compared to the
calculator that can be found on the internet because it deeply relies on different factors
such as the speed of internet connection and specifications of the machine or personal
computer that would be used. The application only shows the computed area, while some
sites on the internet also contains the solutions for solving it. The application has a lot of
space in terms of improvement but it is fully functional and efficient right now.
Hopefully, this would not be the final version of it because it has a lot of potential in
innovating and helping the world and its people.
.

Bibliography
https://en.wikipedia.org/wiki/Riemann_sum
https://emathhelp.net/calculators/calculus-2/riemann-sum-calculator/
https://www.youtube.com/watch?v=wJ2Q4jKqBnY
http://mathworld.wolfram.com/RiemannSum.html

You might also like