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
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): |
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 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 |
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 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, |
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
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) |
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
#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)) |
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
void pwmcycle(uint8_t tOn, uint8_t tOff) | |
{ | |
BITSET(PORTA,PIN_OUT1); | |
wait(tOn); | |
BITCLEAR(PORTA,PIN_OUT1); | |
wait(tOff); | |
} |
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
void wait(uint8_t time) | |
{ | |
uint8_t i; | |
for(i = 0; i < time+1; i+=1) | |
_delay_ms(1); | |
} |