Sharedjulia-1.1.ipynbOpen in CoCalc
Author: Harald Schilly
Views : 66

Julia 1.1 Kernel in CoCalc

In [1]:
1+1+1+1
4
In [2]:
VERSION
v"1.1.1"
In [3]:
ENV["JULIA_DEPOT_PATH"]
"/home/user/.julia/:/ext/julia/depot/"
In [4]:
ENV["JULIA_PROJECT"]
"/home/user/.julia/environment/v1.1"
In [5]:
# delete!(ENV, "JULIA_PROJECT") using Pkg for (k, v) in Pkg.installed() println(k, ":::", (if nothing == v "N/A" else v end)) end
In [6]:
# https://discourse.julialang.org/t/how-does-one-set-up-a-centralized-julia-installation/13922/29 using Pkg Pkg.activate(DEPOT_PATH[2]*"/environments/v1.1") installed_pkgs = Pkg.installed() Pkg.activate(DEPOT_PATH[1]*"/environments/v1.1") for (k, v) in installed_pkgs println(k, "=>", (if nothing == v "N/A" else v end)) end
D4M=>
┌ Info: activating new environment at ~/.julia/environments/v1.1. └ @ Pkg.API /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.1/Pkg/src/API.jl:524
0.1.0 Interact=>0.10.2 ImageMorphology=>0.2.1 ImageFiltering=>0.6.2 SymPy=>1.0.3 Compat=>2.1.0 ImageMagick=>0.7.3 Calculus=>0.4.1 Knet=>1.2.1 Cairo=>0.6.0 DataFrames=>0.18.2 Turing=>0.6.17 ImageDraw=>0.2.0 Primes=>0.4.0 LinearAlgebra=>N/A Plotly=>0.2.0 Combinatorics=>0.7.0 DiffEqFlux=>0.5.0 GraphPlot=>0.3.1 Gadfly=>1.0.1 FileIO=>1.0.6 Convex=>0.12.0 ImageAxes=>0.6.0 CSV=>0.5.3 ImageSegmentation=>1.2.0 Random=>N/A Optim=>0.18.1 StatsPlots=>0.10.2 ColorSchemes=>3.2.0 FFTViews=>0.2.0 Images=>0.18.0 IJulia=>1.18.1 Flux=>0.8.3 Plots=>0.25.1 PyPlot=>2.8.1 TestImages=>0.5.1 BlackBoxOptim=>0.4.0 DifferentialEquations=>6.4.0 UnicodePlots=>1.1.0 GLM=>1.1.1 Statistics=>N/A Fontconfig=>0.2.0 LightGraphs=>1.2.0 ImageFeatures=>0.3.0 JuMP=>0.19.1 Ipopt=>0.5.4 ImageMetadata=>0.7.0 Compose=>0.7.3 CoordinateTransformations=>0.5.0 Colors=>0.9.5 NLsolve=>4.0.0
In [7]:
using Printf
In [8]:
s = 0 for i = [1 2 5 100 -1 5 -6 7.12 948] 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 i = -6 → s = 106 i = 7 → s = 113 i = 948 → s = 1061
In [9]:
[sin(3.14), sin(3.141), sin(3.142)]
3-element Array{Float64,1}: 0.0015926529164868282 0.0005926535550994539 -0.00040734639894142617
In [10]:
println("Hello", 99) x = 10 println("Interpolation $(5 + x)") @printf("pi = %.7f\n", float(pi))
Hello99 Interpolation 15 pi = 3.1415927
In [11]:
Printf.@printf("%f %F %f %F\n", Inf, Inf, NaN, NaN)
Inf Inf NaN NaN
In [12]:
using CSV
In [13]:
using DataFrames
In [14]:
#using Gadfly
In [ ]:
In [ ]:
In [15]:
using LightGraphs g = PathGraph(6) g
{6, 5} undirected simple Int64 graph
In [16]:
nv(g)
6
In [17]:
import Fontconfig
In [ ]:
In [ ]:
In [ ]:
In [18]:
using Random
In [19]:
randn(10)
10-element Array{Float64,1}: -0.5526782733083008 -2.501006177705549 -0.533171626733729 -0.7297475643798319 0.6878756570484674 -1.0432055038973858 -0.511665133251763 -0.1303247647671413 -1.971293303625048 -0.54798536363553
In [ ]:
In [ ]:
In [20]:
using Primes
In [21]:
factor(91345000599801)
3^3 ⋅ 13^3 ⋅ 6959 ⋅ 221281

In [1]:
using JuMP using Ipopt m = Model(with_optimizer(Ipopt.Optimizer, print_level=0)) @variable(m, 0 <= x <= 2 ) @variable(m, 0 <= y <= 30 ) @objective(m, Min, x*x - 3.3x*y + 2.9y*y ) @constraint(m, x + y >= 1 ) optimize!(m) println(termination_status(m)) println("| x = ", JuMP.value(x), "| y = ", JuMP.value(y))
****************************************************************************** This program contains Ipopt, a library for large-scale nonlinear optimization. Ipopt is released as open source code under the Eclipse Public License (EPL). For more information visit http://projects.coin-or.org/Ipopt ****************************************************************************** LOCALLY_SOLVED | x = 0.6319444693926528| y = 0.36805557060339394

In [23]:
using FileIO img = load("qiskit1.png") img
360×360 Array{RGBA{N0f8},2} with eltype ColorTypes.RGBA{FixedPointNumbers.Normed{UInt8,8}}: RGBA{N0f8}(1.0,1.0,1.0,1.0) … RGBA{N0f8}(1.0,1.0,1.0,1.0) RGBA{N0f8}(1.0,1.0,1.0,1.0) RGBA{N0f8}(1.0,1.0,1.0,1.0) RGBA{N0f8}(1.0,1.0,1.0,1.0) RGBA{N0f8}(1.0,1.0,1.0,1.0) RGBA{N0f8}(1.0,1.0,1.0,1.0) RGBA{N0f8}(1.0,1.0,1.0,1.0) RGBA{N0f8}(1.0,1.0,1.0,1.0) RGBA{N0f8}(1.0,1.0,1.0,1.0) RGBA{N0f8}(1.0,1.0,1.0,1.0) … RGBA{N0f8}(1.0,1.0,1.0,1.0) RGBA{N0f8}(1.0,1.0,1.0,1.0) RGBA{N0f8}(1.0,1.0,1.0,1.0) RGBA{N0f8}(1.0,1.0,1.0,1.0) RGBA{N0f8}(1.0,1.0,1.0,1.0) RGBA{N0f8}(1.0,1.0,1.0,1.0) RGBA{N0f8}(1.0,1.0,1.0,1.0) RGBA{N0f8}(1.0,1.0,1.0,1.0) RGBA{N0f8}(1.0,1.0,1.0,1.0) RGBA{N0f8}(1.0,1.0,1.0,1.0) … RGBA{N0f8}(1.0,1.0,1.0,1.0) RGBA{N0f8}(1.0,1.0,1.0,1.0) RGBA{N0f8}(1.0,1.0,1.0,1.0) RGBA{N0f8}(1.0,1.0,1.0,1.0) RGBA{N0f8}(1.0,1.0,1.0,1.0) ⋮ ⋱ RGBA{N0f8}(1.0,1.0,1.0,1.0) RGBA{N0f8}(1.0,1.0,1.0,1.0) RGBA{N0f8}(1.0,1.0,1.0,1.0) RGBA{N0f8}(1.0,1.0,1.0,1.0) RGBA{N0f8}(1.0,1.0,1.0,1.0) … RGBA{N0f8}(1.0,1.0,1.0,1.0) RGBA{N0f8}(1.0,1.0,1.0,1.0) RGBA{N0f8}(1.0,1.0,1.0,1.0) RGBA{N0f8}(1.0,1.0,1.0,1.0) RGBA{N0f8}(1.0,1.0,1.0,1.0) RGBA{N0f8}(1.0,1.0,1.0,1.0) RGBA{N0f8}(1.0,1.0,1.0,1.0) RGBA{N0f8}(1.0,1.0,1.0,1.0) RGBA{N0f8}(1.0,1.0,1.0,1.0) RGBA{N0f8}(1.0,1.0,1.0,1.0) … RGBA{N0f8}(1.0,1.0,1.0,1.0) RGBA{N0f8}(1.0,1.0,1.0,1.0) RGBA{N0f8}(1.0,1.0,1.0,1.0) RGBA{N0f8}(1.0,1.0,1.0,1.0) RGBA{N0f8}(1.0,1.0,1.0,1.0) RGBA{N0f8}(1.0,1.0,1.0,1.0) RGBA{N0f8}(1.0,1.0,1.0,1.0) RGBA{N0f8}(1.0,1.0,1.0,1.0) RGBA{N0f8}(1.0,1.0,1.0,1.0)
In [24]:
using ImageAxes
In [25]:
using Images
In [26]:
using Colors, ImageMetadata, Dates
In [39]:
using TestImages, Images img = testimage("mandrill")
In [40]:
using ImageAxes img = AxisArray(reshape(1:192, (8,8,3)), :x, :y, :z)
8×8×3 AxisArray{Int64,3,Base.ReshapedArray{Int64,3,UnitRange{Int64},Tuple{}},Tuple{Axis{:x,Base.OneTo{Int64}},Axis{:y,Base.OneTo{Int64}},Axis{:z,Base.OneTo{Int64}}}}: [:, :, 1] = 1 9 17 25 33 41 49 57 2 10 18 26 34 42 50 58 3 11 19 27 35 43 51 59 4 12 20 28 36 44 52 60 5 13 21 29 37 45 53 61 6 14 22 30 38 46 54 62 7 15 23 31 39 47 55 63 8 16 24 32 40 48 56 64 [:, :, 2] = 65 73 81 89 97 105 113 121 66 74 82 90 98 106 114 122 67 75 83 91 99 107 115 123 68 76 84 92 100 108 116 124 69 77 85 93 101 109 117 125 70 78 86 94 102 110 118 126 71 79 87 95 103 111 119 127 72 80 88 96 104 112 120 128 [:, :, 3] = 129 137 145 153 161 169 177 185 130 138 146 154 162 170 178 186 131 139 147 155 163 171 179 187 132 140 148 156 164 172 180 188 133 141 149 157 165 173 181 189 134 142 150 158 166 174 182 190 135 143 151 159 167 175 183 191 136 144 152 160 168 176 184 192

In [1]:
using Statistics
In [2]:
Statistics.median([8 9 8 6 87 6 7 6 5.1 4 5 4 3 4 3 3 3 3 ])
5.05
In [3]:
using LinearAlgebra
In [4]:
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 [5]:
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 [6]:
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 [1]:
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="--")
1-element Array{PyCall.PyObject,1}: PyObject <matplotlib.lines.Line2D object at 0x7ff70e88a9b0>
In [2]:
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 [3]:
using D4M
In [4]:
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)
Assoc(Union{AbstractString, Number}["a", "aa", "aaa", "b", "bb", "bbb"], Union{AbstractString, Number}["a", "aa", "aaa", "b", "bb", "bbb"], Union{AbstractString, Number}["a-a", "a-aa", "a-aaa", "a-b", "a-bb", "a-bbb", "aa-a", "aa-aa", "aaa-a", "aaa-aaa", "b-a", "b-b", "bb-a", "bb-bb", "bbb-a", "bbb-bbb"], [1, 1] = 1 [2, 1] = 7 [3, 1] = 9 [4, 1] = 11 [5, 1] = 13 [6, 1] = 15 [1, 2] = 2 [2, 2] = 8 [1, 3] = 3 [3, 3] = 10 [1, 4] = 4 [4, 4] = 12 [1, 5] = 5 [5, 5] = 14 [1, 6] = 6 [6, 6] = 16)
In [5]:
Ar = A["a,b,",:]
Assoc(Union{AbstractString, Number}["a", "b"], Union{AbstractString, Number}["a", "aa", "aaa", "b", "bb", "bbb"], Union{AbstractString, Number}["a-a", "a-aa", "a-aaa", "a-b", "a-bb", "a-bbb", "b-a", "b-b"], [1, 1] = 1 [2, 1] = 7 [1, 2] = 2 [1, 3] = 3 [1, 4] = 4 [2, 4] = 8 [1, 5] = 5 [1, 6] = 6)
In [6]:
Ac = A[:,"a,b,"]
Assoc(Union{AbstractString, Number}["a", "aa", "aaa", "b", "bb", "bbb"], Union{AbstractString, Number}["a", "b"], Union{AbstractString, Number}["a-a", "a-b", "aa-a", "aaa-a", "b-a", "b-b", "bb-a", "bbb-a"], [1, 1] = 1 [2, 1] = 3 [3, 1] = 4 [4, 1] = 5 [5, 1] = 7 [6, 1] = 8 [1, 2] = 2 [4, 2] = 6)
In [7]:
Av = A > "b,"
Assoc(Union{AbstractString, Number}["b", "bb", "bbb"], Union{AbstractString, Number}["a", "b", "bb", "bbb"], Union{AbstractString, Number}["b-a", "b-b", "bb-a", "bb-bb", "bbb-a", "bbb-bbb"], [1, 1] = 1 [2, 1] = 3 [3, 1] = 5 [1, 2] = 2 [2, 3] = 4 [3, 4] = 6)

SymPy test

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

Unicode Plots

In [2]:
using Plots unicodeplots()
Plots.UnicodePlotsBackend()
In [3]:
# /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))
+------------------------------------------------------------+ 1.0599669777078058 | _r--__ .__r--r-.__. ._---_ | | /` "-.. ._-/"` | ""\-_. ..-"` "\ | | |` '`. .r/` | '`.. .-` | | | | .^l. | ./{. | | | | ./` "`. | ./` "`. | | | . ./` "\. | ./` "`. . | | \. r` \. | ./` '. | | | \ / \. | ./ \. / | | ", ./ \. | ./ \. .` | | \v` \.L/ \.` | |""""=/T"""""""""""""""""""""=/@="""""""""""""""""""""]"|""""| | ./ ". ./ | \.. .` \. | | / ". ./ | \. .r` \ | | / \. .." | \. ./ . | | | ".. .r` | \.. .r` \ | | | '.. .-` | '.. .,` | | | | '_/` | '\r` | | | | .r" "\.. | ../` \.. .` | | \. _-/` ""-._. | ._.-"` "\-_. / | -1.0599669777078058 | '---"" """`--r-/""` ""--/" | +------------------------------------------------------------+ -1.0599669777078058 1.0599669777078058
In [ ]:
In [ ]:
In [ ]:
using Turing
In [4]:
using Random, Distributions
In [5]:
d = Normal(3, 1.5) d
Normal{Float64}(μ=3.0, σ=1.5)
In [6]:
x = rand(d, 100) x
100-element Array{Float64,1}: -0.9161188465737355 2.200555899887199 4.385151979363698 5.995361962595702 0.22495401862432018 3.004390808819782 2.8923837783781345 4.51295303013433 5.8723185000748686 2.952862597402599 5.477795578725095 2.769757309670423 0.7377312816972674 ⋮ 4.9293101246878 0.8721179115511903 0.6601663149684085 1.240751150750564 1.3700074977502932 3.324563779903772 5.245640068589239 3.075981374815773 2.6664863743689566 4.598112459483705 4.576644966306112 3.824907845582069
In [7]:
fit(Normal, x)
Normal{Float64}(μ=2.9532163336282196, σ=1.5645082278553348)
In [ ]: