# 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")
ICAgICAgICAgICAgICAgICAgICAgIAojIExvYWQgbmVjZXNzYXJ5IGxpYnJhcnkKbGlicmFyeSh1bmlyb290KQoKIyBEZWZpbmUgYSBmdW5jdGlvbiB0byByZXByZXNlbnQgdGhlIGVxdWF0aW9uIGJlaW5nIHNvbHZlZApwb2xhcl9tb21lbnRfZXF1YXRpb24gPC0gZnVuY3Rpb24oZGksIEQpIHsKICBKX3NvbGlkIDwtIChwaSAvIDMyKSAqIEReNAogIEpfaG9sbG93IDwtIChwaSAvIDMyKSAqIChEXjQgLSBkaV40KQogIEpfcmVjdGFuZ3VsYXIgPC0gKDEgLyAxMikgKiBkaQogIAogIHJldHVybihKX3NvbGlkIC0gKEpfaG9sbG93ICsgSl9yZWN0YW5ndWxhcikpICAjIFRoaXMgc2hvdWxkIGVxdWFsIDAKfQoKIyBEZWZpbmUgcGFyYW1ldGVycwpEX21pbiA8LSAxICMgTWluaW11bSBwb3NzaWJsZSB2YWx1ZSBmb3IgZGlhbWV0ZXIgKGxlbmd0aCBvZiB0aGUgcGxhdGUpCkRfbWF4IDwtIDIgIyBNYXhpbXVtIHBvc3NpYmxlIHZhbHVlIGZvciBkaWFtZXRlcgpEX2F2ZyA8LSAoRF9taW4gKyBEX21heCkgLyAyICAjIENob29zZSBhbiBhdmVyYWdlIHZhbHVlIGZvciBECgojIFV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