Created
December 28, 2011 23:21
-
-
Save robbrit/1530380 to your computer and use it in GitHub Desktop.
World oil production/consumption
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# oil production per day by country | |
production = read.csv("production.csv", header = T) | |
# proven oil reserves by country | |
reserves = read.csv("reserves.csv", header = T) | |
# oil consumption by country | |
consumption = read.csv("consumption.csv", header = T) | |
# the total amount of oil production per year | |
total_production = sum(production$Production) * 365 | |
# total world proven reserves | |
total_reserves = sum(reserves$Reserves) | |
# total world consumption per year | |
total_consumption = sum(consumption$Consumption) * 365 | |
# derivation of time formula | |
# | |
# Take the simple exponential growth function | |
# q is initial quantity, r is growth rate, t is time | |
# | |
# f(t) = q * exp(r * t) | |
# | |
# Total usage over time is the integral of f(t): | |
# | |
# V(T) = int(f(t), 0, T) | |
# = int(q * exp(r * t), 0, T) | |
# = q / r * (exp(r * T) - 1) | |
# | |
# See when this hits some limit L | |
# | |
# L = V(T) | |
# = q / r * (exp(r * T) - 1) | |
# | |
# Solve for T | |
# | |
# T = ln(L * r / q + 1) / r | |
# initial quantity is current production | |
q = total_production | |
# set growth rate to 1.18% | |
r = 0.0118 | |
# set limit equal to current proved reserves | |
L = total_reserves | |
print(sprintf("Current reserves are %e, current consumption is %e, current production is %e.", total_reserves, total_consumption, total_production)) | |
# this is when we will hit that limit | |
t = log(L * r / q + 1) / r | |
print(sprintf("Assuming no production growth, we will hit L in %f years.", total_reserves / total_production)) | |
print(sprintf("Assuming a growth rate of %f%% per year, we will hit L in %f years.", round(r * 100, 2), t)) | |
# now for consumption | |
q = total_consumption | |
t = log(L * r / q + 1) / r | |
print(sprintf("Assuming no consumption growth, we will hit L in %f years.", total_reserves / total_consumption)) | |
print(sprintf("Assuming a growth rate of %f%% per year, we will hit L in %f years.", round(r * 100, 2), t)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment