Skip to content

Instantly share code, notes, and snippets.

View klunkean's full-sized avatar
🏠
Working from home

klunkean klunkean

🏠
Working from home
View GitHub Profile
fname = "7_input.txt"
import numpy as np
with open(fname) as f:
xi = np.array([int(c) for c in f.readline().strip().split(",")], dtype=int)
def costfun(x, xi):
return sum([sum(range(abs(x-xii)+1)) for xii in xi])
def direction(x, xi):
from dolfin import *
import matplotlib.pyplot as plt
import numpy as np
import mshr
import math
# Algorithmic parameters
niternp = 20 # number of non-penalized iterations
niter = 100 # total number of iterations
pmax = 4 # maximum SIMP exponent
@klunkean
klunkean / costa_rica.py
Created August 11, 2021 14:42
Plot of cos(tan(rica)) where rica in [0, pi]
from matplotlib.pyplot import subplots
from numpy import cos, tan, linspace, pi
fig, ax = subplots(1,1)
rica = linspace(0,pi,500)
costa_rica = cos(tan(rica))
#
ax.plot(
rica,
costa_rica,
@klunkean
klunkean / main.c
Last active August 29, 2015 14:21
int main(void)
{
DDRA |= (1 << PIN_OUT1) | (1 << PIN_OUT2);
PORTA |= ( (1<<PIN_RPI) );
BITCLEAR(PORTA, PIN_OUT1);
unsigned int OLDSTATE = BITREAD(PINA, PIN_RPI);
uint8_t mode = 1;
while(1)
{
if(BITREAD(PINA, PIN_RPI) != OLDSTATE)
#define F_CPU 1000000L
#include <avr/io.h>
#include <util/delay.h>
#define PIN_OUT1 PA0
#define PIN_RPI PA7
#define BITSET(prt, pn) prt |= (1<<pn)
#define BITCLEAR(prt, pn) prt &= ~(1<<pn)
#define BITREAD(pin, bit) (pin & (1 << bit))
void pwmcycle(uint8_t tOn, uint8_t tOff)
{
BITSET(PORTA,PIN_OUT1);
wait(tOn);
BITCLEAR(PORTA,PIN_OUT1);
wait(tOff);
}
@klunkean
klunkean / wait.c
Last active August 29, 2015 14:21
void wait(uint8_t time)
{
uint8_t i;
for(i = 0; i < time+1; i+=1)
_delay_ms(1);
}