Skip to content

Instantly share code, notes, and snippets.

@goretkin
goretkin / scipy_fmin_cobyla_test.py
Created August 2, 2011 19:50
fmin_cobyla is returning nan
# -*- coding: utf-8 -*-
"""
Created on Tue Aug 2 15:43:21 2011
@author: gustavo
"""
from scipy.optimize import fmin_cobyla
import numpy as np
@goretkin
goretkin / kane_linearization.py
Created January 23, 2012 21:33
sympy Kane linearization
import sympy
import sympy.utilities
from sympy import symbols
from sympy.physics.mechanics import *
#based on http://pydy.org/index.php?title=Double_Pendulum
q1, q2 = dynamicsymbols('q1 q2')
q1d, q2d = dynamicsymbols('q1 q2', 1)
u1, u2 = dynamicsymbols('u1 u2')
@goretkin
goretkin / gist:2920237
Created June 12, 2012 21:27
matplotlib rectangle intersection
import matplotlib as mpl
import matplotlib.pyplot as plt
r1 = mpl.patches.Rectangle((0.0,0.0),2.0,3.0)
r2 = mpl.patches.Rectangle((0.0,0.0),3.0,2.0)
r3 = mpl.patches.Rectangle((10.0,10.0),2.0,3.0)
r1.set_color('r')
r2.set_color('g')
r3.set_color('b')
@goretkin
goretkin / gist:2989424
Created June 25, 2012 15:59
matplotlib animation issue
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import matplotlib as mpl
ani_fig = plt.figure(None)
ani_ax = ani_fig.gca()
ani_ax.set_xlim(0,1)
ani_ax.set_ylim(0,1)
ani_ax.set_aspect('equal')
import numpy as np
from scipy.spatial import Delaunay
#from http://pydec.googlecode.com/svn-history/r10/trunk/pydec/math/circumcenter.py
__all__ = ['is_wellcentered', 'circumcenter', 'circumcenter_barycentric']
from numpy import bmat, hstack, vstack, dot, sqrt, ones, zeros, sum, \
asarray
#LyX 2.0 created this file. For more info see http://www.lyx.org/
\lyxformat 413
\begin_document
\begin_header
\textclass article
\begin_preamble
\usepackage[T1]{fontenc}
\usepackage{multicol}
\end_preamble
\use_default_options true
@goretkin
goretkin / eigsum-bug
Created March 17, 2013 09:41
Bug with eigsum on Numpy 1.6.1
Code:
import numpy as np
ndims = 3
nbowls = 1 #no crash if this is >1
npts = 10000
bowls = np.random.randn(ndims,ndims,nbowls)
queries = np.random.randn(ndims,npts)
@goretkin
goretkin / interpolations.py
Last active August 29, 2015 13:57
Interpolation types (6.850 Geometric Computing)
{
"metadata": {
"name": "Interpolations-Copy1"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
module BallTree
dist = (p,q)->norm(p-q)
macro argbest(metric,compare,candidates,query)
#returns index into candidates with best metric
local best_so_far_value = metric(candidates[1],query)
local best_so_far_index = 1
for i in 1:length(candidates)
local m = metric(candidates[i],query)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.