Professional Documents
Culture Documents
Cc01 - Group 11 - Numerical Methods Final Project
Cc01 - Group 11 - Numerical Methods Final Project
--------o0o--------
GROUP 11 – TOPIC 1
Class: CC01
Group: 11
Semester: 231
Numerical methods – Topic 1
Table of Contents
I) Group members .............................................................................................................. 3
II) Job role of each members & Work evaluation.................................................................. 3
III) Introduction ................................................................................................................. 4
IV) Calculation ................................................................................................................. 5
A) Theory and algorithm ................................................................................................. 5
B) Solving the problem by using Matlab ........................................................................... 6
1. Choosing a topic and object for the project .............................................................. 6
2. Data collecting procedure ...................................................................................... 7
3. Final data ........................................................................................................... 22
4. Convert table ...................................................................................................... 24
5. Main Code session .............................................................................................. 25
6. Explaining the code ............................................................................................ 27
7. Final result ......................................................................................................... 32
V. Conclusion ................................................................................................................. 34
VI. References ................................................................................................................. 35
Numerical methods – Topic 1
I) Group members
III) Introduction
Numerical methods play a pivotal role in solving mathematical problems that lack closed-
form analytical solutions. As we delve into the realm of mathematical modeling, engineering
simulations, and scientific computations, the limitations of traditional analytical techniques
become apparent. It is in this landscape that numerical methods emerge as indispensable tools,
offering solutions to complex problems through iterative algorithms and computational
techniques.
Numerical methods provide a means to approximate solutions to mathematical problems that may
defy exact analysis. These methods are particularly crucial when dealing with functions that are
intricate, discontinuous, or lack a straightforward algebraic expression. One such numerical
technique that stands out in the realm of numerical integration is Simpson's rule.
In this project, we will use knowledge gained from university to solve the required problems.
Numerical methods – Topic 1
IV) Calculation
A) Theory and algorithm
The Simpson's rule is a numerical integration method used to approximate the definite
integral of a function. It's based on approximating the curve defined by the function with a series
of parabolic arcs.
The basic idea behind Simpson's rule is to divide the area under the curve into a series of narrow,
equal-width subintervals and then use the quadratic interpolating polynomials for each pair of
adjacent subintervals.
𝑏−𝑎
Here, n = 2 is the number of subintervals, h is the width of each subinterval (given by ℎ = ,
𝑛
Simpson's rule gives just an approximate value of the integral, not the exact value. So there is
always an error that can be calculated using the following formula.
Simpson's rule is used to calculate the area of a province because it provides an accurate method
for calculating the area under a curve or the volume of a shape. It's an important method in the
field of Surveying, helping to calculate areas based on diameters.
Simpson's rule states that, the sum of the first and last diameter must be made. Add twice the sum
of the remaining diameters and four times the sum of the remaining diameters. Multiplying this
sum by 1/3 of the common distance between the diameters will give the area sought.
Simpson's rule provides more accurate results than other methods like the Midpoint rule or the
Trapezoidal rule, as it uses parabolas to approximate each part of the curve, rather than rectangles
or trapezoids.
Since it is a large area, and as mentioned above, Hanoi has clear boundaries, which
will be an advantage in collecting data for upcoming calculations.
Numerical methods – Topic 1
As Hanoi is a focal location, known to many, public information about this location
will achieve a certain level of accuracy, thereby ensuring the input information is
accurate, and thus the calculated results are as close to reality as possible.
The picture below shows the actual shape of the area when it is shown in satellite Map
This tool allows you to create, edit, visualize, analyze, and publish geospatial information.
After choosing Vietnam as download object, we choose Shapefile extension and download it for
further steps
c. Step 3: Import data into QGIS
In QGIS, we create a New project. Then we add map file into this app. Remind that, we can only
use data with the “.shp” extension only. Any other extension will cause the error dialog as the
app will not be able to generate the data for out project.
The downloaded data is divided into many types of extensions, however, as metioned before, we
only choose all the data of Vietnam area that have a “.shp” extension
Numerical methods – Topic 1
Firstly, we choose the geometry properties for the shape by clicking: “Vector” “Geometry
tools” “Add geometry properties”
Numerical methods – Topic 1
Then, the app will show us all the properties of the area, including the ID, Name, and the most
important information is the statistics of the latitude and longitude in 3 directions: left, top right
and bottom.
The eliminating procedure can be done with the shortcut function as “Ctrl + L”
After eliminating all of the excess data, will we export the points as its value according to the
coordinate axis to an Excel file. Steps can be done as “Export” “Save as”. Be careful to save
the file with the .xlsx extension to ensure that we will have an Excel file
3. Final data
The final data can be seen clearly in the excel file. In this report, we will only show a part of
the final data as below
Numerical methods – Topic 1
Figure 3.1. First 25 data values of the latitude and the longitude
Besides, we also have the statistics about the minimum, maximum value of both latitude and
longitude, as well as the mean value of that 2 variable. All of that statistic values are shown in
the table below
Numerical methods – Topic 1
Link: https://docs.google.com/spreadsheets/d/19UVZQWVXnYEXaA-iZoHXmJ-
LobvAPdj2/edit?usp=drive_link&ouid=100182846651200143264&rtpof=true&sd=true
For using this file, please download it to your computer with the “.xlsc” extension (Excel file).
Then, upload the file into the MATLAB Drive. Please also remind that if you change the file
name, you should change the “Location.xlsx” into your file name instead of “Location” in our
report.
4. Convert table
Below is the convert table that we use the resource from Wikipedia website. This convert table
show the relationship between the latitude and its related values. The concept of this calculation
is based on the Interpolation theory that we’ve already learned in our course
Below is the value of average longitude that is already transformed to distance format. The
formula is also illustrated in the table.
Average Longitude Average distance North- South Average distance West – East
(20.9853 - 15)*(110.852 - (20.9853 - 15)*(96.486 -
20.9853
110.649)/(30 - 15) + 110.649 107.551)/(30 - 15) + 107.551
Numerical methods – Topic 1
% Convert degree to km
Lattitude_Convert = (20.9853 - 15)*(110.852 - 110.649)/(30 - 15) + 110.649;
Longitude_Convert = (20.9853 - 15)*(96.486 - 107.551)/(30 - 15) + 107.551;
% Compute y(i)
Lattitude = [];
for i = 1 : Size_of_Data(2)
Lattitude_i = 0;
for j = 1 : Size_of_Data(1)/2
Lattitude_i = Lattitude_i + abs(Data(2*j,i) - Data(2*j-1,i));
end;
Lattitude = [Lattitude Lattitude_i];
end;
y = Lattitude_Convert*Lattitude;
% Compute the area by using Simpson's method
w = Longitude_Convert*Longitude_Deviation;
y_first = 0;
y_last = 0;
y_odd = 0;
y_even = 0;
for i = 1 : Size_of_Data(2)
if i == 1
y_first = y(i);
elseif i == Size_of_Data(2)
y_last = y(i);
elseif i - 2*round(i/2) == 0
y_even = y_even + y(i);
else
y_odd = y_odd + y(i);
end;
end;
Area_of_province = (w/3)*(y_first + 4*y_odd + 2*y_even + y_last)
Numerical methods – Topic 1
It means, our data when generating into matrix form, has a size of 3076 rows and 2 columns
Data = [];
Compare_Var = Root_Data(1,2);
Col = 1;
Row = 1;
for i = 1 : Size_of_Root_Data(1)
if Root_Data(i,2) == Compare_Var
Data(Row,Col) = Root_Data(i,1);
Numerical methods – Topic 1
Row = Row + 1;
else
Data(1,Col+1) = Root_Data(i,1);
Compare_Var = Root_Data(i,2);
Col = Col + 1;
Row = 2;
end;
end
Size_of_Data = size(Data);
With this table, we can conclude the concept that each column shows latitude that correspond
with each longitude. The same concept will be applied for all of the other longitude of the data.
c. Convert degree to km
Lattitude_Convert = (20.9853 - 15)*(110.852 - 110.649)/(30 - 15)
+ 110.649;
Longitude_Convert = (20.9853 - 15)*(96.486 - 107.551)/(30 - 15)
+ 107.551;
This step shows the covert formula of latitude and longitude value. The concept of this function
is based on the Interpolation formula. Combine it with the convertible shown above, we can
easily transform the value of latitude and longitude in our data into form of length measures in
km.
end;
y = Lattitude_Convert*Lattitude;
- Aware that at this point, we will use the value of “Size_of_Data(1)/2” instead of
“Size_of_Data(1)” because for each step of the stage, we use 2 continuous value instead
of 1. That means, for each looping turn, we will scan over 2 value. So, the total number
of scanning turn will only be half of the total data.
- Remind that the function “for i = …” just only for defining the number of scanning
turn. One another important value: the number of value that will be scan over in each
time have not been defined yet in this step.
- One more thing that need to be focus here is, rows that have no value should be processed
before coming to this stage. The data processing step will replace the empty value with
“0” so that the computing steps will not be effected by this problem.
for i = 1 : Size_of_Data(2)
if i == 1
y_first = y(i);
elseif i == Size_of_Data(2)
y_last = y(i);
elseif i - 2*round(i/2) == 0
y_even = y_even + y(i);
else
y_odd = y_odd + y(i);
end;
end;
Area_of_province = (w/3)*(y_first + 4*y_odd + 2*y_even +
y_last)
- At this final stage, we will define 4 types of y value in order to apply the area formula
- Simply explain the code
First of all, we will compute the value of w, which is the equal distance between
longitudes by the formula: “Longitude_Convert*Longitude_Deviation”
Secondly, we set up 4 types of y and assign 0 value to it
Using looping function with starting point when i=1, we will scan over the whole
longitude value of the data
o With “y_first”, we assign the first value of y (y(1))
o With “y_last”, we assign the last value of y (y(i))
With the same process, other y values will be defined into 2 groups: even values
and odd value by the function: i – 2*round(i/2) == 0.
o The value of i will be an even number if the function is true. The y value now
will be assign to the y_even
o Otherwise, it will be an odd number and will be assigned into the y_odd
The final value of “y_last” or “y_final” will be the total value of all the “y_last”/ “y
final
Numerical methods – Topic 1
Finally, we compute the area of Hanoi by the Simpson’s rule, with the formula:
“Area_of_province = (w/3)*(y_first + 4*y_odd + 2*y_even + y_last)”
- With this final stage, we remind you two important things
The value of “y_even” and “y_odd” is computed as a sum of all even or odd value.
This issue will not affect the final result since the in the Simpson’s rule, we will not
use the value of each even or odd variable, but the sum of it
The concept of analyzing odd or even values can be explained as followed
o assume that we have i = 3, the formula i – 2*round(i/2) will become: 3 – 2*2
= -1 (3/2 = 1,5, the round up value of it will be 2). Since the result is
different from 0, we will conclude 3 is an odd number, as it is.
o On the other hands, assume that we have i = 4, the formula i – 2*round(i/2)
will become: 4 – 2*2 = 0 (4/2 = 2 is the whole number so we do not need to
round it up). Since the result is equal to 0, we will conclude 4 is an event
number, as it is.
7. Final result
After applying the above formula, we finally computed the approximate value of area of Hanoi.
The value is about 3432 km2. The appearance shown in the program is as the figure below:
Numerical methods – Topic 1
Note that, the program shown us the value of “3.4320e+03”, with “…e+03” means, to find the
actual value, we will need to multiply 3.4320 with 10 cubed, or 1000.
Besides, we also finding the actual value of the area of Hanoi. The real number that is published
on the government website is 3360 km2 as the “Area Capital city and municipality” session
below
Compare with the real value of the area of Hanoi, which is about 3360 km2, we will calculate the
error of this application is about 2,14%
Numerical methods – Topic 1
V. Conclusion
By applying some acknowledgment that has been already taught in our course, we can
understand the concept of using Simpson's rules in approximating the existing as we have done
in this topic.
With the given topic, we chose Simpson's rules as the main numerical method to analyze data in
the form of Latitude and Longitude, then, generate them into a suitable statistical form that can be
used in our code.
In the coding session, firstly, we import the data in an Excel file into the Matlab applications. After
that, we start filtering all the necessary data, besides eliminating excess data so that we will a clear
data for our code without any hand-made filtering.
The main coding session includes 2 main stages: setting up data and computing the final value of
our object. By using a loop function that can help us scan over all the data, we can calculate the
area based on all of that statistical value.
In comparison to other methods to approximate the area such as measuring or other Calculus
methods such as Riemann Sums, Definite Integrals, and Method of Exhaustion…, Simpson's rule
is more flexible and simple as it only requires information about the latitude and longitude to
calculate the specific area without any obstacle.
Moreover, this is a potential and perfect method for this kind of request, since Simpson’s rule has
several advantages when it comes to numerical integration:
- Accuracy: Simpson’s rule provides a more accurate approximation of the area under the
curve, especially for curves that are not smooth or have rapid variations. It is based on the
Numerical methods – Topic 1
fact that given any three points, you can find the equation of a quadratic through those
points
- Efficiency: It requires fewer data points than the Trapezoidal Rule to achieve similar
accuracy. This makes it efficient for larger datasets
- Versatility: While rectangles and trapezoids work better for linear functions, Simpson’s
Rule works quite well on curves. It uses quadratic polynomial approximations instead of
straight lines, which gives more accurate results.
- Polynomial Interpolation: Simpson’s rule is one of the Newton-Cotes formulas used for
approximating the value of a definite integral. It approximates the function using fitting
polynomial identities found by Lagrange interpolation4.
- Exact Results for Polynomials: Simpson’s rule provides exact results for any polynomial
of degree three or less, since the fourth derivative of such a polynomial is zero at all
points
Overall, Simpson’s rule is a powerful and versatile method that is well-suited for analysing data
as well as computing the area of specific place approximated outcomes. It provides direct
estimates of value, is flexible and easy to use, and can handle a wide range of data types and
distributions.
VI. References
[8] K. E. Atkinson, An Introduction to Numerical Analysis (2nd edition), John Wiley & Sons,
1989.
[9] J. D. F. A. M. B. Richard L. Burden, Numerical analysis, Cengage Learning, 2015.