Lab moderna: add P1
Change-Id: Ibbbfa656bfcd29eef2afb9dbd78488e4484054b6
diff --git a/quad12/labmoderna/p1a/r/.gitignore b/quad12/labmoderna/p1a/r/.gitignore
new file mode 100644
index 0000000..01564af
--- /dev/null
+++ b/quad12/labmoderna/p1a/r/.gitignore
@@ -0,0 +1 @@
+*.tex
diff --git a/quad12/labmoderna/p1a/r/main.r b/quad12/labmoderna/p1a/r/main.r
new file mode 100644
index 0000000..151853a
--- /dev/null
+++ b/quad12/labmoderna/p1a/r/main.r
@@ -0,0 +1,14 @@
+library(tikzDevice)
+
+table <- read.table('../dades/fons_a.txt', sep="\t", dec=',', header=TRUE)
+m = mean(table$ImpulsesPerSecond)
+m
+unc = sd(table$ImpulsesPerSecond)
+unc
+
+tikz("fons_fluctuacio.tex", width = 5, height = 4)
+plot(table$t, table$ImpulsesPerSecond, pch = 4, xlab = "$t$ (s)", ylim = c(-2.1, 2.1), ylab = "$I$ (\\#/s)")
+abline(h = m + unc, col = "red", lty = 2)
+abline(h = m - unc, col = "red", lty = 2)
+abline(h = m, col = "green", lty = 2)
+dev.off()
diff --git a/quad12/labmoderna/p1a/r/main2.r b/quad12/labmoderna/p1a/r/main2.r
new file mode 100644
index 0000000..76b4fff
--- /dev/null
+++ b/quad12/labmoderna/p1a/r/main2.r
@@ -0,0 +1,25 @@
+library(tikzDevice)
+
+table <- read.table('../dades/bari_a.txt', sep="\t", dec=',', header=TRUE)
+
+fit <- nls(ImpulsesPerSecond ~ ni*exp(-t/tau), start = list(ni = 40, tau = 20), data = table)
+summary(fit)
+
+tikz("bari.tex", width = 5.5, height = 3.5)
+#pdf('pdf.pdf', width = 6, height = 4)
+fit_coef <- coef(fit)
+plot(table$t, table$ImpulsesPerSecond, pch = 4, xlab = "$t$ (s)", ylab = "$I$ (\\# s\\textsuperscript{-1})")
+curve(fit_coef[1]*exp(-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))
+dev.off()
+
+table$logI <- log(table$ImpulsesPerSecond)
+
+tikz("bari_linealitzat.tex", width = 5.5, height = 3.5)
+#pdf('pdf2.pdf', width = 6, height = 4)
+fit_lineal <- lm(logI~t, data = table)
+summary(fit_lineal)
+plot(table$t, table$logI, pch = 4, xlab = "$t$ (s)", 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))
+dev.off()