Skip to content

Instantly share code, notes, and snippets.

View briochemc's full-sized avatar

Benoît Pasquier briochemc

View GitHub Profile
@briochemc
briochemc / make_c_map_out_of_screenshot.m
Created June 12, 2018 20:40
make a colormap out of a screenshot
function [cbar] = make_c_map_out_of_screenshot(impath,crop,column)
% ------ Help for make_c_map_out_of_screenshot -------
%
% Creates a colorbar from a screenshot of another colorbar.
%
% How to use:
% 1) Make screenshot of the colorbar (Ideally, have the left most column of
% pixels right on the colormap)
% 2) Save as image file (png works, maybe other formats will not, try it out!)
% 3) Put path to file in some variable, e.g.:
@briochemc
briochemc / FastBackslash.jl
Created October 18, 2018 23:46
Testing factorisation in Julia
using LinearAlgebra, DualNumbers, BenchmarkTools, SparseArrays, SuiteSparse
n = 1000 # size of J and y
# make y
a, b = rand(n), rand(n)
y = a + b * ε
# make J
spA = sprandn(n, n, 10/n) + I
H \ sₖ
% The following takes a 3D matrix and averages across depths
% You want to see what the z depth are?
% I would suggest following Seth John's advice: use explcit names and capitals to show big 3d things
DEPTH = z ;
depth = squeeze(DEPTH(1,1,:)) ;
itoplayers = find(depth < 55) ; % this creates a range of the indices for depth less than (i.e., above) 55m
% Here this range is 0m–50m. Check the values before to make sure:
depths_top = depth(itoplayers) ; % These are the depth levels [0, 10, 20, 30, 40, 50]
[[AbstractFFTs]]
deps = ["Compat", "LinearAlgebra"]
git-tree-sha1 = "8d59c3b1463b5e0ad05a3698167f85fac90e184d"
uuid = "621f4979-c628-5d54-868e-fcf4e3e8185c"
version = "0.3.2"
[[Arpack]]
deps = ["BinaryProvider", "Libdl", "LinearAlgebra", "Random", "SparseArrays", "Test"]
git-tree-sha1 = "1ce1ce9984683f0b6a587d5bdbc688ecb480096f"
uuid = "7d9fca2a-8960-54d3-9f78-7d1dccf2cb97"
load Downloads/CTL.mat
T = output.TR ;
f1 = figure ;
spy(T, 'w') ;
darkBackground(f1, [0 0 0], [1 1 1])
f1(x) = x
f2(x) = 2x
f3(x) = 3x
list_methods = [
("method1", :f1)
("method2", :f2)
("method3", :f3)
]
# Example function to find the root of
f(x) = [(x[1] + x[2] + 1)^3, (x[1] - x[2] - 1)^3]
function f_Jac!(J, x)
J[1, 1] = 3(x[1] + x[2] + 1)^2
J[2, 1] = 3(x[1] - x[2] - 1)^2
J[1, 2] = 3(x[1] + x[2] + 1)^2
J[2, 2] = -3(x[1] - x[2] - 1)^2
return J
end
@briochemc
briochemc / Benchmark_backslash.jl
Created February 15, 2019 05:51
Benchmarking backslash in Julia with Float64, ComplexF64, and Dual128 (via DualMatrixTools.jl)
using LinearAlgebra, SparseArrays, SuiteSparse
using DualNumbers, DualMatrixTools
using BenchmarkTools
n = 1000 ;
y = rand(n) ;
A = sprand(n, n, 20/n) ;
i, j, v = findnz(A) ;
# Error check
using LinearAlgebra, SparseArrays, SuiteSparse, BenchmarkTools, MAT
M = matread("test_matrix.mat")["M"] ;
x = matread("test_matrix.mat")["x"] ;
Mf = factorize(M) ;
sol1 = Mf \ x ;
sol2 = M \ x ;
norm(x)
norm(x - M * sol1) / norm(x)
norm(x - M * sol1)