You are on page 1of 24

ESSE 3620 Lab

Non-Linear Parametric Adjustment

Submitted to:
Dr. Spiros Pagiatakis
Patrick Lasagna

Name: Won Mo Jung


E-mail: dnjsah94@my.yorku.ca

York University

Introduction:

The purpose of this lab was to adjust the traverse network using the non-linear parametric
adjustment.

Methodology:

This lab was done by using non-linear parametric adjustment. The following model is the basic
form of non-linear parametric adjustment:
= (, ) (1)
In this case, the observables are equal to the function that contains unknown x, and the constant
c. Since this function is a non-linear function, this function needs to be linearized by using
Taylor series expansion.
() = ( ) +

( ) (2)
|
=

Taylor series expansion help to obtain a better estimate of , and it is iterated until the best
estimate is obtained. Iteration is stopped whenever the user wants to. From the Taylor series
expansion, since A matrix is the derivative of a function respect to unknown x, which has size of
number of observables by the number of unknowns, notice that

= (3)

Also, from Taylor series expansion, ( ) is defined as the correction, which is the difference
between previous x value and current x value. It is expressed as
= ( ) (4)
Therefore, using the variables defined from the Taylor series expansion, the observable l can be
expressed as:
= ( ) + (5)
Surely, the observable l contains an error. So the error is denoted as v and expressed as:
= ( ) + (6)
Then rearranging the equation (6):

= ( ) (7)
From equation (1), the mathematical model shows that the observable l is expressed as the
function of unknown x and constant c. Therefore, the difference of the observable l and the
function of can be expressed as:
= (8)
Where w is denoted as the misclosure of the observables.
= ( ) (9)
Similarly, in linear parametric adjustment,
= (10)
Finally, since the error v was separated, least square adjustment can be used to minimize the
error.
(11)
Plugging in equation (9) into equation (10) yields:
( ) ( ) min (12)
( )( ) (13)
( )( ) (14)
+ (15)
2 + (16)
2 + 2 = 0 (17)
= ( )1 (18)
Then, using the equation (18), can be obtained as following:
= (19)
= (20)
= ( )1 (21)
= (22)

Where N is the matrix of normal equations that has orthogonal eigenvectors and is always
symmetric positive definite.
As seen from equation (8) and (9), the linear parametric adjustment and non-linear parametric
adjustment has the same format of equation with different variables. Therefore, since
= 1 (23)
= (24)
= 1 (25)
This is possible because with in the misclosure equation, which is equation (9), ( ) is
considered as errorless. Since ( ) is considered as constant,
= (26)
So using the equation (20),
= = 1 (27)
since
= + (28)
Propagating the error on right hand side and assuming that is errorless, it will conclude that
= (29)
From this lab, adjustment of traverse was dealt. Therefore, non-linear parametric adjustment was
used. Initially, the traverse data was given in a format of AtToBS. Then followed by the
horizontal angles, standard deviations of horizontal angles, horizontal distances, standard
deviation of horizontal distances, and the known control points were provided. In this lab, the
horizontal distances and the horizontal angles were there required observables and the coordinates
of x and y were the unknowns.
From the known control point, the change in coordinate was added to it to get the initial
approximated coordinates. By using the following equation:
= sin (30)
= cos (31)
where HD represents the horizontal distances and the represents the azimuth between coordinate
points. Furthermore, using the x and y coordinates, the initial ( ) was computed. In this lab, the

( ) consisted of horizontal distances and horizontal angles. Horizontal distance and horizontal
angles were obtained using the following equations:
= ( )2 + ( )2 (32)
= (33)
Hence, the A matrix was coded in a way that it would formulate the A matrix automatically when
data was input. As seen from equation (3), the A matrix looks like the following in matrix form:
1
1
=

[1

(34)

The A matrix in this example can be created by the taking the derivative of the horizontal distance
equation, and horizontal angle equation respect to x, and y coordinates.

(35)

(36)
Misclosure w, was calculated by the equation (9) mentioned previously. Since the observable l has
the size of 11x1 in this lab, ( ) has to have a size of 11x1, in order to compute the misclosure
w.
Since the standard deviations for horizontal angle and horizontal distances were given, they were
used to compute the weight matrix P, which has the size of 11x11. The weight matrix P is inversely
proportional to the covariance matrix of observable .

1
2
==
[0

(37)
1

2]

Then, as seen from equation (25), delta can be computed and it will have the size of 8x1, because
to satisfy equation (28), has to be added to the initial approximated coordinates. When has
been added to the initial approximation, it will yields . In order to get a better value of unknown
x, the misclosure w has to be iterated. When was obtained, it was used as the new initial
approximation, which was supposed to have a better value than previous initial approximation.
Then the previous procedures were repeated to get the again. This was repeated until all the
values were close to zero. Therefore, a while loop was set to iterate until the maximum value of
was less than 1x10-10. When the while loop has been completed, best value of was obtained,
which took 4 iterations.
Moreover, the residual that shows how good the observable was completed. The residual will have
the size of 11x1, because it is the adjusted error in the observable.
= (38)
To get covariance matrix of , that has size of 11x11, using law of propagation:
= (39)
From equation (26), and (29) = and = , equation (39) can be written as:
= 1 (40)
Since
= (41)
= (42)
To get covariance matrix of , that has size of 11x11:
= (43)
= ( 1 ) (44)
= 1 (45)

Results:
Initial x, and y coordinate estimate:
x=

717008.521819685
717000.452811664
717249.119494552
717601.671237188

y=

4914652.89214288
4914242.05737499
4913843.19616912
4914003.14334730

Initial ( ) that contains horizontal distance, and horizontal angles in radians.


( ) =

296.9590000019212
410.9140000021992
470.0269999969194
387.1379999990239
284.4998753279954
2.0202927856764
3.4355278452826
3.1078404099260
2.5644767501687
1.7023607002619
4.4686149169575

Note that the horizontal angles were converted into radians for any unit issue.
Initial misclosure. It is the difference between the observable value and the calculated value using
estimate coordinates.
w=

-0.000000001921194
-0.000000002199272
0.000000003080572
0.000000000976058
0.013124672004608
0.000000000000274
0.000141151739854
-0.000000000001418
0.000000000006148
-0.000000000010625
-0.000157031340980

-0.006173749442823
0.004336313049186
-0.019985296334999
0.005097569045052
-0.033685720769871
-0.002100847820629
-0.038221609376174
-0.013772079584397

The is the difference between x and , which will eventually become close to 0 when iterated
by updating the misclosure w. The following x and y coordinates are the initial .
x=

717008.5156459355
717000.4328263676
717249.0858088313
717601.6330155786

y=

4914652.896479193
4914242.062472558
4913843.194068273
4914003.129575220

= =
2.55E-05
1.24E-05
3.37E-05
1.26E-05
3.00E-05
1.31E-05
2.17E-06
1.16E-06

1.24E-05
1.11E-04
1.36E-05
9.84E-05
-1.05E-05
6.65E-05
1.72E-05
1.65E-05

3.37E-05
1.36E-05
8.82E-05
1.38E-05
9.66E-05
2.76E-05
3.37E-06
9.63E-07

1.26E-05
9.84E-05
1.38E-05
1.09E-04
-1.30E-05
7.35E-05
1.91E-05
1.83E-05

3.00E-05
-1.05E-05
9.66E-05
-1.30E-05
1.64E-04
2.38E-05
3.93E-08
-2.15E-06

1.31E-05
6.65E-05
2.76E-05
7.35E-05
2.38E-05
7.54E-05
1.83E-05
1.79E-05

2.17E-06
1.72E-05
3.37E-06
1.91E-05
3.93E-08
1.83E-05
1.89E-05
1.16E-05

is the covariance matrix of that shows the variance and covariance of the .
The residual is the adjusted error from the observable.
=

0.004000670852273
0.000489893369410
0.001139660732123
0.008952663900018
0.000196474095926
-0.000021539535999
0.000005772999949
-0.000012102133087
0.000000804458957
0.000010223748486
0.000000960854946

1.16E-06
1.65E-05
9.63E-07
1.83E-05
-2.15E-06
1.79E-05
1.16E-05
1.29E-05

2.96955E+02
4.10914E+02
4.70026E+02
3.87129E+02
2.84513E+02
2.02031E+00
3.43566E+00
3.10785E+00
2.56448E+00
1.70235E+00
4.46846E+00

The is the adjusted observable that the error on the observable has been removed.
=

The covariance matrix of adjusted observable shows the variance and covariance of the adjusted
observable.

After the iteration, where the has been reduced until the maximum element was less than
1010, new results were output.
=

-4.08E-11
-3.72E-10
1.34E-10
2.51E-10
2.76E-10
2.91E-10
2.83E-10
6.08E-11

As mentioned before, the adjusted x and y coordinates are the in this lab.
x=

717008.5156
717000.4328
717249.0858
717601.633

y=

4914652.896
4914242.062
4913843.194
4914003.13

Even after iteration, the covariance matrix , , and remains the same because A matrix
wasnt updated with the misclosure w. The coefficient matrix of unknowns, A matrix can be
updated as well, but since the change is so minimal, it doesnt necessarily have to be updated.

0.003998609225343
0.000489659529669
0.001139389794849
0.008952454943194
0.000196431241334
-0.000021538742482
0.000005774334503
-0.000012102353177
0.000000802911756
0.000010222338640
0.000000961904013

296.9550
410.9135
470.0259
387.1290
284.5128
115.7555
196.8490
178.0668
146.9336
97.5375
256.0237

Since these adjusted observables are the final answer, the angles were converted back to degrees
from radian.

Discussion:
From the initial approximation, the coordinates changed few meters after the adjustment. However,
not all the coordinates changed uniformly, because these coordinates were adjusted according to
the weight of each observables and the errors within the observables. The unknown x becomes
after the adjustment, which is the initial unknown plus . Then, the adjusted unknown x will
become the initial unknown that will be added to the next iterated . Non-linear parametric
adjustment is iterated until all values of is reasonably close to being 0, which means if the initial
approximation of unknowns are bad, it may have to iterate several times more than expected.
Moreover, can be either positive or negative value, which will result the final coordinates to
either decrease or increase after the adjustment.
The covariance matrix of the unknowns x, shows the variance and the covariance of unknown x.
In the non-linear parametric adjustment, = . In this lab, the variance of unknowns came out
to be small values, which means the unknowns have high accuracy. Clearly, this is expected,
because after the adjustment, the errors shouldve been minimized and best values were supposed
to be obtained. Hence, after the final adjustment, the misclosure w, which are the horizontal angles
and distances, should output a small value that is close to being 0 and if this is the case, it indicates
that the values are adjusted correctly.
Similarly, the covariance matrix of adjusted observables, and the covariance matrix of residuals,
also has very small variances after the adjustment has been done. Small variances indicate high
accuracy, which should be reasonable after the adjustment has been done. Since approximate
coordinates are used to calculates initial approximation of horizontal distances and angles, as the
coordinates get adjusted, the horizontal distances and angles are adjusted as well.
Conclusion:
Ultimately, from this lab, the initial approximated coordinates were adjusted to correct coordinates.
To find the best value for the , which is the easting and northing coordinates in this lab, the
misclosure w, has to be updated to iterate the adjustment. The iterative condition is the values of
being reasonably close to 0. However, the coefficient matrix, A, doesnt have to be updated,
because changes are so minimal and it can be neglected. After the iteration has been completed,
the covariance matrix of adjusted observables, adjusted unknowns, and adjusted residuals has to
have small variances, which represents high accuracy of the adjusted observables, adjusted
unknowns, and adjusted residuals, because they will be adjusted along the way and end up with
minimized errors.
Finally, the adjusted coordinates are the following:
x=

717008.5156
717000.4328
717249.0858
717601.633

y=

4914652.896
4914242.062
4913843.194
4914003.13

Reference:
Ghilani, Charles D. "16." Adjustment Computations: Spatial Data Analysis. 5.th ed. Hoboken:
Wiley, 2010. Print.
Lasagna, Patrick. "ESSE 3620 Lab." Web. 1 Nov. 2015.

Appendix:
A=

P=

Matlab code:
Main Script
clc;
format long;
% Importing data file
dat = importdata('lab6.txt');
coor = importdata('initial_coor.txt');
% dat = importdata('lab6_test.txt');
% coor = importdata('lab6_test_coor.txt');
order = dat(:,1:3);
hor_ang = dat(:,4:6);
ang_std = ((dat(:,7)/206265).^2).^-1;
hor_dist = dat(:,8);
dist_std = (dat(:,9).^2).^-1;
% remove row with NaN
hor_dist = hor_dist(~any(isnan(hor_dist),2),:);
dist_std = dist_std(~any(isnan(dist_std),2),:);
for h = 1:size(order,1)
hor_angle(h) = deg2rad(dms2deg(hor_ang(h,1:3)));
end
l = [hor_dist;hor_angle'];

% a0 = atand((coor(1,2) - coor(2,2))/(coor(1,3) - coor (2,3)));


% [ Alpha ] = AzimuthCalc(a0, hor_angle);
% check reference coordinate!
% [ x, y ] = Changed_Coordinate( unk, coor, hor_dist, Alpha );
x = importdata('x_coor.txt');
y = importdata('y_coor.txt');
% x = importdata('lab6_test_x_coor.txt');
% y = importdata('lab6_test_y_coor.txt');
unk = size(x,1)*2;
[ HD, theta, fxo ] = observable( x, y, order, coor, dat );
[ temp1 ] = A_tem1( order, x, y, coor, hor_dist, unk, dat);
[ temp2 ] = A_tem2( order, x, y, coor, unk, hor_angle );
A = [temp1;temp2];

w = l - fxo;
P = diag([dist_std;ang_std]);
delta = (inv(transpose(A)*P*A))*transpose(A)*P*w;
k = 1;
for j = 1:unk/2
xhat(k) = x(j) + delta(k);
xhat(k+1) = y(j) + delta(k+1);
x(j) = xhat(k);
y(j) = xhat(k+1);
k= k+2;
end

k = 1;
v = 1;
while abs(max(delta)) > 10e-9
[ HD, theta, fxo ] = observable( x, y, order, coor, dat );

w = l - fxo;
delta = ((transpose(A)*P*A)^-1)*transpose(A)*P*w;

k = 1;
for j = 1:unk/2
xhat(k) = x(j) + delta(k);
xhat(k+1) = y(j) + delta(k+1);
x(j) = xhat(k);
y(j) = xhat(k+1);
k= k+2;
end
v = v+1;
end
Cdeltahat = (transpose(A)*P*A)^-1;
rhat = w - A*delta;
Crhat = (P^-1)-(A*Cdeltahat*transpose(A));
lhat = l - rhat;
Clhat = A*((transpose(A)*P*A)^-1)*transpose(A);

A Matrix part
function [ temp1 ] = A_tem1( order, x, y, coor, hor_dist, unk, dat)
% First Horizontal distance part of A matrix
temp1 = zeros([size(hor_dist,1), unk]);
for m = 1:size(order,1)
if isnan(dat(m,8)) == 0
if (order(m,1) > 1000 && order(m,2) > 1000)
elseif (order(m,1) > 1000)
df_dx(m) = -(coor(coor(:,1)== order(m,1),2) - x(order(m,2)))/...
(sqrt(((coor(coor(:,1)== order(m,1),2)-x(order(m,2))).^2) ...
+ (coor(coor(:,1)== order(m,1),3)-y(order(m,2)))^2));
df_dy(m) = -(coor(coor(:,1)== order(m,1),3) - y(order(m,2)))/...
(sqrt(((coor(coor(:,1)== order(m,1),2)-x(order(m,2))).^2) ...
+ (coor(coor(:,1)== order(m,1),3)-y(order(m,2)))^2));
temp1(m,2*(order(m,2))-1) = df_dx(m);
temp1(m,2*(order(m,2))) = df_dy(m);
elseif (order(m,2) > 1000)
df_dx(m) = (x(order(m,1))-coor(coor(:,1)== order(m,2),2))/...
sqrt(((coor(coor(:,1)== order(m,2),2)-x(order(m,1))).^2) ...
+ (coor(coor(:,1)== order(m,2),3)-y(order(m,1)))^2);
df_dy(m) = (y(order(m,1))-coor(coor(:,1)== order(m,2),3))/...
sqrt(((coor(coor(:,1)== order(m,2),2)-x(order(m,1))).^2) ...
+ (coor(coor(:,1)== order(m,2),3)-y(order(m,1)))^2);
temp1(m,2*(order(m,1))-1) = df_dx(m);
temp1(m,2*(order(m,1))) = df_dy(m);
else
df_dx(m) = (x(order(m,1)) - x(order(m,2)))/...
sqrt(((x(order(m,1))-x(order(m,2))).^2) ...
+ (y(order(m,1))-y(order(m,2)))^2);
df_dy(m) = (y(order(m,1)) - y(order(m,2)))/...
sqrt(((x(order(m,1))-x(order(m,2))).^2) ...
+ (y(order(m,1))-y(order(m,2)))^2);
temp1(m,2*(order(m,1))-1) = df_dx(m);
temp1(m,2*(order(m,1))) = df_dy(m);
df_dx(m) = -(x(order(m,1)) - x(order(m,2)))/...
sqrt(((x(order(m,1))-x(order(m,2))).^2) ...
+ (y(order(m,1))-y(order(m,2)))^2);
df_dy(m) = -(y(order(m,1)) - y(order(m,2)))/...
sqrt(((x(order(m,1))-x(order(m,2))).^2) ...
+ (y(order(m,1))-y(order(m,2)))^2);

temp1(m,2*(order(m,2))-1) = df_dx(m);
temp1(m,2*(order(m,2))) = df_dy(m);
end
else
% do nothing
end
end
%remove rows with all zeros
temp1( all(~temp1,2), : ) = [];
end

function [ temp2 ] = A_tem2( order, x, y, coor, unk, hor_angle )


% Second Horizontal angle part of the A matrix
temp2 = zeros([size(hor_angle,1), unk]);
for m = 1:size(order,1)
if (order(m,1) > 1000 && order(m,2) > 1000 && order(m,3) > 1000)
elseif (order(m,1) > 1000 && order(m,2) > 1000)
df_dx(m) = ((coor(coor(:,1)== order(m,1),3))-y(order(m,3)))/...
(((coor(coor(:,1)== order(m,1),2)-x(order(m,3))).^2) ...
+ (coor(coor(:,1)== order(m,1),3)-y(order(m,3)))^2);
df_dy(m) = ((x(order(m,3))-coor(coor(:,1)== order(m,1),2)))/...
(((coor(coor(:,1)== order(m,1),2)-x(order(m,3))).^2) ...
+ (coor(coor(:,1)== order(m,1),3)-y(order(m,3)))^2);
temp2(m,2*(order(m,3))-1) = df_dx(m);
temp2(m,2*(order(m,3))) = df_dy(m);
elseif (order(m,1) > 1000 && order(m,3) > 1000)
df_dx(m) = ((y(order(m,2)))-coor(coor(:,1)== order(m,1),3))/...
(((coor(coor(:,1)== order(m,1),2)-x(order(m,2))).^2) ...
+ (coor(coor(:,1)== order(m,1),3)-y(order(m,2)))^2);
df_dy(m) = ((coor(coor(:,1)== order(m,1),2))-x(order(m,2)))/...
(((coor(coor(:,1)== order(m,1),2)-x(order(m,2))).^2) ...
+ (coor(coor(:,1)== order(m,1),3)-y(order(m,2)))^2);
temp2(m,2*(order(m,2))-1) = df_dx(m);
temp2(m,2*(order(m,2))) = df_dy(m);
elseif (order(m,2) > 1000)
df_dx(m) = (y(order(m,1))-y(order(m,3)))/...
(((x(order(m,1))-x(order(m,3)))^2) ...
+ (y(order(m,1))-y(order(m,3)))^2);

df_dy(m) = (x(order(m,3))-x(order(m,1)))/...
(((x(order(m,1))-x(order(m,3)))^2) ...
+ (y(order(m,1))-y(order(m,3)))^2);
temp2(m,2*(order(m,3))-1) = df_dx(m);
temp2(m,2*(order(m,3))) = df_dy(m);
df_dx(m) = ((y(order(m,3))-y(order(m,1)))/...
(((x(order(m,1))-x(order(m,3)))^2) ...
+ (y(order(m,1))-y(order(m,3)))^2))-...
((coor(coor(:,1)== order(m,2),3)-y(order(m,1)))/...
(((x(order(m,1))-coor(coor(:,1)== order(m,2),2))^2) ...
+ (y(order(m,1))-coor(coor(:,1)== order(m,2),3))^2));
df_dy(m) = ((x(order(m,1))-x(order(m,3)))/...
(((x(order(m,1))-x(order(m,3)))^2) ...
+ (y(order(m,1))-y(order(m,3)))^2))-...
((x(order(m,1))-coor(coor(:,1)== order(m,2),2))/...
(((x(order(m,1))-coor(coor(:,1)== order(m,2),2))^2) ...
+ (y(order(m,1))-coor(coor(:,1)== order(m,2),3))^2));
temp2(m,2*(order(m,1))-1) = df_dx(m);
temp2(m,2*(order(m,1))) = df_dy(m);
elseif (order(m,3) > 1000)
df_dx(m) = ((coor(coor(:,1)== order(m,3),3)-y(order(m,1)))/...
(((x(order(m,1))-coor(coor(:,1)== order(m,3),2))^2) ...
+ (y(order(m,1))-coor(coor(:,1)== order(m,3),3))^2))...
-((y(order(m,2))-y(order(m,1)))/...
(((x(order(m,1))-x(order(m,2)))^2) ...
+ (y(order(m,1))-y(order(m,2)))^2));
df_dy(m) = ((x(order(m,1))-coor(coor(:,1)== order(m,3),2))/...
(((x(order(m,1))-coor(coor(:,1)== order(m,3),2))^2) ...
+ (y(order(m,1))-coor(coor(:,1)== order(m,3),3))^2))...
-((x(order(m,1))-x(order(m,2)))/...
(((x(order(m,1))-x(order(m,2)))^2) ...
+ (y(order(m,1))-y(order(m,2)))^2));
temp2(m,2*(order(m,1))-1) = df_dx(m);
temp2(m,2*(order(m,1))) = df_dy(m);
df_dx(m) = (y(order(m,2))-y(order(m,1)))/...
(((x(order(m,1))-x(order(m,2)))^2) ...
+ (y(order(m,1))-y(order(m,2)))^2);
df_dy(m) = (x(order(m,1))-x(order(m,2)))/...
(((x(order(m,1))-x(order(m,2)))^2) ...
+ (y(order(m,1))-y(order(m,2)))^2);
temp2(m,2*(order(m,2))-1) = df_dx(m);
temp2(m,2*(order(m,2))) = df_dy(m);

else
df_dx(m) = (y(order(m,1))-y(order(m,3)))/...
(((x(order(m,1))-x(order(m,3)))^2) ...
+ (y(order(m,1))-y(order(m,3)))^2);
df_dy(m) = (x(order(m,3))-x(order(m,1)))/...
(((x(order(m,1))-x(order(m,3)))^2) ...
+ (y(order(m,1))-y(order(m,3)))^2);
temp2(m,2*(order(m,3))-1) = df_dx(m);
temp2(m,2*(order(m,3))) = df_dy(m);
df_dx(m) = ((y(order(m,3))-y(order(m,1)))/...
(((x(order(m,1))-x(order(m,3)))^2) ...
+ (y(order(m,1))-y(order(m,3)))^2))...
-((y(order(m,2))-y(order(m,1)))/...
(((x(order(m,1))-x(order(m,2)))^2) ...
+ (y(order(m,1))-y(order(m,2)))^2));
df_dy(m) = ((x(order(m,1))-x(order(m,3)))/...
(((x(order(m,1))-x(order(m,3)))^2) ...
+ (y(order(m,1))-y(order(m,3)))^2))...
-((x(order(m,1))-x(order(m,2)))/...
(((x(order(m,1))-x(order(m,2)))^2) ...
+ (y(order(m,1))-y(order(m,2)))^2));
temp2(m,2*(order(m,1))-1) = df_dx(m);
temp2(m,2*(order(m,1))) = df_dy(m);
df_dx(m) = (y(order(m,2))-y(order(m,1)))/...
(((x(order(m,1))-x(order(m,2)))^2) ...
+ (y(order(m,1))-y(order(m,2)))^2);
df_dy(m) = (x(order(m,1))-x(order(m,2)))/...
(((x(order(m,1))-x(order(m,2)))^2) ...
+ (y(order(m,1))-y(order(m,2)))^2);
temp2(m,2*(order(m,2))-1) = df_dx(m);
temp2(m,2*(order(m,2))) = df_dy(m);
end
end
end

f(xo) Part
function [ HD, theta, fxo ] = observable( x, y, order, coor, dat )
% Calculating Horizontal distance and
%Horizontal Angle with Initial coordinates

for m = 1:size(order,1)
if (order(m,1) > 1000 && order(m,2) > 1000)
elseif (order(m,1) > 1000)
HD(m) = sqrt((x(order(order(:,1)== order(m,1),2)) - coor(coor(:,1)== order(m,1),2)).^2 +
((y(order(order(:,1)== order(m,1),2)) - coor(coor(:,1)== order(m,1),3)).^2));
elseif (order(m,2) > 1000)
HD(m) = sqrt((x(order(order(:,2)== order(m,2),1)) - coor(coor(:,1)== order(m,2),2)).^2 +
((y(order(order(:,2)== order(m,2),1)) - coor(coor(:,1)== order(m,2),3)).^2));
else
HD(m) = sqrt(((x(order(m,1))- x(order(m,2))).^2) + ((y(order(m,1))- y(order(m,2))).^2));
end
if (isnan(dat(m,8)) == 0)
if (order(m,1) > 1000 && order(m,2) > 1000)
elseif (order(m,1) > 1000)
fHD(m) = sqrt((x(order(order(:,1)== order(m,1),2)) - coor(coor(:,1)== order(m,1),2)).^2 +
((y(order(order(:,1)== order(m,1),2)) - coor(coor(:,1)== order(m,1),3)).^2));
elseif (order(m,2) > 1000)
fHD(m) = sqrt((x(order(order(:,2)== order(m,2),1)) - coor(coor(:,1)== order(m,2),2)).^2 +
((y(order(order(:,2)== order(m,2),1)) - coor(coor(:,1)== order(m,2),3)).^2));
else
fHD(m) = sqrt(((x(order(m,1))- x(order(m,2))).^2) + ((y(order(m,1))- y(order(m,2))).^2));
end
end
end
% erase column with 0
HD( :, ~any(HD,1) ) = [];
fHD( :, ~any(fHD,1) ) = [];

for n = 1:size(order,1)
if (order(n,1) > 1000 && order(n,3) > 1000)
theta(n) = atan2d((coor(coor(:,1)== order(n,1),2)-x(order(n,2))),...
(coor(coor(:,1)== order(n,1),3)-y(order(n,2)))) - ...
atan2d((coor(coor(:,1)== order(n,1),2)-coor(coor(:,1)== order(n,3),2)),...
(coor(coor(:,1)== order(n,1),3)-coor(coor(:,1)== order(n,3),3)));
elseif (order(n,1) > 1000 && order(n,2) > 1000)
theta(n) = atan2d((coor(coor(:,1)== order(n,1),2)-coor(coor(:,1)== order(n,2),2)),...
(coor(coor(:,1)== order(n,1),3)-coor(coor(:,1)== order(n,2),3))) - ...
atan2d((coor(coor(:,1)== order(n,1),2)-x(order(n,3))),...
(coor(coor(:,1)== order(n,1),3)-y(order(n,3))));
elseif (order(n,3) > 1000)
theta(n) = atan2d((x(order(n,1))-x(order(n,2))),...

(y(order(n,1))-y(order(n,2)))) - ...
atan2d((x(order(n,1))-coor(coor(:,1)== order(n,3),2)),...
(y(order(n,1))-coor(coor(:,1)== order(n,3),3)));
elseif (order(n,2) > 1000)
theta(n) = atan2d((x(order(n,1))-coor(coor(:,1)== order(n,2),2)),...
(y(order(n,1))-coor(coor(:,1)== order(n,2),3))) - ...
atan2d((x(order(n,1))-x(order(n,3))),...
(y(order(n,1))-y(order(n,3))));
else
theta(n) = atan2d((x(order(n,1))-x(order(n,2))),...
(y(order(n,1))-y(order(n,2)))) - ...
atan2d((x(order(n,1))-x(order(n,3))),...
(y(order(n,1))-y(order(n,3))));
end
if (theta(n) < 0)
theta(n) = theta(n) + 360;
end
end
fxo = [fHD';deg2rad(theta)'];
end

Initial coordinate calculation


function [ x, y ] = Changed_Coordinate( unk, coor, hor_dist, Alpha )
% Change in coordinate
ref_coor_E = coor(2,2);
ref_coor_N = coor(2,3);
for j = 1:unk/2;
% Change in Easting coordinate
dE(j) = hor_dist(j,1)*sind(Alpha(j));
% Change in Northing coordinate
dN(j) = hor_dist(j,1)*cosd(Alpha(j));
% Add the change in coordinate to initial coordinate
x(j) = dE(j) + ref_coor_E;
y(j) = dN(j) + ref_coor_N;
ref_coor_E = x(j);
ref_coor_N = y(j);
end
x = x';
y = y';
end

Azimuth calculation
function [ Alpha ] = Azimuth( coor,order,x,y )
% Azimuth Calculation
for m = 1:size(order,1);
if (order(m,1) > 1000 && order(m,2) > 1000)
Alpha(m) = atand((coor(coor(:,1)== order(m,1),2) - coor(coor(:,1)== order(m,2),2))/(coor(coor(:,1)==
order(m,1),3) - coor(coor(:,1)== order(m,2),3)));
elseif (order(m,1) < 1000 && order(m,2) < 1000)
Alpha(m) = atand((x(order(m,1))-x(order(m,2)))/(y(order(m,1))-y(order(m,2))));
elseif (order(m,1) > 1000)
Alpha(m) = atand((coor(coor(:,1)== order(m,1),2) - x(order(order(:,1)==
order(m,1),2)))/(coor(coor(:,1)== order(m,1),3) - y(order(order(:,1)== order(m,1),2))));
elseif (order(m,2) > 1000)
Alpha(m) = atand((x(order(order(:,2)== order(m,2),1))-(coor(coor(:,1)==
order(m,2),2)))/(y(order(order(:,2)== order(m,2),1))-(coor(coor(:,1)== order(m,2),3))));
end

if (Alpha(m) > 360)

Alpha(m) = Alpha(m) - 360;


elseif (Alpha(m) > 180 )
Alpha(m) = Alpha(m) - 180;
elseif (Alpha(m) < 180 )
Alpha(m) = Alpha(m) + 180;
end
end

You might also like