-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path010_Visualise_Wave_v5_3D_1D.R
181 lines (129 loc) · 3.53 KB
/
010_Visualise_Wave_v5_3D_1D.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#==============
# 23 Nov. 2023
#==============
# Aim:
# to visualize wave_5 function in 1D and 3D to better understand its property
#---------
# Settings
#---------
library(plot3D)
getwd()
img_path <- "./Results/"
#--------
# Domain
#--------
ds <- 0.1
s <- seq(-1 + ds/2, 1 - ds/2, by = ds)
# for 3D requires displacement
H <- t(outer(s, s, "-"))
#------
# Range check
#------
source("Fn_Waves.R")
DELTA <- c(-0.7, -0.3, -0.1, 0.1, 0.3, 0.5, 0.7, 1)
R <- matrix(NA, ncol = 3)
for (delta in DELTA){
w5 <- wave_v5(h = H, delta = delta, A = 1)
r <- range(w5)
dr <- t(c(delta, r))
R <- rbind(R, dr)
}
R
colnames(R) <- c("delta", "min", "max")
R[-1, ]
# delta min max
# [1,] -0.7 -0.4693878 1
#[2,] -0.3 -1.0000000 1
#[3,] -0.1 -1.0000000 1
#[4,] 0.1 -1.0000000 1
#[5,] 0.3 -1.0000000 1
#[6,] 0.5 -1.0000000 1
#[7,] 0.7 -0.4693878 1
#[8,] 1.0 -0.6200000 1
#-----
# 3D
#----
## positive dlt
jpeg(paste0(img_path, "wave_v5_3D_pos_dlt.jpeg"),
width = 8, height = 7, units = "in", res = 300)
par(mfrow = c(3, 2), mar = c(1.5, 1, 3.5, 2.5))
DELTA <- c(0.1, 0.3, 0.5, 0.7, 0.9, 1)
for (delta in DELTA) {
w5 <- wave_v5(h = H, delta = delta, A = 1)
w5_mat <- matrix(w5, nrow = nrow(H))
main_title <- as.expression(paste("Tri_Wave (A = 1) \n delta = ", delta))
persp3D(s, s, w5_mat, theta = 135,
main = main_title)
}
dev.off()
## Neg dlt
jpeg(paste0(img_path, "wave_v5_3D_neg_dlt.jpeg"),
width = 8, height = 7, units = "in", res = 300)
par(mfrow = c(3, 2), mar = c(1.5, 1, 3.5, 2.5))
DELTA <- -1 * c(0.1, 0.3, 0.5, 0.7, 0.9, 1)
for (delta in DELTA) {
w5 <- wave_v5(h = H, delta = delta, A = 1)
w5_mat <- matrix(w5, nrow = nrow(H))
main_title <- as.expression(paste("Tri_Wave (A = 1) \n delta = ", delta))
persp3D(s, s, w5_mat, theta = 135,
main = main_title)
}
dev.off()
#---------
# 1D plots
#---------
length(H) # 400
length(s) # 20
plt_w56 <- function(dlt){
# plot wave_v5 at each grid of s
#w_5 <- wave_v5(h = s, delta = dlt, A = 1)
w_6 <- wave_v6(h = s, delta = dlt, A = 1)
plot(s, w_6, type = "l",
main = bquote(atop("Tri_wave_v6 (A = 1)",
"delta = "~ .(dlt))))
}
jpeg(paste0(img_path, "Wave_v5_1D_pos_dlt.jpeg"),
width = 8, height = 7, units = "in", res = 300)
jpeg(paste0(img_path, "Wave_v6_1D_pos_dlt.jpeg"),
width = 8, height = 7, units = "in", res = 300)
par(mfrow = c(3, 2), mar = c(2.5, 2.5, 3.5, 2.5))
DELTA <- c(0.1, 0.3, 0.5, 0.7, 0.9, 1)
for (dlt in DELTA){
plt_w56(dlt)
}
dev.off()
## neg-delta
jpeg(paste0(img_path, "Wave_v6_1D_neg_dlt.jpeg"),
width = 8, height = 7, units = "in", res = 300)
par(mfrow = c(3, 2), mar = c(2.5, 2.5, 3.5, 2.5))
DELTA <- -1*c(0.1, 0.3, 0.5, 0.7, 0.9, 1)
for (dlt in DELTA){
plt_w56(dlt)
}
dev.off()
#=======================
# Settings 2: large grid
#=======================
ds <- 10
s <- seq(-100 + ds/2, 100 - ds/2, by = ds)
jpeg(paste0(img_path, "Wave_v5_1D_pos_dlt_big_grid.jpeg"),
width = 8, height = 7, units = "in", res = 300)
DELTA <- c(10, 30, 50, 70, 90, 100)
par(mfrow = c(3, 2), mar = c(2.5, 2.5, 3.5, 2.5))
for (dlt in DELTA){
plt_w5(dlt)
}
dev.off()
#------
# large grid but very small dlt, what happens
#------
ds <- 10
s <- seq(-100 + ds/2, 100 - ds/2, by = ds)
#jpeg(paste0(img_path, "Wave_v5_1D_pos_dlt_big_grid.jpeg"),
#width = 8, height = 7, units = "in", res = 300)
DELTA <- c(0.1, 0.5, 1, 3, 5)
par(mfrow = c(3, 2), mar = c(2.5, 2.5, 3.5, 2.5))
for (dlt in DELTA){
plt_w5(dlt)
}
wave_v5(h = s, delta = 0.1, A = 1)