Lab moderna: add p9

Change-Id: I2bbcf8606379a44825edd03b0020179b4205af6a
diff --git a/quad12/labmoderna/p9/r/kbr.r b/quad12/labmoderna/p9/r/kbr.r
new file mode 100644
index 0000000..3c8f06e
--- /dev/null
+++ b/quad12/labmoderna/p9/r/kbr.r
@@ -0,0 +1,42 @@
+library(svglite)
+library(tikzDevice)
+
+filename = 'ni0.01_kbr'
+scale <- 75
+
+args = commandArgs(trailingOnly=TRUE)
+
+table <- read.table(paste0('dades/', filename, '.txt'), sep="\t", dec=',', header=FALSE, col.names=c('Theta', 'I'))
+
+# Plot the data
+plotall <- function() {
+  par(mar=c(4,4,0.5,0.5))
+  plot(table$Theta, table$I, type="l", xlab="$\\theta$ (º)", ylab="$I$ (\\#/s)", ylim=c(0, 3500))
+
+  # Add arrows and text labels to the peaks
+  i <- 87
+  arrows(table$Theta[i], table$I[i] + scale*(3 + 2), table$Theta[i], table$I[i] + scale*0.2, length = 0.05, code = 1, col = "#F03A47")
+  text(table$Theta[i], table$I[i] + scale*(5.2 + 2), '$n = 1$', col = "#F03A47", cex = 0.75)
+
+  i <- 231
+  arrows(table$Theta[i], table$I[i] + scale*(3 + 2), table$Theta[i], table$I[i] + scale*0.2, length = 0.05, code = 1, col = "#F03A47")
+  text(table$Theta[i], table$I[i] + scale*(5.2 + 2), '$n = 2$', col = "#F03A47", cex = 0.75)
+
+  i <- 396
+  arrows(table$Theta[i], table$I[i] + scale*(3 + 2), table$Theta[i], table$I[i] + scale*0.2, length = 0.05, code = 1, col = "#F03A47")
+  text(table$Theta[i], table$I[i] + scale*(5.2 + 2), '$n = 3$', col = "#F03A47", cex = 0.75)
+
+  i <- 639
+  arrows(table$Theta[i], table$I[i] + scale*(3 + 2), table$Theta[i], table$I[i] + scale*0.2, length = 0.05, code = 1, col = "#F03A47")
+  text(table$Theta[i], table$I[i] + scale*(5.2 + 2), '$n = 4$', col = "#F03A47", cex = 0.75)
+}
+
+svg(paste0('output/', filename, '.svg'), width = 4*0.82, height = 3*0.82)
+plotall()
+dev.off()
+
+if (length(args) < 1 || args[1] != "preview") {
+  tikz(paste0('output/', filename, '.tex'), width = 4*0.82, height = 3*0.82)
+  plotall()
+  dev.off()
+}
diff --git a/quad12/labmoderna/p9/r/lif.r b/quad12/labmoderna/p9/r/lif.r
new file mode 100644
index 0000000..912b96a
--- /dev/null
+++ b/quad12/labmoderna/p9/r/lif.r
@@ -0,0 +1,42 @@
+library(svglite)
+library(tikzDevice)
+
+filename = '0.02_lif'
+scale <- 200
+
+args = commandArgs(trailingOnly=TRUE)
+
+table <- read.table(paste0('dades/', filename, '.txt'), sep="\t", dec=',', header=FALSE, col.names=c('Theta', 'I'))
+
+# Plot the data
+plotall <- function() {
+  par(mar=c(4,4,0.5,0.5))
+  plot(table$Theta, table$I, type="l", xlab="$\\theta$ (º)", ylab="$I$ (\\#/s)", ylim=c(0, 9000))
+
+  # Add arrows and text labels to the peaks
+  i <- 154
+  arrows(table$Theta[i], table$I[i] + scale*(3 + 2), table$Theta[i], table$I[i] + scale*0.2, length = 0.05, code = 1, col = "#F03A47")
+  text(table$Theta[i], table$I[i] + scale*(5.2 + 2), '$\\mathbf{K}_{\\beta}$', col = "#F03A47", cex = 0.75)
+
+  i <- 177
+  arrows(table$Theta[i], table$I[i] + scale*(3 + 2), table$Theta[i], table$I[i] + scale*0.2, length = 0.05, code = 1, col = "#F03A47")
+  text(table$Theta[i], table$I[i] + scale*(5.2 + 2), '$\\mathbf{K}_{\\alpha 2}$', col = "#F03A47", cex = 0.75)
+
+  i <- 390
+  arrows(table$Theta[i], table$I[i] + scale*(3 + 2), table$Theta[i], table$I[i] + scale*0.2, length = 0.05, code = 1, col = "#F03A47")
+  text(table$Theta[i], table$I[i] + scale*(5.2 + 2), '$\\mathbf{K}_{\\beta}$', col = "#F03A47", cex = 0.75)
+
+  i <- 452
+  arrows(table$Theta[i], table$I[i] + scale*(3 + 2), table$Theta[i], table$I[i] + scale*0.2, length = 0.05, code = 1, col = "#F03A47")
+  text(table$Theta[i], table$I[i] + scale*(5.2 + 2), '$\\mathbf{K}_{\\alpha 1}$', col = "#F03A47", cex = 0.75)
+}
+
+svg(paste0('output/', filename, '.svg'), width = 4*0.82, height = 3*0.82)
+plotall()
+dev.off()
+
+if (length(args) < 1 || args[1] != "preview") {
+  tikz(paste0('output/', filename, '.tex'), width = 4*0.82, height = 3*0.82)
+  plotall()
+  dev.off()
+}
diff --git a/quad12/labmoderna/p9/r/lif_filtre.r b/quad12/labmoderna/p9/r/lif_filtre.r
new file mode 100644
index 0000000..0002514
--- /dev/null
+++ b/quad12/labmoderna/p9/r/lif_filtre.r
@@ -0,0 +1,38 @@
+library(svglite)
+library(tikzDevice)
+
+filename = 'ni0.01_lif'
+scale <- 200
+
+args = commandArgs(trailingOnly=TRUE)
+
+table <- read.table(paste0('dades/', filename, '.txt'), sep="\t", dec=',', header=FALSE, col.names=c('Theta', 'I'))
+
+# Plot the data
+plotall <- function() {
+  par(mar=c(4,4,0.5,0.5))
+  plot(table$Theta, table$I, type="l", xlab="$\\theta$ (º)", ylab="$I$ (\\#/s)", ylim=c(0, 9000))
+
+  # Add arrows and text labels to the peaks
+  i <- 154
+  arrows(table$Theta[i], table$I[i] + scale*(3 + 2), table$Theta[i], table$I[i] + scale*0.2, length = 0.05, code = 1, col = "#F03A47")
+  text(table$Theta[i], table$I[i] + scale*(5.2 + 2), '$\\mathbf{K}_{\\beta}$', col = "#F03A47", cex = 0.75)
+
+  i <- 177
+  arrows(table$Theta[i], table$I[i] + scale*(3 + 2), table$Theta[i], table$I[i] + scale*0.2, length = 0.05, code = 1, col = "#F03A47")
+  text(table$Theta[i], table$I[i] + scale*(5.2 + 2), '$\\mathbf{K}_{\\alpha 2}$', col = "#F03A47", cex = 0.75)
+
+  i <- 452
+  arrows(table$Theta[i], table$I[i] + scale*(3 + 2), table$Theta[i], table$I[i] + scale*0.2, length = 0.05, code = 1, col = "#F03A47")
+  text(table$Theta[i], table$I[i] + scale*(5.2 + 2), '$\\mathbf{K}_{\\alpha 1}$', col = "#F03A47", cex = 0.75)
+}
+
+svg(paste0('output/', filename, '.svg'), width = 4*0.82, height = 3*0.82)
+plotall()
+dev.off()
+
+if (length(args) < 1 || args[1] != "preview") {
+  tikz(paste0('output/', filename, '.tex'), width = 4*0.82, height = 3*0.82)
+  plotall()
+  dev.off()
+}
diff --git a/quad12/labmoderna/p9/r/regressio.r b/quad12/labmoderna/p9/r/regressio.r
new file mode 100644
index 0000000..d0db5dd
--- /dev/null
+++ b/quad12/labmoderna/p9/r/regressio.r
@@ -0,0 +1,28 @@
+library(svglite)
+library(tikzDevice)
+
+filename = 'regressio'
+
+args = commandArgs(trailingOnly=TRUE)
+
+table <- read.table(paste0('dades/', filename, '.txt'), sep=" ", dec='.', header=TRUE)
+
+fit <- lm(X ~ Y, data = table)
+summary(fit)
+
+# Plot the data
+plotall <- function() {
+  par(mar=c(4,4,0.5,0.5))
+  plot(table$Y, table$X, pch = 4, xlab = "$\\sin(\\theta)$", ylab = "$\\frac{n \\lambda}{2}$ (pm)")
+  abline(fit, col = "#799B6F")
+}
+
+svg(paste0('output/', filename, '.svg'), width = 4*0.82, height = 3*0.82)
+plotall()
+dev.off()
+
+if (length(args) < 1 || args[1] != "preview") {
+  tikz(paste0('output/', filename, '.tex'), width = 4*0.82, height = 3*0.82)
+  plotall()
+  dev.off()
+}