-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.R
More file actions
36 lines (30 loc) · 835 Bytes
/
script.R
File metadata and controls
36 lines (30 loc) · 835 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
library(geosphere)
locations <- data.frame(
latitude = c(
-8.068361111, -8.075916667, -8.076361111, -8.0593334,
-8.066, -8.06458333333333
),
longitude = c(
-34.892722222, -34.894611111, -34.908, -34.9073435,
-34.8894444444444, -34.8945833333333
),
distance = c(124.4, 188.6, 709, 2350, 806.8, 706.2)
)
# Use average as the starting point
fit <- nls(
distance ~ distm(
data.frame(longitude, latitude),
c(fitLongitude, fitLatitude)
),
data = locations,
start = list(
fitLongitude=mean(locations$longitude),
fitLatitude=mean(locations$latitude)
),
control = list(maxiter = 1000, tol = 1e-02)
)
# Result
latitude <- summary(fit)$coefficients[2]
longitude <- summary(fit)$coefficients[1]
paste(latitude, longitude, sep=",")
#