                      
# Load necessary library
library(uniroot)

# Define a function to represent the equation being solved
polar_moment_equation <- function(di, D) {
  J_solid <- (pi / 32) * D^4
  J_hollow <- (pi / 32) * (D^4 - di^4)
  J_rectangular <- (1 / 12) * di
  
  return(J_solid - (J_hollow + J_rectangular))  # This should equal 0
}

# Define parameters
D_min <- 1 # Minimum possible value for diameter (length of the plate)
D_max <- 2 # Maximum possible value for diameter
D_avg <- (D_min + D_max) / 2  # Choose an average value for D

# Use uniroot to find a root of the equation within a reasonable range for di
di_solution <- uniroot(polar_moment_equation, c(0, D_avg), D = D_avg)

# Output the inner diameter di
cat("The inner diameter di of the hollow circular shaft is:", di_solution$root, "\n")
                  