Tuesday, December 22, 2009

Introducing R

All statisticians know about R and most use it, but I think it could be useful for normal people too. So much so that children should learn math with R.

You can get R online at places like this: http://cran.r-project.org/bin/windows/base/

It's free and surprisingly intuitive, especially if you know someone who can get you started with the basics.

Here is my latest R project. Someone was building a zipline on a hill for people to ride. How steep should they make it so that the rider is not thrown off at high speed at the end of the ride, they asked? The following code took me about half an hour to put together. At the top, you set the length of the zip line and angle of descent. Then you run the program and it gives you how long the ride lasts and how fast you'll be going at the end:

#zip line speed
#enter the angle of descent in degrees:
angle = 10

#enter the distance in feet
distance = 200

#convert angle to radians:
rad = pi*angle/180

#here is the vertical acceleration due to gravity in feet/sec^2:
acc = 32.174

#the acceleration at an x-degree angle is
tangent.acc = acc*sin(rad)
perp.acc = acc*cos(rad)

#account for friction:
friction.coef = 0.03
resistance = friction.coef*perp.acc

#predict acceleration
final.acc = tangent.acc - resistance

#how long does the ride last (in seconds):
t = sqrt(2*distance/final.acc)
print(t)

#predicted final speed
speed.feet.sec = final.acc*t
speed.miles.hour = speed.feet.sec*(1/5280)*3600
print(speed.miles.hour)

With the above settings, the output you get is a 9-second ride ending at about 30 mph. If you make the angle 89 degrees, for a near-vertical free-fall, you end the ride at 77 mph. This analysis ignores wind-resistance, but possibly compensates somewhat with a fairly conservative estimate for the coefficient of friction, which is incorporated.

0 Comments:

Post a Comment

Links to this post:

Create a Link

<< Home