LaborCapitalAndTheOptimalGr.../CobbDouglas/README.md

69 lines
1.6 KiB
Markdown
Raw Normal View History

2020-09-24 10:39:48 +00:00
## README
## About
2021-03-09 17:04:26 +00:00
This is some R code for the paper [Labor, Capital, and the Optimal Growth ofSocial Movements](https-//nunosempere.github.io/ea/MovementBuildingForUtilityMaximizers.pdf)
2020-09-24 10:39:48 +00:00
## Structure of the code.
2021-03-09 17:04:26 +00:00
1. `Variables.R`- Contains variables
2. `Transition dynamics.R`- If we know our system at time t, generate an approximation of our system at time t+stepsize.
3. `Forward Shooting.R`- Carries out the forward shooting.
4. `ReverseShooting.R`- Nonfunctional. Ignore.
5. `Plotting.R`- Generates graphs of the results
2020-09-24 10:39:48 +00:00
## How to run
Open files 1.,2.,3., and 5. in an IDE for R, like RStudio. Run them in order. For `Plotting.R`, add or create the directory in which you want the graphs to be generated, making sure it has suitable permissions.
## Gotchas
2021-03-09 17:04:26 +00:00
Using a very small stepsize runs into floating point errors. Consider a stylized example-
2020-09-24 10:39:48 +00:00
```r
options(digits=22)
dx <- 10^43
numsteps <- 10^7
stepsize <- 10^(-3)
## Example 1
x <- pi*1e+60
print(x)
2021-03-09 17:04:26 +00:00
for(i in c(1-numsteps)){
2020-09-24 10:39:48 +00:00
x <- x+dx*stepsize
}
x == pi*1e+60
print(x)
## Example 2
x <- pi*1e+60 + numsteps*stepsize*dx
x == pi*1e+60
print(x)
```
The two examples should give the same results, but don't.
### Why reverse shooting doesn't work
2021-03-09 17:04:26 +00:00
Consider this example-
```r
## Stylized forward shooting
x <- 0
2021-03-09 17:04:26 +00:00
for(i in c(1-200)){
x <- x + 7^i
}
## Stylized reverse shooting
y <- x
2021-03-09 17:04:26 +00:00
for(i in c(200-1)){
y <- y - 7^i
}
print(y)
# [1] -3.762262199769919175323e+152
```
Here, `y` should at the end be 0, but floating point errors ensure that it isn't. Given that our variables grow exponentially, we work with very large numbers and reverse shooting encounters similar errors.