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 nodal | |
import sys | |
OUTFILE = "vll-sparse.csv" | |
RESISTANCE = 1 | |
CURRENT = 1 | |
def formattuple(coords, groundcoords): | |
if coords == groundcoords: | |
return "g" |
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 sys | |
import numpy as np | |
import csv | |
import logging | |
from math import ceil | |
logging.basicConfig(level=logging.WARNING) | |
OUTFILE = "vll.csv" | |
RESISTANCE = 1 | |
CURRENT = 1 |
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
from pyDatalog import pyDatalog as pyd | |
import sys | |
pyd.create_terms('L1, L2, I, triples') | |
def triples(maxleg): | |
return (L1.in_(range(1,maxleg)) & | |
L2.in_(range(1,maxleg)) & | |
I.in_(range(1, 2 * maxleg)) & | |
(I ** 2 == (L1 ** 2 + L2 ** 2)) | |
) |
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 Data.Number.CReal | |
e :: (Integral a, Fractional b) => a -> b | |
-- The last term of the Taylor series is (1 / x!) | |
e x = snd $ foldl (\(below, result) x -> (below * x, result + (1 / fromIntegral (below * x)))) (1,1) [1..x] | |
safeE :: Int -> String | |
-- n is the number of decimal places | |
safeE n = showCReal n $ | |
head [ e i | i <- [0..], showCReal n (e i) == showCReal n (e (i + 1))] |
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
MAXITER = 1000 | |
TOL = 1e-6 | |
def bis(func, lower, upper, maxiter=MAXITER, tol=TOL): | |
if lower >= upper: | |
raise ValueError('Range error: lower >= upper') | |
if func(lower) == 0: | |
return lower | |
elif func(upper) == 0: |
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
module Pigrec where | |
pigrec :: Int -> Float | |
pigrec x = foldl (ptwon) (2 * sqrt 2) (map (\x -> 2^x) [2..x]) | |
ptwon :: Double -> Int -> Double | |
-- Given the perimeter pn of a n-sided polygon inscribed in a | |
-- circle of diameter 1 returns the perimeter of the 2n-sided | |
-- polygon inscribed in the same circle | |
ptwon pn n = n' * ( sqrt (1 + l) - sqrt (1 - l)) |