Skip to content

Instantly share code, notes, and snippets.

Avatar

Michy mick001

View GitHub Profile
@mick001
mick001 / Linear_model.R
Created Aug 28, 2015
Linear model with 4 variables in R
View Linear_model.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 Jan 17, 2021
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
View arrivalTimes1.R
#-------------------------------------------------------------------------------
# Loading data
#-------------------------------------------------------------------------------
# Observed data
data <- read.csv('data.txt',header=T)
# Take a look of the data
View(data)
@mick001
mick001 / arrivalTimes2.R
Created Aug 28, 2015
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
View arrivalTimes2.R
#-------------------------------------------------------------------------------
# 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 Aug 28, 2015
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
View arrivalTimes3.R
#-------------------------------------------------------------------------------
# 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 Aug 28, 2015
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
View arrivalTimes4.R
#-------------------------------------------------------------------------------
# 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
View waveEquation.py
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)
View RCRL.py
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
View RC.py
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 Aug 28, 2015
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
View transportEq.py
#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)
View heatEquation2.py
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