Sharedjulia-1.1.ipynbOpen in CoCalc

# Julia 1.1 Kernel in CoCalc¶

1+1+1+1

4
VERSION

v"1.1.0"
ENV["JULIA_DEPOT_PATH"]

"/home/user/.julia/:/ext/julia/depot/"
ENV["JULIA_PROJECT"]

"/home/user/.julia/environment/v1.1"
# delete!(ENV, "JULIA_PROJECT")
using Pkg
for (k, v) in Pkg.installed()
println(k, ":::", (if nothing == v "N/A" else v end))
end

# 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

┌ 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:519
D4M=>0.1.0 Interact=>0.10.0 ImageMorphology=>0.1.1 ImageFiltering=>0.5.4 SymPy=>0.9.0 Compat=>2.1.0 ImageMagick=>0.7.1 Calculus=>0.4.1 Knet=>1.2.1 Cairo=>0.5.6 DataFrames=>0.17.1 Turing=>0.6.13 ImageDraw=>0.1.0 Primes=>0.4.0 LinearAlgebra=>N/A Plotly=>0.2.0 Combinatorics=>0.7.0 DiffEqFlux=>0.2.0 GraphPlot=>0.3.1 Gadfly=>1.0.1 FileIO=>1.0.5 Convex=>0.11.3 ImageAxes=>0.5.0 CSV=>0.4.3 ImageSegmentation=>1.1.0 Random=>N/A Optim=>0.18.1 StatsPlots=>0.10.2 ColorSchemes=>3.2.0 FFTViews=>0.2.0 Images=>0.17.3 IJulia=>1.18.0 Flux=>0.8.1 Plots=>0.23.2 PyPlot=>2.8.0 TestImages=>0.4.1 BlackBoxOptim=>0.4.0 DifferentialEquations=>6.3.0 UnicodePlots=>1.1.0 GLM=>1.1.1 Statistics=>N/A Fontconfig=>0.2.0 LightGraphs=>1.2.0 ImageFeatures=>0.2.0 JuMP=>0.19.0 Ipopt=>0.5.4 ImageMetadata=>0.6.1 Compose=>0.7.3 CoordinateTransformations=>0.5.0 Colors=>0.9.5 NLsolve=>3.0.1
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
[sin(3.14), sin(3.141), sin(3.142)]

3-element Array{Float64,1}: 0.0015926529164868282 0.0005926535550994539 -0.00040734639894142617
println("Hello", 99)
x = 10
println("Interpolation \$(5 + x)")
@printf("pi = %.7f\n", float(pi))

Hello99 Interpolation 15 pi = 3.1415927
Printf.@printf("%f %F %f %F\n", Inf, Inf, NaN, NaN)

Inf Inf NaN NaN
using CSV

using DataFrames

#using Gadfly





using LightGraphs
g = PathGraph(6)
g

{6, 5} undirected simple Int64 graph
nv(g)

6
import Fontconfig







using Random

randn(10)

10-element Array{Float64,1}: -0.23297800420305573 0.668227972599595 0.19324411893935067 -0.12016472359645843 0.8772729690167044 0.5939528977360506 -0.9534901793711894 0.4619022950316919 0.031439906901720195 0.42311472411633555






using Primes

factor(91345000599801)

3^3 ⋅ 13^3 ⋅ 6959 ⋅ 221281

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

using FileIO
img

360×360 Array{RGBA{N0f8},2} with eltype ColorTypes.RGBA{FixedPointNumbers.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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)
using ImageAxes

using Images

using Colors, ImageMetadata, Dates

using TestImages, Images
img = testimage("mandrill")

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

using Statistics

Statistics.median([8 9 8 6 87 6 7 6 5.1 4 5 4 3 4 3 3 3 3 ])

5.05
using LinearAlgebra

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
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

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)

┌ Info: Precompiling DifferentialEquations [0c46a032-eb83-5123-abaf-570d42b7fbaa] └ @ Base loading.jl:1186 WARNING: both DifferentialEquations and JuMP export "solve"; uses of it in module Main must be qualified
UndefVarError: solve not defined  Stacktrace:  [1] top-level scope at In[17]:10 
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)

UndefVarError: notime_squaremesh not defined  Stacktrace:  [1] top-level scope at In[5]:7 
using GLM


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 0x7fa6b8f8cd30>
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")