forked from dgrechka/SolarWindVelocity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
2ndOrderPolyApproxTest.R
36 lines (26 loc) · 1.17 KB
/
2ndOrderPolyApproxTest.R
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
#This test script does approximation of sample data
# It loads sample data
# approximates it
# draws observations and approximation
obs <- read.csv('SampleData/observations.csv', header = T, sep = ';')
pred <- read.csv('SampleData/prediction.csv', header = T, sep = ';')
colnames(obs) <- c('t','v')
colnames(pred) <- c('t','v')
mv <- 300
filtered_pred <- pred[pred$v != mv,]
joined <- rbind(obs,filtered_pred)
nodes <- joined$t
nodes <- nodes[c(c(T),logical(9))] #take every 10th reference point as node point
if(nodes[length(nodes)]!=joined$t[length(joined$t)])
nodes <- c(nodes,joined$t[length(joined$t)]) #the last ref point must always present
source("2OrderPolynomialApprox.R")
plot(obs$t,obs$v,
xlab = "Time (hours since 03.02.2016 18:00:00)",
ylab = "Velocity (km/s)",
main = "Solar Wind near Earth\n2nd order piecewise polynomial approximation of observation data",
xlim=c(0,760),
ylim=c(250,850),
sub="Black points - observations; Blue points - predictions; Red curve - trend")
res1_poly <- getApproxF(nodes, joined$t, joined$v)
points(filtered_pred$t,filtered_pred$v,col="blue")
curve(res1_poly,add = T, from = 0, to = 760,col = "red",n=2000,lwd=2)