Skip to content

Instantly share code, notes, and snippets.

View acbalingit's full-sized avatar
🐈
🐈🐈🐈

Chester Balingit acbalingit

🐈
🐈🐈🐈
View GitHub Profile
@acbalingit
acbalingit / hybrid.py
Created December 7, 2011 06:36
FFFFFFFUUUUUUUUUUUU
import numpy as np
import time
import matplotlib.pyplot as plt
#function
def f(x):
y = x**2 - 4*x*np.sin(x) + (2*np.sin(x))**2
return y
#routine
@acbalingit
acbalingit / one.r
Created December 7, 2011 10:12 — forked from anonymous/one
## a second order differential equation
## D2 y + 2 r w D y + w^2 y = 0
# D is the differential operator
# r is the damping ratio (r = c/(2mw))
# w is the undamped frequency
# c is the viscous damping coefficent
# m is the mass
#////////////////////////////////////////////////////////////////////////////////
#// //
#// Description: //
@acbalingit
acbalingit / rk4-ode2.r
Created December 7, 2011 15:58
vanilla RK4 for ODE2, written in R (07Dec2011)
# vanilla RK4 written in R (07Dec2011)
# evaluates a 2nd order ODE by splitting into 2- 1st order ODE
# and solved by Runge-Kutta Method
# Concepts and algorithm from:
# http://en.wikipedia.org/wiki/Runge-Kutta_methods
# http://www.cms.livjm.ac.uk/etchells/notes/ma200/2ndodes.pdf
#
# f1(t,y) : substituted function from dz(y')/dt = F(z,y,t), z = y'
#
# rk4(f, h, tinit, yinit, limit): main RK4 routine
# vanilla RK4 written in R (09Dec2011) v1.1
# evaluates a 2nd order ODE by splitting into 2- 1st order ODE
# and solved by Runge-Kutta Method
# Concepts and algorithm from:
# http://en.wikipedia.org/wiki/Runge-Kutta_methods
# http://www.cms.livjm.ac.uk/etchells/notes/ma200/2ndodes.pdf
#
# f1(t,y) : substituted function from dz(y')/dt = F(z,y,t), z = y'
#
# rk4(f, h, tinit, yinit, limit): main RK4 routine
def cat_n_times(s, n):
print n*str(s)
def is_divisible_by_3(n):
if n%3 == 0: print "This number is divisible by 3."
else: print "This number is not divisible by 3."
@acbalingit
acbalingit / root.py
Created December 14, 2011 00:57
Set of root finders for AP155 - Functions and Roots Exercise
#!/usr/bin/env python
import numpy as np
import matplotlib.pyplot as plt
from scipy.misc import *
import time
def func(x):
return x*x - 4*x*np.sin(x) +(2*np.sin(x))**2
@acbalingit
acbalingit / sdf.py
Created December 21, 2011 02:21
yo yo yo
__author__ = "Chester Balingit"
import numpy as np
from scipy import optimize
import matplotlib.pyplot as plt
## Part 1 - Find all the zeros of the function:
## f(x) = cos(x) - xsin(x) using the optimize.brentq
## function of the scipy library
import scipy.optimize as optimize
import numpy as np
import collections
import matplotlib.pyplot as plt
from numpy import random
def sampler(points,mu,sigma):
return np.linspace(0, 2*np.pi, points), \
np.sin(np.linspace(0, 2*np.pi, points)) \
+ random.normal(mu,sigma,size=(points))
@acbalingit
acbalingit / numint.py
Created February 19, 2012 11:18
Trapezoidal and Romberg Integration
import numpy as np
import matplotlib.pyplot as plt
func = lambda x: np.sin(x)
d1func = lambda x: np.cos(x)
d3func = lambda x: -1*np.cos(x)
def trapezoidal(func, n, dfunc='null',dddfunc='null', x0=0, xn=np.pi):
x = np.linspace(x0, xn, n)
import random
import numpy as np
import matplotlib.pyplot as plt
import networkx as nx
from plots import *
import pickle
#bump
def coord_solver(trigs, rad):
"""