# TA2 - Graphic, Numeric, Analytic # ----------------------------------------------------- library(ggplot2) # Q7 # --------- Dt = numericSolution = data.frame(t = seq(0,1,Dt), x = numeric(length = length(seq(0,1,Dt))), dxdt = numeric(length = length(seq(0,1,Dt))), dxdtDt = numeric(length = length(seq(0,1,Dt)))) numericSolution$x[1] = 1 for(row in 1:length(seq(0,1,Dt))){ if(row > 1) { numericSolution$x[row] = numericSolution$x[row-1]+numericSolution$dxdtDt[row-1] } numericSolution$dxdt[row] = (3/numericSolution$x[row])+1 numericSolution$dxdtDt[row] = numericSolution$dxdt[row]*Dt } ggplot(numericSolution, aes(x = t, y = x)) + geom_point() + geom_line() + labs(title = paste0("X as a function of t - Dt = ",Dt)) + theme_light() ggplot(numericSolution, aes(x = t, y = dxdt)) + geom_point() + geom_line() + labs(title = paste0("dx/dt as a function of t - Dt = ",Dt)) + theme_light() ggplot(numericSolution, aes(x = x, y = dxdt)) + geom_point() + geom_line() + labs(title = paste0("dx/dt as a function of x - Dt = ",Dt)) + theme_light()