# 加載 ggplot2 庫
library(ggplot2)
# 固定參數(shù)賦值
# 定義表達(dá)式 y 的函數(shù)
y_function <- function(t,n) {
? Ka <- 0.1
? F <- 0.8
? Dose <- 3
? ktr <- 0.5
? Input_Rate<- Ka*F*Dose*((ktr * t)^n / factorial(n)) * exp(-ktr*t)
}
# 定義時(shí)間范圍
t <- seq(0, 24, by = 0.5)? # 時(shí)間范圍從 0 到 5,步長為 0.01
# 定義 n 的取值范圍
n_values <- c(0, 1, 2, 3, 4, 5,6,7,8)? # n 的取值
# 創(chuàng)建數(shù)據(jù)框以便 ggplot 使用
data <- data.frame()
for (n in n_values) {
? y <- sapply(t, y_function, n = n)? # 計(jì)算不同 t 下的 y 值
? temp_data <- data.frame(t = t, y = y, n = factor(n))? # 將 n 轉(zhuǎn)換為因子類型
? data <- rbind(data, temp_data)? # 合并數(shù)據(jù)
}
# 使用 ggplot 繪制圖像
ggplot(data, aes(x = t, y = y, color = n)) +
? geom_line(size = 1) +? # 繪制曲線
? labs(title = "y vs t for different n", x = "time", y = "Input Rate", color = "n") +? # 添加標(biāo)題和標(biāo)簽
? theme_minimal() +? # 使用簡潔主題
? scale_color_brewer(palette = "Set1")? # 設(shè)置顏色樣式