r - When a function is equal to a certain value -
i extremely new r, solution relatively simple. have next function calculate stopping distance average car:
distance <- function(mph){(2.0*(mph/60))+(0.062673*(mph^1.9862))}
and i'm plotting stopping distances 1 mph 60 mph:
range = distance(1:60)
but need mark stopping distance equal 120 ft. don't have thought how done in r, i'd write function where, stoppingdistance(x), maximum speed of auto in mph. function should use, , there easy way check if value of distance(x) (as it's written above) equal value?
one way find when function -120 equal 0:
distance <- function(mph, dist=0){(2.0*(mph/60))+(0.062673*(mph^1.9862))-dist} uniroot(distance, c(1, 60), dist=120) ## $root ## [1] 44.63998 ## ## $f.root ## [1] -5.088982e-06 ## ## $iter ## [1] 6 ## ## $estim.prec ## [1] 6.103516e-05
and see if worked:
distance(44.63998) ## [1] 120
r statistics
No comments:
Post a Comment