CoCalc Public Filesjulia-1.ipynbOpen with one click!
Authors: Harald Schilly, ℏal Snyder
Views : 493
Compute Environment: Ubuntu 18.04 (Deprecated)

Julia 1.0 Kernel in CoCalc

In [1]:

Here is the other common building block for programming: Evaluating a block of code more than once, e.g. by either counting the iterations or until a condition is met (or no longer met). This is one of the most confusing parts of programming. So don't be shy to take your time inspecting this. Try to evaluate this little program in your head by reading the lines over and over again...

In [4]:
using Printf s = 0 for i = [1 2 5 100 -1 5] s = s + i @printf("i = %4d → s = %4d\n", i, s) end
i = 1 → s = 1 i = 2 → s = 3 i = 5 → s = 8 i = 100 → s = 108 i = -1 → s = 107 i = 5 → s = 112
In [3]:
@printf("%.2f", pi)
3.14
In [1]:
1+1+1+23
26
In [2]:
VERSION
v"1.0.5"
In [3]:
ENV["JULIA_DEPOT_PATH"]
"/home/user/.julia:/ext/julia/depot/"
In [ ]:
Pkg.installed()
In [ ]:
using Pkg for (k, v) in Pkg.installed() println(k, ":::", (if nothing == v "N/A" else v end)) end
In [ ]:
using Printf
In [ ]:
s = 0 for i = [1 2 5 100 -1 5] s = s + i @printf("i = %4d → s = %4d\n", i, s) end
In [ ]:
[sin(3.14), sin(3.141), sin(3.142)]
In [ ]:
println("Hello", 99) x = 10 println("Interpolation $(5 + x)") @printf("pi = %.7f\n", float(pi))
In [ ]:
Printf.@printf("%f %F %f %F\n", Inf, Inf, NaN, NaN)
In [ ]:
using CSV
In [ ]:
using DataFrames
In [ ]:
#using Gadfly
In [ ]:
using Nemo

In [5]:
using Statistics
In [6]:
Statistics.median([8 9 8 6 87 6 7 6 5.1 4 5 4 3 4 3 3 3 3 ])
5.05
In [7]:
using LinearAlgebra
In [8]:
m1 = [ 1 2 -3 3 -1 1 1.0 1 1] q1, r1 = LinearAlgebra.qr(m1)
LinearAlgebra.QRCompactWY{Float64,Array{Float64,2}} Q factor: 3×3 LinearAlgebra.QRCompactWYQ{Float64,Array{Float64,2}}: -0.301511 0.816497 -0.492366 -0.904534 -0.408248 -0.123091 -0.301511 0.408248 0.86164 R factor: 3×3 Array{Float64,2}: -3.31662 2.22045e-16 -0.301511 0.0 2.44949 -2.44949 0.0 0.0 2.21565
In [9]:
q1 * r1
3×3 Array{Float64,2}: 1.0 2.0 -3.0 3.0 -1.0 1.0 1.0 1.0 1.0

In [ ]:
using DifferentialEquations α=1 β=1 u₀=1/2 f(t,u) = α*u g(t,u) = β*u dt = 1//2^(4) tspan = (0.0,1.0) prob = SDEProblem(f,g,u₀,(0.0,1.0)) sol = solve(prob,EM(),dt=dt) using Plots plot(sol)
In [ ]:
using DifferentialEquations f(x) = sin(2π.*x[:,1]).*cos(2π.*x[:,2]) gD(x) = sin(2π.*x[:,1]).*cos(2π.*x[:,2])/(8π*π) dx = 1//2^(5) mesh = notime_squaremesh([0 1 0 1],dx,:dirichlet) prob = PoissonProblem(f,mesh,gD=gD) sol = solve(prob) using Plots plot(sol)
In [ ]:
using GLM

In [10]:
using PyPlot x = range(0, stop = 4*pi, length=1000) y = sin.(3*x + 1.5*cos.(2*x)) plot(x, y, color="red", linewidth=2.0, linestyle="--")
┌ Info: Precompiling PyPlot [d330b81b-6aea-500a-939a-2ce795aea3ee] └ @ Base loading.jl:1192
1-element Array{PyCall.PyObject,1}: PyObject <matplotlib.lines.Line2D object at 0x7f857bae0c50>
In [11]:
using PyPlot x = range(0; stop=2*pi, length=1000); y = sin.(3 * x + 4 * cos.(2 * x)); plot(x, y, color="red", linewidth=2.0, linestyle="--") title("A sinusoidally modulated sinusoid")
PyObject Text(0.5, 1, 'A sinusoidally modulated sinusoid')

In [ ]:
using D4M
In [ ]:
row = "a,a,a,a,a,a,a,aa,aaa,b,bb,bbb,a,aa,aaa,b,bb,bbb," column = "a,aa,aaa,b,bb,bbb,a,a,a,a,a,a,a,aa,aaa,b,bb,bbb," values = "a-a,a-aa,a-aaa,a-b,a-bb,a-bbb,a-a,aa-a,aaa-a,b-a,bb-a,bbb-a,a-a,aa-aa,aaa-aaa,b-b,bb-bb,bbb-bbb," A = Assoc(row,column,values)
In [ ]:
Ar = A["a,b,",:]
In [ ]:
Ac = A[:,"a,b,"]
In [ ]:
Av = A > "b,"

SymPy test

In [ ]:
using SymPy x = symbols("x") # or @vars x, Sym("x"), or Sym(:x) y = sin(pi*x) y(1), y(2.2), y(123456)

Unicode Plots

In [ ]:
using Plots unicodeplots()
In [ ]:
# /Users/tom/.julia/v0.4/Plots/docs/example_generation.jl, line 50: plot(sin,x-> sin(1.5x), 0, 4π, line=1, leg=false, fill=(0,:orange))
In [ ]: