Skip to content

Instantly share code, notes, and snippets.

View vcarret's full-sized avatar

Vincent Carret vcarret

View GitHub Profile
@vcarret
vcarret / Vincent Carret - Frisch (1933): And yet it rocks.r
Last active January 4, 2023 20:45
Source code of the figures in the paper "And yet it rocks! Fluctuations and growth in Ragnar Frisch's rocking horse model"
# Author: Vincent Carret
# Contact: vincent.carret@univ-lyon2.fr
# This R script reproduces the figures in the paper "And yet it rocks! Fluctuations and growth in Ragnar Frisch's rocking horse model" (version 3 - online 5 Dec. 2020)
# There is an app version accessible here: https://cbheem.shinyapps.io/Frisch/
# The libraries at the beginning are necessary and must be installed
library(plotly)
library(dplyr)
# Functions ----
@vcarret
vcarret / complex-W.r
Last active June 29, 2020 15:21
Pure R algorithm for the complex branches of the Lambert W function. Based on Corless et al. (1996) and Istvan Mezo C++ implementation (https://github.com/IstvanMezo/LambertW-function). Quite slow compared to the C++ version which can be run with Rcpp
initPoint <- function(z, k){
I <- complex(real = 0, imaginary = 1)
tPiKI <- complex(real = 0, imaginary = 2*pi*k)
ip <- log(z) + tPiKI - log(log(z) + tPiKI)
p <- sqrt(2*(exp(1)*z+1))
if(abs(z - (-exp(-1))) <= 1){
if(k == 0) ip <- -1 + p - 1/3 * p^2 + 11/72 * p^3
if(k == 1 && Im(z) < 0) ip <- -1 - p - 1/3 * p^2 - 11/72 * p^3
if(k == -1 && Im(z) > 0) ip <- -1 - p - 1/3 * p^2 - 11/72 * p^3