Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 16

VIETNAM NATIONAL UNIVERSITY

HO CHI MINH UNIVERSITY OF TECHNOLOGY

c···®···d

PROJECT REPORT

NUMBERING METHODS
Topic 1: Using Simpson’s method to measure area of a province

Lecturer: Hoàng Hải Hà

Semester: 231

Class: MT1009 – CC01

Group: 01

No. Student name Student ID


1 Lê Sỹ Anh Đức 2152522
2 Ngô Đại Quý 2153759
3 Trần Đức Thuận 2053471
4 Đinh Văn Việt Hùng 2153401

Ho Chi Minh City – 2023

0
Table of Contents
PART I: THEOREM...........................................................................2
1.1. Introduction to Simpson method...................................................................................2

1.2. Introduction to Cubic Spline..........................................................................................4


1.2.1. Natural Cubic Spline......................................................................................................................6
1.2.2. Clamped Cubic Spline...................................................................................................................7

1.3. Objective of the project.................................................................................................7

PART II: CALCULATION – MATLAB CODE.................................8


2.1. Procedure......................................................................................................................8

2.2. Directions to solve the problem.....................................................................................9

2.3. MATLAB Code..............................................................................................................10


2.4 The result ……………………………………………………………………………………………………………....13

Reference:..........................................................................................15

1
PART I: THEOREM

1.1. Introduction to Simpson method


Simpson's rule is a numerical integration technique that approximates the definite
integral of a function. It uses quadratic polynomials to fit the curve of the function and
provides an accurate estimate of the integral.

The basic idea behind Simpson's rule is to divide the interval of integration into
smaller subintervals and approximate the function within each subinterval using
quadratic polynomials. The integral over each subinterval is then calculated by
integrating the quadratic polynomial. The results from all the subintervals are then
combined to obtain the final estimate of the integral.

To apply Simpson's rule, the interval of integration is divided into an even


number of subintervals. The more subintervals used, the more accurate the
approximation becomes. For each subinterval, three points are selected: the endpoints
of the subinterval and the midpoint. Simpson's rule uses these three points to construct
a quadratic polynomial that closely matches the function within the subinterval.

The integral over each subinterval is then calculated using the quadratic
polynomial. Simpson's rule approximates the integral as the sum of the integrals over
all the subintervals. Mathematically, the integral using Simpson's rule can be
expressed as:

Δx
∫ [ a , b ] f ( x ) dx ≈
3
[ f ( a )+ 4 f ( a+ Δx )+ 2 f ( a+2 Δx ) +…+ 4 f ( b− Δx ) + f ( b ) ]

by ( b−a )
Where Δx is the width of each subinterval, given , where n is the number of
n
subintervals.

Simpson's rule provides a more accurate estimate of the integral compared to


simpler methods like the Trapezoidal rule. It is particularly effective for functions that
can be well approximated by quadratic polynomials within each subinterval.

2
Assume that we subdivide the interval [a , b] into n=2 m subintervals. On each two
consecutive intervals, we use a curved trapezoid. Then this is the picture:

We thus have the following approximation:

That is

Here

n
m=
2

3
Understanding the features of a province requires calculating its area. Simpson's
1/3 Rule is a dependable and effective solution for this activity.

Simpson's Rule was chosen for the following reasons:

1. Precision: Taking into account the land's smoothness and curvature, Simpson's
1/3 Rule yields exact findings.

2. Flexibility: It adjusts to the varied geography of that province, accommodating


irregular forms and curves.

3. Efficiency: By splitting the region and applying interpolation, the rule decreases
processing effort while preserving accuracy.

4. Reliable for Smooth Curves: It successfully handles smooth curves, assuring


accurate area calculations.

Due to its precision, flexibility, efficiency, dependability, variety, scientific validity,


historical importance, educational value, comparability, and future uses, Simpson's 1/3
Rule is an excellent choice for estimating the province's area.

1.2. Introduction to Cubic Spline


In order to use Simpson method to calculate the area, we need to find function
f ( x ) and extraodinary values, which express the area of the province, by using Cubic
Spine method as an intermediate ones.

Cubic splines are a technique for generating a smooth curve that goes through a
set of points. The goal is to divide the curve into smaller parts and then fit a cubic
polynomial to each one.

The main idea is to make the final curve continuous and visually appealing.
Cubic splines impose the following criteria to do this:

1. Interpolation: The curve goes across each of the data points provided. This
guarantees that the produced curve represents the original data properly.

4
2. Continuity: There are no sudden shifts or discontinuities in the curve. This
implies that when neighbouring portions of the curve meet, they join
seamlessly.
3. Differentiability: The curve's derivatives are well-defined. This guarantees that
the curve is not just smooth but also Visually and statistically smooth, allowing
for additional analysis or calculations.

Cubic splines can meet these constraints by fitting cubic polynomials to each
segment. The cubic polynomials are sufficiently flexible to capture the curve's local
behaviour, and the constraints ensure that the segments blend together flawlessly.

The procedure entails solving a series of equations to determine the coefficients


of the cubic polynomials. These equations take into account the provided data points
as well as the continuity requirements at the sites where segments intersect.

Once the coefficients are determined, the cubic spline may be evaluated at any
desired position on the curve to yield the associated value.

5
1.2.1. Natural Cubic Spline

6
1.2.2. Clamped Cubic Spline

1.3. Objective of the project


Our team supposed to take a survey on Kon Tum province, which is a beautiful area of
Vietnam locating in the middle of the country. We aim to use the above method to
measure the area of Kon Tum, which is an achivement of this study in Numbering
Methods.

7
PART II: CALCULATION – MATLAB CODE

2.1. Procedure
Below is our team procedure of taking data:

1. We first take Bac Ninh province ID (1902690) from a geometry website called
OpenStreetMap1.Duplicate the layer in case the original layer has a problem, it can
still be fixed.
2. Then we access the website Polygon creation2, to download the polygon data of
Bac Ninh province.
3. We choose the poly data (as shown in the image) .

4. Create an Excel file named bacninh.xlsx with the poly data.


5. Coding for the input data, cubic spline interpolation, and Simpson’s rule.
6. Finally, import the coordinates from Excel file for MATLAB calculation.

1
https://www.openstreetmap.org/
2
https:// Polygon creation (openstreetmap.fr)
8
2.2. Directions to solve the problem
The formula has the following form:

w
Area= ( y + 4 ( y odd ) +2 ( y even )− y last ) ( 1 )
3 first

When:

w : is the distance between two values h ( x ) or y

y first : first value of y

y odd : sum of y i values where i is an odd number

y even: sum of y i values where i is an even number

y last : last value of y

Then we follow these steps:

1. Use Google Earth to collect coordinates of Bac Ninh province with 2 upper and
lower contours.
2. Use a Cubic Spline to interpolate the function to approximate the upper and
lower boundaries, set the above functions as f ( x ) and g ( x ), respectively. Then
build the function y=h ( x ) =f ( x )−g ( x ) to correspond to each value of x i, we get
the value of y i as shown.
3. Divide the area to be calculated into 1645 segments from there we have:

x 1645 −x 1
w=
1645

9
2.2. MATLAB Code
clc;
clear;

file = 'bacninh.xlsx';

data = xlsread(file);

% Split the data into two equal halves


half = size(data, 1) / 2;
data_top = data(1:half, :);
data_bot = data(half+1:end, :);

% Extract x and y values for top and bot data


x1 = data_top(:, 1);
y1 = data_top(:, 2);
x2 = data_bot(:, 1);
y2 = data_bot(:, 2);

%
min_n1 = min(x1);
min_n2 = min(x2);
max_n1 = max(x1);
max_n2 = max(x2);

% Make sure x values are unique


[unique_x1, idx1] = unique(x1, 'stable');
unique_y1 = y1(idx1);
[unique_x2, idx2] = unique(x2, 'stable');
unique_y2 = y2(idx2);
idx1 = round(idx1);
idx2 = round(idx2);

% Perform cubic spline interpolation


f = @(x) ppval(spline(unique_x1, unique_y1), x);
g = @(x) ppval(spline(unique_x2, unique_y2), x);

% Define the range of x values


x_range = linspace(min(min(unique_x1), min(unique_x2)), max(max(unique_x1), max(unique_x2)), 1000);

% Evaluate the functions at the points in the range


f_values = f(x_range);
g_values = g(x_range);

% Find the maximum and minimum of the functions


f_max = max(f_values);
f_min = min(f_values);
g_max = max(g_values);
g_min = min(g_values);

%
n = max(min_n1,min_n2); %starting point of the area
m = min(max_n1,max_n2); %ending point of the area

% Calculate the area under the curve using Simpson's rule


area_f = integral(f, min(x_range), max(x_range));
area_g = integral(g, min(x_range), max(x_range));

% Take the absolute value of the area under the curve of g(x)

10
area_g = abs(area_g);

% Calculate the sum of the areas


sum_area = area_f + area_g;

% Check if all elements in idx1 are positive integers


isPositiveInteger_idx1 = all(isreal(idx1) & isfinite(idx1) & idx1 > 0 & idx1 == floor(idx1));
isPositiveInteger_idx2 = all(isreal(idx2) & isfinite(idx2) & idx2 > 0 & idx2 == floor(idx2));

% Display the results


fprintf('All elements in idx1 are positive integers: %d\n', isPositiveInteger_idx1);
fprintf('All elements in idx2 are positive integers: %d\n', isPositiveInteger_idx2);

% Display the results


fprintf('Max of f(x): %f\n', f_max);
fprintf('Min of f(x): %f\n', f_min);
fprintf('Max of g(x): %f\n', g_max);
fprintf('Min of g(x): %f\n', g_min);
fprintf('Area under the curve of f(x): %f\n', area_f);
fprintf('Area under the curve of g(x): %f\n', area_g);

% Plot the interpolated functions


figure;
plot(x1, y1, 'r'); % Plot the top data
hold on;
plot(x2, y2, 'b'); % Plot the bottom data
title('2D Map of the Province');
xlabel('Longitude (WGS84)');
ylabel('Latitude (WGS84)');
legend('Top Data', 'Bottom Data');
grid on;
axis equal;

% Plot the area under the curve


figure;
area(x_range, f_values - min(f_values), 'FaceColor', 'r');
hold on;
area(x_range, g_values - min(g_values), 'FaceColor', 'b');
title('Area under the curve');
xlabel('x');
ylabel('y');
legend('Area under f(x)', 'Area under g(x)');
grid on;
hold off;
disp(size(x_range));
disp(size(f_values - min(f_values)));
if any(f_values - min(f_values) < 0)
disp('Negative values found');
end

% Create a new figure


fig = figure;

% Set the figure size [left, bottom, width, height]


set(fig, 'Position', [100, 100, 400, 300]);

% Now you can plot your graph


plot(x_range, f_values, 'r', 'LineWidth', 2);
hold on;
plot(x_range, g_values, 'b', 'LineWidth', 2);

11
title('Interpolated Functions');
xlabel('x');
ylabel('y');
legend('f(x)', 'g(x)');
grid on;

%Plot the simulation of the province


plot(x1,y1);
ylim([min(f_min,g_min),max(f_max,g_max)]);
title('Mo phong toa do ban do cua tinh');
xlabel('Truc X');
ylabel('Truc Y');
hold on;
plot(x2,y2);

% Display the results


fprintf('Area under the curve of f(x): %f\n', area_f);
fprintf('Area under the curve of g(x): %f\n', area_g);
fprintf('Sum of the areas under f(x) and g(x): %f\n', sum_area);

12
2.4. The Results
The Interpolation mapping

The Area under the curve

13
The Command Window

Comparing to the real data

The real data area is 822,71km2


The Simpson’s rule data is 886,2533km2
∆=886,2533−822 ,71=63,5433=7,7237 %

14
REFERENCE:

[1] Burden, Richard L., J. Douglas Faires, and Annette M. Burden. Numerical
analysis. Cengage learning, 2015.

15

You might also like