Skip to content

Instantly share code, notes, and snippets.

@kourzanov
Last active January 15, 2020 12:55
Show Gist options
  • Save kourzanov/d24ecfe27bd57866406c3d7f9e17bca4 to your computer and use it in GitHub Desktop.
Save kourzanov/d24ecfe27bd57866406c3d7f9e17bca4 to your computer and use it in GitHub Desktop.
Julia prelude
# basic packages and plotting
versioninfo()
using FFTW, DSP, DataFrames, Query, Plots, StatsPlots; #plotlyjs()
const N=100
plot(1:N,1:N |> x->cos.(2pi*x/N)+0sin.(2pi*x/N) |> fft |> x->abs.(x) |> fftshift)
# calling to C++ via LLVM
using Cxx
cxx"""#include <iostream>"""
cxx"""using namespace std;"""
icxx"""cout << 123+234 << endl;"""
#__current_compiler__ = Cxx.new_clang_instance()
# adding new packages
using Pkg
Pkg.add("CSV")
using CSV
# process tabled data
df=DataFrame(xs=1:N,ys=1:N |> x->sin.(2pi*x/N),zs=1:N |> x->cos.(2pi*x/N))
display(df)
df1 = ( @from d in df begin
@where d.ys>.5
@select d
@collect DataFrame
end )
display(df1)
CSV.write("df1.csv",df1)
@df stack(df,[:ys,:zs]) plot(:xs,:value,group=:variable)
# get help
?CSV.write
# Units
using Pkg; Pkg.add("Unitful")
using Unitful
SpeedOfLight=299_792_458u"m/s"
freq=2.959u"GHz"
len=SpeedOfLight/u"s^-1"(freq)
display(len)
ustrip(len)
# Setup Conda (working with Python packages)
ENV["PYTHON"]=""
using Pkg
Pkg.build("PyCall")
Pkg.build("PyPlot")
Pkg.add("Conda")
# SciPy
using Conda
Conda.add("scipy")
using PyCall
so=pyimport("scipy.optimize")
display(so.newton(x->cos(x)-2x,1))
using PyPlot
x=-3:.1:3
plot(x,cos.(x)-2x,x,zeros(length(x)))
# SymPy
using Pkg
Pkg.add("SymPy")
using SymPy
x=symbols(:x)
eval(solve(x^4-x-1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment