Skip to content

Instantly share code, notes, and snippets.

@kailaix
kailaix / find_largest.py
Created August 14, 2018 05:05
find largest number
def find_largest(L):
N = len(L)
minL = [ [None] * N for j in range(N)]
sumL = [ [None] * N for j in range(N)]
def helper(i):
if i==0:
minL[0][0] = L[0]
else:
for j in range(i):
@kailaix
kailaix / example.jl
Created November 30, 2018 02:45
Julia: export figures to tikz
using PyPlot
using PyCall
@pyimport matplotlib2tikz as mpl
mpl.save("figures/fig.tex")
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kailaix
kailaix / assembler.jl
Created December 22, 2018 02:57
Assembler Programming
# This is an example of solving the Poisson problem using the Assembler Programming method
# (-Δ) u(x) = f(x)
# u(x) = 0, x ∈ [0,1]^2
# The exact solution is u(x,y) = sin(pi*x)sin(pi*y)
# and f(x,y) = 2pi^2 * sin(pi*x)sin(pi*y)
using PyPlot
import Plots
using PyCall
using SparseArrays
@kailaix
kailaix / planestress.jl
Created December 22, 2018 04:40
Plane Stress: An Example of Assembler Programming
# This example solves the plane stress problem
# E/(2(1+ν)) ∇^2 u_1 + E/(2(1-ν)) * ∂/∂x ( ∂u_1/∂x + ∂u_2/∂y ) = f1
# E/(2(1+ν)) ∇^2 u_2 + E/(2(1-ν)) * ∂/∂y ( ∂u_1/∂x + ∂u_2/∂y ) = f2
# Exact solution = sin(πx)sin(πy)
# f1, f2, σ can be evaluated analytically
using LinearAlgebra
using PyPlot
import Plots
@kailaix
kailaix / wave.jl
Last active July 28, 2022 11:05
Example of 1D Wave Equation with Absorbing Boundary Condition
# solve 1D wave equation with ABC
using PyPlot
using Plots
using LinearAlgebra
N = 100
x = LinRange(-1.,1.,N+1)
Δx = x[2]-x[1]
NT = 200
@kailaix
kailaix / mlp.jl
Last active December 25, 2018 21:58
Multilayer Perceptron in Julia
using TensorFlow
num_layers = 3 # number of hidden layer
nh = 20 # number of neurons per hidden layer
"""
neural(x, scope="default", reuse=false)
A Multilayer Perceptron with `num_layers` hidden layers. The last layer is a linear layer.
The neural network is enough to perform many useful approximations
"""
@kailaix
kailaix / CO2.png
Last active December 28, 2018 02:54
Predicting CO2 using PyTensorFlow
CO2.png