Skip to content

Instantly share code, notes, and snippets.

View mick001's full-sized avatar

Michy mick001

View GitHub Profile
@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
@mick001
mick001 / estimatDataParameters.R
Last active August 28, 2015 19:09
Estimating data parameters using R (confidence intervals). Full article at http://www.firsttimeprogrammer.blogspot.com/2015/07/estimating-data-parameters-using-r.html
###############################################################################
# Confidence intervals for the population mean (t-student distribution)
# We assume that
# 1. Data is normally distributed
# 2. Samples are iid
#
# Note that population variance is unknown and therefore must be
# estimated. In this case Student distribution should be used.
# The number of degree of freedom is n-1 where n is the size of
# the sample. Note that as n -> Inf the Student distribution tends to
@mick001
mick001 / test_hp.R
Last active August 28, 2015 19:23
Hypothesis testing on normally distributed data in R. Full article at: http://www.firsttimeprogrammer.blogspot.com/2015/07/hypothesis-testing-on-normally.html
###############################################################################
# The code below can be used to perform a z-test under the following
# assumptions:
# 1. The data is normally distributed
# 2. Samples are iid
#
# Remember that:
# 1.Low pvalue: strong empirical evidence against h0
# 2.High pvalue: little or 'no' empirical evidence against h0
#
@mick001
mick001 / test_hp2.R
Created August 28, 2015 19:24
Hypothesis testing on normally distributed data in R (part 2). Full article at: http://www.firsttimeprogrammer.blogspot.com/2015/07/hypothesis-testing-on-normally.html
# Plot of the Student distribution
dfs <- length(data_vector)-1
x_ <- seq(-8,8,0.1)
y <- dt(x_,dfs)
t.val <- qt(1-0.05,df=dfs)
plot(x_,y,type='l',lwd=3,col='blue',xlab='x',ylab='Density',main='Student distribution 9 dof')
abline(v=0)
abline(v=t.val,lwd=2,col='red')
points(t.val,dt(t.val,dfs),lwd=3,col='red')
@mick001
mick001 / complex_flow1.m
Created August 28, 2015 19:31
Complex functions and flow around a cylinder part 1 (matlab). Full article available at: http://www.firsttimeprogrammer.blogspot.com/2015/07/complex-functions-and-flow-around.html
% Set up
x = -4:0.2:4;
y1 = -4:0.2:4;
y = (-4:0.2:4)*1i;
[X, Y]= meshgrid(x,y);
% Complex variable s
s = X + Y;
% Complex function f(z)
@mick001
mick001 / complex_flow2.m
Created August 28, 2015 19:32
Complex functions and flow around a cylinder part 2 (matlab). Full article available at: http://www.firsttimeprogrammer.blogspot.com/2015/07/complex-functions-and-flow-around.html
%%Gradient and flow
figure
subplot(1,2,1);
[Dx, Dy] = gradient(real(z));
Dx(isinf(Dx)) = 0;
Dy(isinf(Dy)) = 0;
hQuiver = quiver(x,y1,Dx,Dy,'LineWidth',1); hold on;
viscircles([0 0],1,'LineWidth',1); hold off;
title('u(x,y) gradient, vector field');
@mick001
mick001 / complex_flow3.m
Created August 28, 2015 19:32
Complex functions and flow around a cylinder part 3 (matlab). Full article available at: http://www.firsttimeprogrammer.blogspot.com/2015/07/complex-functions-and-flow-around.html
figure
subplot(1,3,1)
C1 = contour(x,y1,abs(z),linspace(-10,10,100)); title('Contour of abs(f)');
xlabel('x'); ylabel('y'); %clabel(C1);
subplot(1,3,2)
C2 = contour(x,y1,real(z),linspace(-10,10,100)); title('Contour of re(f)');
xlabel('x'); ylabel('y'); %clabel(C2);
subplot(1,3,3)
C3 = contour(x,y1,imag(z),linspace(-10,10,100)); title('Contour of Im(f)');
xlabel('x'); ylabel('y'); %clabel(C3);
@mick001
mick001 / normal_data_1.R
Created August 28, 2015 19:38
How to make a rough check to see if your data is normally distributed part 1 (R). Full article at: http://www.firsttimeprogrammer.blogspot.com/2015/07/how-to-make-rough-check-to-see-if-your.html
# Simulated data (normal and beta distributions)
set.seed(70)
data_norm <- rnorm(100,0,1)
data_beta <- rbeta(1000,2,30)*10
# Compare the boxplots
boxplot(data_norm,data_beta,col='cyan')
@mick001
mick001 / normal_data_2.R
Created August 28, 2015 19:40
How to make a rough check to see if your data is normally distributed part 2 (R). Full article at: http://www.firsttimeprogrammer.blogspot.com/2015/07/how-to-make-rough-check-to-see-if-your.html
# Skewness
library(moments)
print("Skewness:")
print("Normal")
skewness(data_norm)
print("Beta")
skewness(data_beta)
# < 0 skewed left (left tail)
# > 0 skewed right (right tail)
@mick001
mick001 / normal_data_3.R
Created August 28, 2015 19:41
How to make a rough check to see if your data is normally distributed part 3 (R). Full article at: http://www.firsttimeprogrammer.blogspot.com/2015/07/how-to-make-rough-check-to-see-if-your.html
# Compare the histograms
hist(data_norm,col='red')
hist(data_beta,col='blue')