Adrià Vilanova MartÃnez | 52e9843 | 2023-03-20 20:00:28 +0100 | [diff] [blame] | 1 | library(tikzDevice) |
| 2 | |
| 3 | table <- read.table('../dades/dades.txt', sep="\t", header=TRUE) |
| 4 | |
| 5 | table$logI <- log(table$impulsosPerSegon) |
| 6 | |
| 7 | fit_lineal <- lm(logI~gruixMassic, data = table) |
| 8 | summary(fit_lineal) |
| 9 | |
| 10 | fit_coef <- coef(fit_lineal) |
| 11 | fit_coef |
| 12 | |
| 13 | plotall <- function() { |
| 14 | plot(table$gruixMassic, table$logI, pch = 4, xlab = "$t$ (g cm\\textsuperscript{-2})", ylab = "$\\log(I)$") |
| 15 | abline(fit_lineal, col = "mediumorchid2") |
| 16 | legend("topright", inset = c(0.015, 0.03),col = c("black", "mediumorchid2"), legend = c("Mesures", "Ajust"), pch=c(4, NA), lty=c(NA, 1)) |
| 17 | } |
| 18 | |
| 19 | plotallnormal <- function() { |
| 20 | plot(table$gruixMassic, table$impulsosPerSegon, pch = 4, xlab = "$t$ (g cm\\textsuperscript{-2})", ylab = "$I$ (\\#s \\textsuperscript{-1})") |
| 21 | curve(exp(fit_coef[1] + x*fit_coef[2]), col = "mediumorchid2", add = TRUE) |
| 22 | legend("topright", inset = c(0.015, 0.03),col = c("black", "mediumorchid2"), legend = c("Mesures", "Ajust"), pch=c(4, NA), lty=c(NA, 1)) |
| 23 | } |
| 24 | |
| 25 | pdf('grafica.pdf', width = 6, height = 5) |
| 26 | plotall() |
| 27 | dev.off() |
| 28 | |
| 29 | tikz("grafica.tex", width = 5.5, height = 4.5) |
| 30 | plotall() |
| 31 | dev.off() |
| 32 | |
| 33 | pdf('graficanormal.pdf', width = 6, height = 5) |
| 34 | plotallnormal() |
| 35 | dev.off() |
| 36 | |
| 37 | tikz("graficanormal.tex", width = 5.5, height = 4.5) |
| 38 | plotallnormal() |
| 39 | dev.off() |