Instantly share code, notes, and snippets.

🥝
Focusing
Created May 20, 2022 15:15
View periodic_qr.jl
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
 using LinearAlgebra, BandedMatrices n = 3000 A = Matrix(SymTridiagonal(Symmetric(rand(n, n)))); A[end, 1] = A[1, end] = 1; b = rand(size(A, 1)) function periodic_givens_rotation!(A::AbstractMatrix{T}) where T m, n = size(A) gs = Vector{LinearAlgebra.Givens{T}}(undef, 2n-2) jj = 0
Last active July 31, 2020 18:39
View clenshaw_vs_gauss.jl
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
 using Plots, FastGaussQuadrature, FastTransforms fejer1(N) = FastTransforms.fejernodes1(Float64, N), FastTransforms.fejerweights1(FastTransforms.FastTransforms.chebyshevmoments1(Float64, N)) fejer2(N) = FastTransforms.fejernodes2(Float64, N), FastTransforms.fejerweights2(FastTransforms.FastTransforms.chebyshevmoments2(Float64, N)) clenshawcurtis(N) = FastTransforms.clenshawcurtisnodes(Float64, N), FastTransforms.clenshawcurtisweights(FastTransforms.FastTransforms.chebyshevmoments1(Float64, N)) x = range(-1.2, stop = 1.2, length = 1000) y = range(-0.4, stop = 0.4, length = 1000÷3) r(z, x, w) = sum(k->w[k]/(z - x[k]), eachindex(x)) ϕ(z) = log((z+1)/(z-1)) quadrature_contour(xs, w; kwargs...) = contour(x, y, (x, y) -> abs(r(x + y*im, xs, w) - ϕ(x + y*im)); levels=map(i->1/10^i, 0:10), aspect_ratio=1, colorbar=false, xlimits=(-1.5, 1.5), ylimits=(-0.5, 0.5), kwargs...) plts = [quadrature_contour(clenshawcurtis(64)...; title="Clenshaw-Curtis"),
Created July 30, 2020 22:40
View stability_contour.jl
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
 using DiffEqDevTools, BifurcationKit, Setfield, Plots mutable struct TermCache start sign::Bool count::Int end function stability_curve(tab) function curve((x, ), (y, ))
Created June 18, 2020 20:27
View teach_forwarddiff.jl
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
 using ForwardDiff goo((x, y, z),) = [x^2*z, x*y*z, abs(z)-y] foo((x, y, z),) = [x^2*z, x*y*z, abs(z)-y] function foo(u::Vector{ForwardDiff.Dual{T,V,P}}) where {T,V,P} # unpack: AoS -> SoA vs = ForwardDiff.value.(u) # you can play with the dimension here, sometimes it makes sense to transpose ps = mapreduce(ForwardDiff.partials, hcat, u) # get f(vs) val = foo(vs)
Created May 26, 2020 02:25
View linear_solve_design.jl
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
 #= Replace calcJ, calcW, linsolve, do_newJW to [u, p, t, newJ, newW, tol, error_estimate] foo!(z, integrator, alg, nlsolver) -> z .= W\z foo(z, integrator, alg, nlsolver) -> W\z foo!(z, integrators, alg, nlsolver) - User control inverse of W(_t) - user defined factorization (object with ldiv! defined) (Info: u, p, t, newW, tol, error_estimate)
Created April 3, 2020 04:40
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
 A = [11//45-7sqrt(6)/360 37//225-169sqrt(6)/1800 -2//225+sqrt(6)/75 37//225+169sqrt(6)/1800 11//45+7sqrt(6)/360 -2//225-sqrt(6)/75 4//9-sqrt(6)/36 4//9+sqrt(6)/36 1//9] T = Float64 T11 = convert(T, 9.1232394870892942792e-02) T12 = convert(T, -0.14125529502095420843e0) T13 = convert(T, -3.0029194105147424492e-02) T21 = convert(T, 0.24171793270710701896e0) T22 = convert(T, 0.20412935229379993199e0)
Last active January 15, 2020 03:59
View fd_typed.jl
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
 │ ─ %-1 = invoke perform_step!(::OrdinaryDiffEq.ODEIntegrator{Tsit5,true,Array{ForwardDiff.Dual{ForwardDiff.Tag{var"#25#26",Float64},Float64,4},1},Float64,DiffEqBase.NullParameters,Float 64,Float64,Float64,Array{Array{ForwardDiff.Dual{ForwardDiff.Tag{var"#25#26",Float64},Float64,4},1},1},ODESolution{ForwardDiff.Dual{ForwardDiff.Tag{var"#25#26",Float64},Float64,4},2,Array{ Array{ForwardDiff.Dual{ForwardDiff.Tag{var"#25#26",Float64},Float64,4},1},1},Nothing,Nothing,Array{Float64,1},Array{Array{Array{ForwardDiff.Dual{ForwardDiff.Tag{var"#25#26",Float64},Float 64,4},1},1},1},ODEProblem{Array{ForwardDiff.Dual{ForwardDiff.Tag{var"#25#26",Float64},Float64,4},1},Tuple{Float64,Float64},true,DiffEqBase.NullParameters,ODEFunction{true,typeof(lorenz),L inearAlgebra.UniformScaling{Bool},Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing,Nothing},Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple {}}},DiffEqBase.StandardODEProblem},Tsit5,OrdinaryDiffEq.InterpolationData{ODEFuncti
Last active January 15, 2020 03:54
View fd_llvm.ll
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