Lab moderna: add P1

Change-Id: Ibbbfa656bfcd29eef2afb9dbd78488e4484054b6
diff --git a/quad12/labmoderna/p1b/r/main.r b/quad12/labmoderna/p1b/r/main.r
new file mode 100644
index 0000000..47cc204
--- /dev/null
+++ b/quad12/labmoderna/p1b/r/main.r
@@ -0,0 +1,39 @@
+library(tikzDevice)
+
+table <- read.table('../dades/dades.txt', sep="\t", header=TRUE)
+
+table$logI <- log(table$impulsosPerSegon)
+
+fit_lineal <- lm(logI~gruixMassic, data = table)
+summary(fit_lineal)
+
+fit_coef <- coef(fit_lineal)
+fit_coef
+
+plotall <- function() {
+  plot(table$gruixMassic, table$logI, pch = 4, xlab = "$t$ (g cm\\textsuperscript{-2})", ylab = "$\\log(I)$")
+  abline(fit_lineal, col = "mediumorchid2")
+  legend("topright", inset = c(0.015, 0.03),col = c("black", "mediumorchid2"), legend = c("Mesures", "Ajust"), pch=c(4, NA), lty=c(NA, 1))
+}
+
+plotallnormal <- function() {
+  plot(table$gruixMassic, table$impulsosPerSegon, pch = 4, xlab = "$t$ (g cm\\textsuperscript{-2})", ylab = "$I$ (\\#s \\textsuperscript{-1})")
+  curve(exp(fit_coef[1] + x*fit_coef[2]), col = "mediumorchid2", add = TRUE)
+  legend("topright", inset = c(0.015, 0.03),col = c("black", "mediumorchid2"), legend = c("Mesures", "Ajust"), pch=c(4, NA), lty=c(NA, 1))
+}
+
+pdf('grafica.pdf', width = 6, height = 5)
+plotall()
+dev.off()
+
+tikz("grafica.tex", width = 5.5, height = 4.5)
+plotall()
+dev.off()
+
+pdf('graficanormal.pdf', width = 6, height = 5)
+plotallnormal()
+dev.off()
+
+tikz("graficanormal.tex", width = 5.5, height = 4.5)
+plotallnormal()
+dev.off()