library(deSolve) library(ggplot2) model <- function(t, Tr, parms) { qv <- parms$qv pa <- parms$pa Ca <- parms$Ca V <- parms$V # Text <- c(-5, 0, 2, 4, 6, 8, 10, 8, 6, 4, 2, 0, -2, -4, -3, -2, -1, 0, 1, 2, 3, 4, 6, 8) Text <- parms$Text dTr <- -(qv * pa * Ca * (Tr - Text)) / (V * pa * Ca) dText = return(list(dTr)) } data=read.csv("input.csv") parms = list(qv = 54, pa = 1.204, Ca = 1006, V = 3000,Text=data$temp) solution <- ode(y=20, times = data$time, func = model, parms) solution=data.frame(solution) print(solution) #gg_plot <- ggplot(data = solution, aes(x = time, y = Tr)) + # geom_line() + # labs(x = "Time Steps", y = "Room Temperature (Tr)") + # ggtitle("Room Temperature Over Time") # # Save the ggplot as a PDF file #ggsave(filename = "room_temperature_plot.pdf", plot = gg_plot) # Plot tank volume over time and save as PDF file #pdf("tank_volume_plot.pdf") # Specify PDF file name #ggplot(data = data.frame(time = out[,1], volume = out[,2])) + # geom_line(aes(x = time, y = volume)) + # labs(title = "Tank Volume Over Time", x = "Time (hours)", y = "Volume (litres)") #dev.off() # Close PDF device