Adrià Vilanova MartÃnez | 52e9843 | 2023-03-20 20:00:28 +0100 | [diff] [blame] | 1 | library(tikzDevice) |
| 2 | |
| 3 | table <- read.table('../dades/bari_a.txt', sep="\t", dec=',', header=TRUE) |
| 4 | |
| 5 | fit <- nls(ImpulsesPerSecond ~ ni*exp(-t/tau), start = list(ni = 40, tau = 20), data = table) |
| 6 | summary(fit) |
| 7 | |
| 8 | tikz("bari.tex", width = 5.5, height = 3.5) |
| 9 | #pdf('pdf.pdf', width = 6, height = 4) |
| 10 | fit_coef <- coef(fit) |
| 11 | plot(table$t, table$ImpulsesPerSecond, pch = 4, xlab = "$t$ (s)", ylab = "$I$ (\\# s\\textsuperscript{-1})") |
| 12 | curve(fit_coef[1]*exp(-x/fit_coef[2]), col = "mediumorchid2", add = TRUE) |
| 13 | legend("topright", inset = c(0.015, 0.03),col = c("black", "mediumorchid2"), legend = c("Mesures", "Ajust"), pch=c(4, NA), lty=c(NA, 1)) |
| 14 | dev.off() |
| 15 | |
| 16 | table$logI <- log(table$ImpulsesPerSecond) |
| 17 | |
| 18 | tikz("bari_linealitzat.tex", width = 5.5, height = 3.5) |
| 19 | #pdf('pdf2.pdf', width = 6, height = 4) |
| 20 | fit_lineal <- lm(logI~t, data = table) |
| 21 | summary(fit_lineal) |
| 22 | plot(table$t, table$logI, pch = 4, xlab = "$t$ (s)", ylab = "$\\log(I)$") |
| 23 | abline(fit_lineal, col = "mediumorchid2") |
| 24 | legend("topright", inset = c(0.015, 0.03),col = c("black", "mediumorchid2"), legend = c("Mesures", "Ajust"), pch=c(4, NA), lty=c(NA, 1)) |
| 25 | dev.off() |