This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def randomvariate(pdf,n=1000,xmin=0,xmax=1): | |
""" | |
Rejection method for random number generation | |
=============================================== | |
Uses the rejection method for generating random numbers derived from an arbitrary | |
probability distribution. For reference, see Bevington's book, page 84. Based on | |
rejection*.py. | |
Usage: | |
>>> randomvariate(P,N,xmin,xmax) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import uncertainties as unc | |
import uncertainties.unumpy as unumpy | |
import numpy | |
import nemmen | |
# Defines x and y | |
x=numpy.linspace(0,10,50) | |
y=numpy.linspace(15,20,50) | |
# Defines the error arrays, values follow a normal distribution |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def random_normal(mean,std,n): | |
""" | |
Returns an array of n elements of random variables, following a normal | |
distribution with the supplied mean and standard deviation. | |
""" | |
import scipy | |
return std*scipy.random.standard_normal(n)+mean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import fish | |
import time | |
steps=input('How many steps? ') | |
# Progress bar initialization | |
peixe = fish.ProgressFish(total=steps) | |
for i in range(steps): | |
# Progress bar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Count words in a latex file, without taking into account | |
# the latex constructs | |
detex $file | wc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -w | |
# | |
# Source: http://handyfloss.net/2008.09/making-a-pdf-grayscale-with-ghostscript/ | |
# handyfloss blog | |
# | |
# Usage: pdf2gray.pl input_color.pdf | |
use strict; | |
my $infile = $ARGV[0]; | |
my $outfile = $infile; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Galaxy rotation curves in Mathematica | |
Author: Rodrigo Nemmen | |
Visually illustrating the impact of the presence of dark matter in speeding up the | |
rotation of test particles in galaxies | |
Input | |
nϕ=15; | |
rmin=1;rmax=50; nr=40; | |
tmin=0; tmax=15Pi; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Captures regular screenshots and saves them to dropbox. | |
# Useful when I leave my linux box doing number crunching | |
# over long periods. | |
# | |
# t = number of seconds in-between screenshots | |
t=5400 # 1.5 h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def confband(xd,yd,a,b,conf=0.95,x=None): | |
""" | |
Calculates the confidence band of the linear regression model at the desired confidence | |
level, using analytical methods. The 2sigma confidence interval is 95% sure to contain | |
the best-fit regression line. This is not the same as saying it will contain 95% of | |
the data points. | |
Arguments: | |
- conf: desired confidence level, by default 0.95 (2 sigma) | |
- xd,yd: data arrays |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def scatterfit(x,y,a=None,b=None): | |
""" | |
Compute the mean deviation of the data about the linear model given if A,B | |
(y=ax+b) provided as arguments. Otherwise, compute the mean deviation about | |
the best-fit line. | |
x,y assumed to be Numpy arrays. a,b scalars. | |
Returns the float sd with the mean deviation. | |
Author: Rodrigo Nemmen |
OlderNewer