length = c(108, 89,58,44,25) period = c(2.080, 1.888, 1.534, 1.3352, 1.0199) pendulum=data.frame(length, period) # #plotting the period versus length data plot(pendulum$length, pendulum$period, main="Pendulum Data", xlab="length (cm)", ylab="period (s)") # # one can obtain use the linear model lm to #obtain a power-law fit by taking the log of both # x and y variables pend_fit = lm(log(pendulum$period) ~ log(pendulum$length)) summary(pend_fit) # #isolating the power fit_power=pend_fit$coefficients["log(pendulum$length)"] fit_power # #isolating the coefficient coeff = exp(pend_fit$coefficients["(Intercept)"]) coeff # #displaying the equation fit_power= round(fit_power,5) coeff=round(coeff,5) fit_eq=paste("y=",coeff,"x^",fit_power) text(40,1.9,fit_eq) # #displaying the curve curve(coeff*x^fit_power,30,110, add=TRUE, col="blue")