Skip to content

Instantly share code, notes, and snippets.

View mick001's full-sized avatar

Michy mick001

View GitHub Profile
@mick001
mick001 / Linear_model.R
Created August 28, 2015 01:00
Linear model with 4 variables in R
#-------------------------------------------------------------------------------
# Another linear model using more information y = a*x1 + b*x2 + c*x3 + d*x4
#-------------------------------------------------------------------------------
# Plot data
plot(disp,wt,type='p',xlab='Disp',ylab='Wt',main='Linear regression')
# Add a legend
legend("topleft",c("Observ.","Predicted"), col=c("black","red"), lwd=3)
@mick001
mick001 / arrivalTimes1.R
Last active January 17, 2021 03:46
Estimating arrival times of people in a shop using R. Part 1. Full article at: http://www.firsttimeprogrammer.blogspot.com/2015/07/estimating-arrival-times-of-people-in.html
#-------------------------------------------------------------------------------
# Loading data
#-------------------------------------------------------------------------------
# Observed data
data <- read.csv('data.txt',header=T)
# Take a look of the data
View(data)
@mick001
mick001 / arrivalTimes2.R
Created August 28, 2015 18:33
Estimating arrival times of people in a shop using R. Part 2. Full article at: http://www.firsttimeprogrammer.blogspot.com/2015/07/estimating-arrival-times-of-people-in.html
#-------------------------------------------------------------------------------
# Simulation
#-------------------------------------------------------------------------------
# Estimated parameters of the exponential distribution
x.rate <- length(data$num)
# Remember that mean = 1/x.rate
# meaning that, on average, we expect a new arrival every 1/74 of an hour.
# (1/74 =~ 0.01355)
@mick001
mick001 / arrivalTimes3.R
Created August 28, 2015 18:35
Estimating arrival times of people in a shop using R. Part 3. Full article at: http://www.firsttimeprogrammer.blogspot.com/2015/07/estimating-arrival-times-of-people-in.html
#-------------------------------------------------------------------------------
# Compare simulated to obseved data
#-------------------------------------------------------------------------------
# Let's compare observed data with simulated data
# Comparative boxplot
boxplot(interarrivals,simulated.min,xlab='Minutes',col=c('cyan','chartreuse'),
border=c('blue','seagreen'),names=c('Observed','Simulated'),
main='Interarrival times',notch=TRUE,horizontal=TRUE)
@mick001
mick001 / arrivalTimes4.R
Created August 28, 2015 18:36
Estimating arrival times of people in a shop using R. Part 4. Full article at: http://www.firsttimeprogrammer.blogspot.com/2015/07/estimating-arrival-times-of-people-in.html
#-------------------------------------------------------------------------------
# Probability distributions
#-------------------------------------------------------------------------------
# Density plot
#Since the rate is given as person/hour we need to set time in hours
#Initial time Final time Step
#0 hour 0.15 of an hour 0.001 of an hour
#0 minutes 9 minutes 0.06 minutes = 3.6 seconds
@mick001
mick001 / waveEquation.py
Last active August 28, 2015 18:44
The wave equation: a Python implementation. Full article at: http://www.firsttimeprogrammer.blogspot.com/2015/07/the-wave-equation-2d-and-3d.html
import numpy as np
from numpy import pi
import matplotlib.pyplot as plt
import matplotlib.animation as animation
plt.style.use('dark_background')
fig = plt.figure()
fig.set_dpi(100)
ax1 = fig.add_subplot(1,1,1)
import numpy as np
import matplotlib.pyplot as plt
plt.style.use('ggplot')
l = 0.0229 #Inductance (H)
r = 3.34 #Resistance (Ohm)
v = 5 #Voltage (V) DC
i = v/r #Peak current (A)
tau = l/r #Tau time constant
import numpy as np
import matplotlib.pyplot as plt
plt.style.use('ggplot')
c = 100 * 10**(-6)
v = 5
r = 2000
t = np.linspace(0,1,1000)
@mick001
mick001 / transportEq.py
Created August 28, 2015 18:57
Transport equation with decay, a Python implementation. Full article can be found at http://www.firsttimeprogrammer.blogspot.com/2015/07/pdes-time-again-transport-equation.html
#Transport equation with decay implementation
import numpy as np
from numpy import pi
import matplotlib.pyplot as plt
import matplotlib.animation as animation
fig = plt.figure()
fig.set_dpi(100)
ax1 = fig.add_subplot(1,1,1)
@mick001
mick001 / heatEquation2.py
Last active August 28, 2015 19:03
Heat Equation part 2 a slight modification. Full article can be found at http://www.firsttimeprogrammer.blogspot.com/2015/07/heat-equation-part-2-slight-modification.html
import numpy as np
from numpy import pi
import matplotlib.pyplot as plt
import matplotlib.animation as animation
fig = plt.figure()
fig.set_dpi(100)
ax1 = fig.add_subplot(1,1,1)
#Diffusion constant