HSG-MCS-HS21_Julia/JuliaTutorial-master/Tutorial_01_Basics.ipynb
2021-11-15 21:14:51 +01:00

1072 lines
67 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{
"cells": [
{
"cell_type": "markdown",
"source": [
"# Basic Julia Tutorial"
],
"metadata": {
"collapsed": true
}
},
{
"cell_type": "markdown",
"source": [
"# Running/Installing Julia\n",
"\n",
"This is a notebook. To run in you need Julia and jupyter or nteract (see below).\n",
"\n",
"1. To run Julia without a local installation, use (for instance) [CoCalc](https://cocalc.com).\n",
"\n",
"2. To install Julia on your machine, [download and install it](https://julialang.org/downloads/). \n",
"\n",
"3. You may also want to use [VS Code with the Julia extension](https://github.com/julia-vscode/julia-vscode) IDE. See also the [julia-vscode.org](https://www.julia-vscode.org/) for more information.\n",
"\n",
"4. To run notebooks with either jupyter or nteract from your local installation, see [IJulia](https://github.com/JuliaLang/IJulia.jl) for instructions. See also below for some hints.\n",
"\n",
"5. As an alternative to jupyter/nteract you can also run notebooks in VS Code (see above).\n",
"\n",
"\n",
"\n",
"## More Details on Installing jupyter and nteract\n",
"\n",
"1. If you want to use nteract do as follows: install IJulia, but do *not* call on `notebook()` to avoid the automatic Python installation. Then install nteract.\n",
"\n",
"2. After installing IJulia and issuing the command `notebook()` a new local Python installation will be made - unless IJulia finds an existing installation.\n",
"\n",
"3. If you already have a Python installation, run `ENV[\"JUPYTER\"] = \"C:\\\\Miniconda3\\\\Scripts\\\\jupyter.exe\"` (change the path as needed) before you install IJulia. The best is perhaps to add this to your startup.jl file (~/.julia/config/startup.jl, for instance, C:\\Users\\yourusername\\.julia\\config\\startup.jl if you are on Windows). You can test whether it works by running ```run(`$(ENV[\"JUPYTER\"]) --version`)``` from the Julia REPL.\n",
"\n",
"4. On Windows, it helps to allow the Python installer to add python to the system path."
],
"metadata": {}
},
{
"cell_type": "markdown",
"source": [
"# Documentation and Help\n",
"\n",
"1. Cheat sheet at [QuantEcon](https://cheatsheets.quantecon.org/julia-cheatsheet.html)\n",
"2. [Wiki book](https://en.wikibooks.org/wiki/Introducing_Julia)\n",
"3. [Short tutorials](https://techytok.com/from-zero-to-julia/) \n",
"4. [ThinkJulia](https://benlauwens.github.io/ThinkJulia.jl/latest/book.html) is a free on-line book\n",
"5. The [official Julia on-line manual](https://docs.julialang.org)\n",
"6. Discussion lists are found at\n",
" * https://discourse.julialang.org/\n",
" * https://stackoverflow.com/questions/tagged/julia-lang\n",
" * https://www.reddit.com/r/Julia/\n",
" * https://gitter.im/JuliaLang/julia\n",
"7. In Julia, do ```? cos``` to get help with the cos function "
],
"metadata": {}
},
{
"cell_type": "markdown",
"source": [
"# About Notebooks\n",
"\n",
"This cell is a \"Markdown\" cell. This is meant for comments and documentation, not computations.\n",
"\n",
"You can change a cell to \"Code\" or \"Markdown\" in the menu.\n",
"\n",
"Markdown cells can handle LaTeX. An example: $\\alpha = \\beta/2$. A Markdown cell can also contain some *formatting*, like lists of this kind\n",
"\n",
"1. To insert a new cell, use the menu. \n",
"\n",
"2. The next cell is \"Code\". You can run it. Text after a # sign is treated as a comment.\n",
"\n",
"3. The subsequent cell shows how to get help on a command."
],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 29,
"source": [
"a = 2 #this is a comment\n",
" #run this cell by using the menu, or by Shift+Enter"
],
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"2"
]
},
"metadata": {},
"execution_count": 29
}
],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 30,
"source": [
"? cos #to get help on the cos() function"
],
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"search: \u001b[0m\u001b[1mc\u001b[22m\u001b[0m\u001b[1mo\u001b[22m\u001b[0m\u001b[1ms\u001b[22m \u001b[0m\u001b[1mc\u001b[22m\u001b[0m\u001b[1mo\u001b[22m\u001b[0m\u001b[1ms\u001b[22mh \u001b[0m\u001b[1mc\u001b[22m\u001b[0m\u001b[1mo\u001b[22m\u001b[0m\u001b[1ms\u001b[22md \u001b[0m\u001b[1mc\u001b[22m\u001b[0m\u001b[1mo\u001b[22m\u001b[0m\u001b[1ms\u001b[22mc \u001b[0m\u001b[1mc\u001b[22m\u001b[0m\u001b[1mo\u001b[22m\u001b[0m\u001b[1ms\u001b[22mpi a\u001b[0m\u001b[1mc\u001b[22m\u001b[0m\u001b[1mo\u001b[22m\u001b[0m\u001b[1ms\u001b[22m a\u001b[0m\u001b[1mc\u001b[22m\u001b[0m\u001b[1mo\u001b[22m\u001b[0m\u001b[1ms\u001b[22mh a\u001b[0m\u001b[1mc\u001b[22m\u001b[0m\u001b[1mo\u001b[22m\u001b[0m\u001b[1ms\u001b[22md sin\u001b[0m\u001b[1mc\u001b[22m\u001b[0m\u001b[1mo\u001b[22m\u001b[0m\u001b[1ms\u001b[22m sin\u001b[0m\u001b[1mc\u001b[22m\u001b[0m\u001b[1mo\u001b[22m\u001b[0m\u001b[1ms\u001b[22md sin\u001b[0m\u001b[1mc\u001b[22m\u001b[0m\u001b[1mo\u001b[22m\u001b[0m\u001b[1ms\u001b[22mpi \u001b[0m\u001b[1mc\u001b[22m\u001b[0m\u001b[1mo\u001b[22mn\u001b[0m\u001b[1ms\u001b[22mt\n",
"\n"
]
},
{
"output_type": "execute_result",
"data": {
"text/latex": [
"\\begin{verbatim}\n",
"cos(x)\n",
"\\end{verbatim}\n",
"Compute cosine of \\texttt{x}, where \\texttt{x} is in radians.\n",
"\n",
"See also [\\texttt{cosd}], [\\texttt{cospi}], [\\texttt{sincos}], [\\texttt{cis}].\n",
"\n",
"\\rule{\\textwidth}{1pt}\n",
"\\begin{verbatim}\n",
"cos(A::AbstractMatrix)\n",
"\\end{verbatim}\n",
"Compute the matrix cosine of a square matrix \\texttt{A}.\n",
"\n",
"If \\texttt{A} is symmetric or Hermitian, its eigendecomposition (\\href{@ref}{\\texttt{eigen}}) is used to compute the cosine. Otherwise, the cosine is determined by calling \\href{@ref}{\\texttt{exp}}.\n",
"\n",
"\\section{Examples}\n",
"\\begin{verbatim}\n",
"julia> cos(fill(1.0, (2,2)))\n",
"2×2 Matrix{Float64}:\n",
" 0.291927 -0.708073\n",
" -0.708073 0.291927\n",
"\\end{verbatim}\n"
],
"text/markdown": [
"```\n",
"cos(x)\n",
"```\n",
"\n",
"Compute cosine of `x`, where `x` is in radians.\n",
"\n",
"See also [`cosd`], [`cospi`], [`sincos`], [`cis`].\n",
"\n",
"---\n",
"\n",
"```\n",
"cos(A::AbstractMatrix)\n",
"```\n",
"\n",
"Compute the matrix cosine of a square matrix `A`.\n",
"\n",
"If `A` is symmetric or Hermitian, its eigendecomposition ([`eigen`](@ref)) is used to compute the cosine. Otherwise, the cosine is determined by calling [`exp`](@ref).\n",
"\n",
"# Examples\n",
"\n",
"```jldoctest\n",
"julia> cos(fill(1.0, (2,2)))\n",
"2×2 Matrix{Float64}:\n",
" 0.291927 -0.708073\n",
" -0.708073 0.291927\n",
"```\n"
],
"text/plain": [
"\u001b[36m cos(x)\u001b[39m\n",
"\n",
" Compute cosine of \u001b[36mx\u001b[39m, where \u001b[36mx\u001b[39m is in radians.\n",
"\n",
" See also [\u001b[36mcosd\u001b[39m], [\u001b[36mcospi\u001b[39m], [\u001b[36msincos\u001b[39m], [\u001b[36mcis\u001b[39m].\n",
"\n",
" ────────────────────────────────────────────────────────────────────────────\n",
"\n",
"\u001b[36m cos(A::AbstractMatrix)\u001b[39m\n",
"\n",
" Compute the matrix cosine of a square matrix \u001b[36mA\u001b[39m.\n",
"\n",
" If \u001b[36mA\u001b[39m is symmetric or Hermitian, its eigendecomposition (\u001b[36meigen\u001b[39m) is used to\n",
" compute the cosine. Otherwise, the cosine is determined by calling \u001b[36mexp\u001b[39m.\n",
"\n",
"\u001b[1m Examples\u001b[22m\n",
"\u001b[1m ≡≡≡≡≡≡≡≡≡≡\u001b[22m\n",
"\n",
"\u001b[36m julia> cos(fill(1.0, (2,2)))\u001b[39m\n",
"\u001b[36m 2×2 Matrix{Float64}:\u001b[39m\n",
"\u001b[36m 0.291927 -0.708073\u001b[39m\n",
"\u001b[36m -0.708073 0.291927\u001b[39m"
]
},
"metadata": {},
"execution_count": 30
}
],
"metadata": {}
},
{
"cell_type": "markdown",
"source": [
"# Load Packages and Extra Functions\n",
"\n",
"There are many packages for Julia, for instance, for plotting or statistical methods (see [JuliaHub](https://juliahub.com/) for a list). To install a package, you do either \n",
"\n",
"1. (works everywhere) run `import Pkg` and then `Pkg.add(\"Packagename\")`\n",
"\n",
"2. (works in the Julia console, REPL) enter the \"package manager mode\" by typing `]`, then run `add PackageName`. You leave the package manager mode by ctrl-c or backspace.\n",
"\n",
"Once a package is installed, you can use it by running\n",
"\n",
"```\n",
"using PackageName\n",
"```"
],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 31,
"source": [
"using Printf\n",
"\n",
"include(\"jlFiles/printmat.jl\") #just a function for prettier matrix printing"
],
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"printyellow (generic function with 1 method)"
]
},
"metadata": {},
"execution_count": 31
}
],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 32,
"source": [
"using Plots #this loads the Plots package\n",
"\n",
"#pyplot(size=(600,400)) #choice of plotting backend\n",
"gr(size=(480,320))\n",
"default(fmt = :svg) #try :png or :svg"
],
"outputs": [],
"metadata": {}
},
{
"cell_type": "markdown",
"source": [
"# Scalars and Matrices\n",
"\n"
],
"metadata": {}
},
{
"cell_type": "markdown",
"source": [
"### Create a Scalar and a Matrix"
],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 33,
"source": [
"q = 1 #create a scalar\n",
"Q = [ 1 2 3; #create 2x3 matrix\n",
" 4 5 6 ] \n",
"println(\"q is a scalar. To print, use println() or printlnPs()\")\n",
"println(q)\n",
"\n",
"println(\"\\nQ is a matrix. To print, use display() or printmat()\")\n",
"printmat(Q) #case sensitive (q and Q are different)\n",
" #the \\n adds a line break"
],
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"q is a scalar. To print, use println() or printlnPs()\n",
"1\n",
"\n",
"Q is a matrix. To print, use display() or printmat()\n",
" 1 2 3 \n",
" 4 5 6 \n",
"\n"
]
}
],
"metadata": {}
},
{
"cell_type": "markdown",
"source": [
"### Picking Out Parts of a Matrix"
],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 34,
"source": [
"println(\"\\n\",\"element [1,2] of Q: \", #commands continue on\n",
" Q[1,2]) #the next line (until finished)\n",
"\n",
"println(\"\\ncolumns 2 and 3 of Q: \")\n",
"printmat(Q[:,2:3])\n",
"\n",
"println(\"\\nline 1 of Q (as a vector): \")\n",
"printmat(Q[1,:])"
],
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"\n",
"element [1,2] of Q: 2\n",
"\n",
"columns 2 and 3 of Q: \n",
" 2 3 \n",
" 5 6 \n",
"\n",
"\n",
"line 1 of Q (as a vector): \n",
" 1 \n",
" 2 \n",
" 3 \n",
"\n"
]
}
],
"metadata": {}
},
{
"cell_type": "markdown",
"source": [
"### Basic Linear Algebra\n",
"\n",
"The syntax for linear algebra is similar to the standard text book approach. For instance, \n",
"* `Q'Q` (or `Q'*Q`) multiplies the transpose ($Q'$) with the matrix ($Q$)\n",
"* `A*B` does matrix multiplication\n",
"* `100*Q` multiplies each element of the matrix ($Q$) by 100. (You can also do `100Q`.)\n",
"\n",
"However, to add a scalar to each element of a matrix, use `100 .+ Q`. Notice the dot."
],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 35,
"source": [
"println(\"transpose of Q:\")\n",
"printmat(Q')\n",
"\n",
"println(\"Q'Q:\")\n",
"printmat(Q'Q)\n",
"\n",
"println(\"scalar * matrix:\")\n",
"printmat(100*Q)\n",
"\n",
"println(\"scalar .+ matrix:\") #notice the dot\n",
"printmat(100 .+ Q)"
],
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"transpose of Q:\n",
" 1 4 \n",
" 2 5 \n",
" 3 6 \n",
"\n",
"Q'Q:\n",
" 17 22 27 \n",
" 22 29 36 \n",
" 27 36 45 \n",
"\n",
"scalar * matrix:\n",
" 100 200 300 \n",
" 400 500 600 \n",
"\n",
"scalar .+ matrix:\n",
" 101 102 103 \n",
" 104 105 106 \n",
"\n"
]
}
],
"metadata": {}
},
{
"cell_type": "markdown",
"source": [
"### Creating a Sequence and a Vector"
],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 36,
"source": [
"θ = 1:10:21 #a range, type \\theta[TAB] to get this symbol\n",
"println(\"\\n\",\"θ is a sequence: \",θ)\n",
"\n",
"ρ = collect(θ) #make the sequence into a vector, \\rho[TAB]\n",
"println(\"\\n\",\"ρ is a vector: \")\n",
"printmat(ρ)"
],
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"\n",
"θ is a sequence: 1:10:21\n",
"\n",
"ρ is a vector: \n",
" 1 \n",
" 11 \n",
" 21 \n",
"\n"
]
}
],
"metadata": {}
},
{
"cell_type": "markdown",
"source": [
"# Comparing Things\n",
"\n",
"To see if the scalar z <= 0, do \n",
"```\n",
"vv = z <= 0\n",
"```\n",
"to get a single output (true or false).\n",
"\n",
"Instead, if x is an array, do \n",
"```\n",
"vv = x .<= 0 #notice the dot.\n",
"```\n",
"to get an array of outputs (same dimension as x)"
],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 37,
"source": [
"x = [-1.5,-1.0,-0.5,0,0.5] #this is a vector\n",
"\n",
"println(\"x values: \")\n",
"printmat(x)\n",
"\n",
"vv = -1 .< x .<= 0 #true for x values (-1,0], vv is a vector\n",
"println(\"true if x is in (-1,0]: \")\n",
"printmat(vv)\n",
"\n",
"x2 = x[vv] #x values for which vv==true\n",
"println(\"x values that are in (-1,0]: \")\n",
"printmat(x2)"
],
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"x values: \n",
" -1.500\n",
" -1.000\n",
" -0.500\n",
" 0.000\n",
" 0.500\n",
"\n",
"true if x is in (-1,0]: \n",
" 0 \n",
" 0 \n",
" 1 \n",
" 1 \n",
" 0 \n",
"\n",
"x values that are in (-1,0]: \n",
" -0.500\n",
" 0.000\n",
"\n"
]
}
],
"metadata": {}
},
{
"cell_type": "markdown",
"source": [
"# Finding Things\n",
"\n",
"can be done by, for instance, `findfirst()`, `findall()` and `indexin()`. \n",
"\n",
"Instead, if you just need to check if the number `z` is in an array (or any collection) `x`, then use `in(z,x)`."
],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 38,
"source": [
"x = [-1.5,-1.0,-0.5,0,0.5] #this is a vector\n",
"\n",
"println(\"x values: \")\n",
"printmat(x)\n",
"\n",
"v1 = findfirst(x.==0)\n",
"println(\"(first) index v in x such x[v]==0: \",v1)\n",
"\n",
"v2 = findall(x.>=0)\n",
"println(\"\\nall indices v in x such x[v]>=0: \")\n",
"printmat(v2)\n",
"\n",
"y = [-1.0,0]\n",
"v3 = indexin(y,x)\n",
"println(\"\\nindices in x so that x[v] equals the vector y=$y: \")\n",
"printmat(v3)\n",
"\n",
"v4 = in(0,x)\n",
"println(\"\\ntesting if 0 is in x: \",v4)"
],
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"x values: \n",
" -1.500\n",
" -1.000\n",
" -0.500\n",
" 0.000\n",
" 0.500\n",
"\n",
"(first) index v in x such x[v]==0: 4\n",
"\n",
"all indices v in x such x[v]>=0: \n",
" 4 \n",
" 5 \n",
"\n",
"\n",
"indices in x so that x[v] equals the vector y=[-1.0, 0.0]: \n",
" 2 \n",
" 4 \n",
"\n",
"\n",
"testing if 0 is in x: true\n"
]
}
],
"metadata": {}
},
{
"cell_type": "markdown",
"source": [
"# if-else\n",
"\n",
"allows you to run different comman ddepending on a condition which you specify.\n",
"\n",
"(extra) There are also other (more compact) possibilities for `if-else` case\n",
"\n",
"1. `y = ifelse(z <= 2,z,2)` or \n",
"2. `z <= 2 ? y = z : y = 2`\n",
"(In this partcular case, `y=minimum(z,2)` also works.)\n",
"\n",
"You can also insert an `ifelse` command."
],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 39,
"source": [
"z = 1.05\n",
"\n",
"if z <= 2 #(a) if true, run the next command (y=z) and then jump to end\n",
" y = z\n",
"else #(b) if (a) is false, do this instead\n",
" y = 2\n",
"end\n",
"\n",
"#y = ifelse(z <= 2,z,2) #these two versions also work\n",
"#z <= 2 ? y = z : y = 2\n",
"\n",
"println(y)"
],
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"1.05\n"
]
}
],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 40,
"source": [
"if z < 1 #(a) if true, run the next command (y=1) and then jump to end\n",
" y = 1\n",
"elseif 1 <= z <= 2 #(b) if (a) is false, try this instead \n",
" y = z\n",
"else #(c) if also (b) is false, do this\n",
" y = 2\n",
"end\n",
"\n",
"println(y)"
],
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"1.05\n"
]
}
],
"metadata": {}
},
{
"cell_type": "markdown",
"source": [
"# Loops\n",
"\n",
"The are two types of loops: \"for loops\" and \"while loops\". \n",
"\n",
"The *for loop* is best when you know how many times you want to loop (for instance, over all $m$ rows in a matrix). \n",
"\n",
"The *while loop* is best when you want to keep looping until something happens, for instance, that $x_0$ and $x_1$ get really close.\n",
"\n",
"The default behaviour in *IJulia*, *inside functions* and at the *REPL* promt is that assignments of `x` inside the loop overwrites `x` defined before the loop. To get the same behavior in scripts, you need to add `global x` somewhere inside the loop.\n",
"\n",
"To make sure that the `y` calculated inside the loop does not affect `y` outside the loop, add `local y`.\n",
"\n",
"A variable (here `z2`) that does not exist before the loop is local to the loop."
],
"metadata": {}
},
{
"cell_type": "markdown",
"source": [
"### A Simple \"for loop\"\n",
"\n",
"The \"for loop\" in the next cell makes 3 iterations and changes a global $x$ variable."
],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 41,
"source": [
"x = 0\n",
"y = -999\n",
"for i = 3:3:9 #or `i in 3:3:9`, or `v=[3,6,9]; i in v`\n",
" #global x #only needed in script\n",
" local y #don't overwrite y outside loop\n",
" x = x + i #adding i to the \"old\" x\n",
" y = i\n",
" z2 = -998 #notice: z2 has not been used before \n",
" println(\"i=$i, x=$x and z2=$z2\") #$x prints the value of x\n",
"end\n",
"\n",
"println(\"\\nAfter loop: x=$x and y=$y\")\n",
"#println(z2) #does not work: z2 is local to the loop"
],
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"i=3, x=3 and z2=-998\n",
"i=6, x=9 and z2=-998\n",
"i=9, x=18 and z2=-998\n",
"\n",
"After loop: x=18 and y=-999\n"
]
}
],
"metadata": {}
},
{
"cell_type": "markdown",
"source": [
"### A Double \"for loop\"\n",
"\n",
"An example of a nested for for loop\n",
"\n",
"```\n",
"for j = 1:n, i = 1:m\n",
" #do something\n",
"end\n",
"```\n",
"\n",
"If you prefer, could also write a longer version to do the same thing\n",
"```\n",
"for j = 1:n \n",
" for i = 1:m\n",
" #do something\n",
" end \n",
"end\n",
"```\n",
"\n",
"The next cell uses a double loop to fill a matrix. "
],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 42,
"source": [
"(m,n) = (4,3) #same as m=4;n=3\n",
"x = fill(-999,(m,n)) #to put results in, initialized as -999\n",
"for i = 1:m, j = 1:n\n",
" x[i,j] = 10*i + j\n",
"end\n",
"\n",
"println(\"new x matrix: \\n\")\n",
"printmat(x)"
],
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"new x matrix: \n",
"\n",
" 11 12 13 \n",
" 21 22 23 \n",
" 31 32 33 \n",
" 41 42 43 \n",
"\n"
]
}
],
"metadata": {}
},
{
"cell_type": "markdown",
"source": [
"## A Simple \"while loop\"\n",
"\n",
"The \"while loop\" in the next cell iterates until two variables ($x_0$ and $x_1$) get close.\n",
"\n",
"The background to the example is that we want to solve a function $f(x)=x^2$ for the $x$ value that makes $f(x)=2$. The Newton-Raphson algorithm starts with a value $x_0$ and updates it to\n",
"$\n",
"x_1 = x_0 + (2-f(x_0))/f'(x_0)\n",
"$\n",
"where $f'(x_0)$ is the derivative of $f()$ evaluated at $x_0$. The algorithm iterates until $x_0$ and $x_1$ are close. Clearly, we are trying to find the square root of 2."
],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 43,
"source": [
"println(\"Solving x^2 = 2 with Newton-Raphson:\\n\")\n",
"\n",
"x₀ = Inf #x\\_0[TAB]\n",
"x₁ = 10\n",
"\n",
"while abs(x₁-x₀) > 0.001 #keep going until they get similar\n",
" #global x₀, x₁ #only needed in script\n",
" local y, dy #don't overwrite any y,dy outside loop\n",
" x₀ = x₁ #initial guess is taken from old guess\n",
" y = x₀^2 #value of function\n",
" dy = 2*x₀ #derivative of function\n",
" x₁ = x₀ + (2 - y)/dy #updating the guess, Newton-Raphson\n",
" printlnPs(x₀,\" is changed to \",x₁)\n",
"end\n",
"\n",
"printlnPs(\"\\nThe result should be close to \",sqrt(2))"
],
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Solving x^2 = 2 with Newton-Raphson:\n",
"\n",
" 10 is changed to 5.100\n",
" 5.100 is changed to 2.746\n",
" 2.746 is changed to 1.737\n",
" 1.737 is changed to 1.444\n",
" 1.444 is changed to 1.415\n",
" 1.415 is changed to 1.414\n",
"\n",
"The result should be close to 1.414\n"
]
}
],
"metadata": {}
},
{
"cell_type": "markdown",
"source": [
"# A Simple Function\n",
"\n",
"The next cell defines a new function, `fn1()`. It takes a scalar input (`x`) and returns a scalar output (`y`).\n",
"\n",
"If you instead use a vector as the input, then the computation fails. (The reason is that you cannot do x^2 on a vector. You could on a square matrix, though.)\n",
"\n",
"However, using the \"dot\" syntax\n",
"```\n",
"y = fn1.(x)\n",
"```\n",
"gives an array as output where element `y[i,j] = fn1(x[i,j])`."
],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 44,
"source": [
"function fn1(x) #define a new function \n",
" y = (x-1.1)^2 - 0.5\n",
" return y\n",
"end"
],
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"fn1 (generic function with 1 method)"
]
},
"metadata": {},
"execution_count": 44
}
],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 45,
"source": [
"y = fn1(1.5)\n",
"printlnPs(\"result from fn1(1.5): \",y)\n",
"\n",
"x = [1;1.5]\n",
"#y = fn1(x) #would give an error \n",
"y = fn1.(x) #calling on the function, dot. to do for each element in x\n",
"printlnPs(\"\\nresult from fn1.(x): \")\n",
"printmat(y)"
],
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"result from fn1(1.5): -0.340\n",
"\n",
"result from fn1.(x): \n",
" -0.490\n",
" -0.340\n",
"\n"
]
}
],
"metadata": {}
},
{
"cell_type": "markdown",
"source": [
"# A First Plot\n",
"\n",
"With the Plots package you create a a simple plot like this:\n",
"\n",
"1. Plot two curve by using the `plot([x1 x2],[y1 y2])` command\n",
"2. Configure curves by `linecolor =`, `linestyle =` etc\n",
"2. Add titles and labels by `title = `, `xlabel = `, etc\n",
"\n",
"Notice: the *first plot is slow*."
],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 46,
"source": [
"x = -3:6/99:6 \n",
"\n",
"p1 = plot( [x x],[fn1.(x) cos.(x)],\n",
" linecolor = [:red :blue],\n",
" linestyle = [:solid :dash],\n",
" linewidth = [2 1],\n",
" label = [\"fn1()\" \"cos\"],\n",
" title = \"My Results\",\n",
" xlabel = \"x\",\n",
" ylabel = \"my output value\" )\n",
"\n",
"#display(p1) #not needed in notebook, but useful in script"
],
"outputs": [
{
"output_type": "execute_result",
"data": {
"image/svg+xml": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"480\" height=\"320\" viewBox=\"0 0 1920 1280\">\n<defs>\n <clipPath id=\"clip210\">\n <rect x=\"0\" y=\"0\" width=\"1920\" height=\"1280\"/>\n </clipPath>\n</defs>\n<path clip-path=\"url(#clip210)\" d=\"\nM0 1280 L1920 1280 L1920 0 L0 0 Z\n \" fill=\"#ffffff\" fill-rule=\"evenodd\" fill-opacity=\"1\"/>\n<defs>\n <clipPath id=\"clip211\">\n <rect x=\"384\" y=\"0\" width=\"1345\" height=\"1280\"/>\n </clipPath>\n</defs>\n<path clip-path=\"url(#clip210)\" d=\"\nM199.164 1106.38 L1872.76 1106.38 L1872.76 123.472 L199.164 123.472 Z\n \" fill=\"#ffffff\" fill-rule=\"evenodd\" fill-opacity=\"1\"/>\n<defs>\n <clipPath id=\"clip212\">\n <rect x=\"199\" y=\"123\" width=\"1675\" height=\"984\"/>\n </clipPath>\n</defs>\n<polyline clip-path=\"url(#clip212)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n 422.551,1106.38 422.551,123.472 \n \"/>\n<polyline clip-path=\"url(#clip212)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n 774.594,1106.38 774.594,123.472 \n \"/>\n<polyline clip-path=\"url(#clip212)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n 1126.64,1106.38 1126.64,123.472 \n \"/>\n<polyline clip-path=\"url(#clip212)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n 1478.68,1106.38 1478.68,123.472 \n \"/>\n<polyline clip-path=\"url(#clip212)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n 1830.72,1106.38 1830.72,123.472 \n \"/>\n<polyline clip-path=\"url(#clip210)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n 199.164,1106.38 1872.76,1106.38 \n \"/>\n<polyline clip-path=\"url(#clip210)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n 422.551,1106.38 422.551,1087.48 \n \"/>\n<polyline clip-path=\"url(#clip210)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n 774.594,1106.38 774.594,1087.48 \n \"/>\n<polyline clip-path=\"url(#clip210)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n 1126.64,1106.38 1126.64,1087.48 \n \"/>\n<polyline clip-path=\"url(#clip210)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n 1478.68,1106.38 1478.68,1087.48 \n \"/>\n<polyline clip-path=\"url(#clip210)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n 1830.72,1106.38 1830.72,1087.48 \n \"/>\n<path clip-path=\"url(#clip210)\" d=\"M392.493 1146.38 L422.169 1146.38 L422.169 1150.32 L392.493 1150.32 L392.493 1146.38 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip210)\" d=\"M436.289 1159.28 L452.609 1159.28 L452.609 1163.21 L430.664 1163.21 L430.664 1159.28 Q433.326 1156.52 437.91 1151.89 Q442.516 1147.24 443.697 1145.9 Q445.942 1143.37 446.822 1141.64 Q447.725 1139.88 447.725 1138.19 Q447.725 1135.43 445.78 1133.7 Q443.859 1131.96 440.757 1131.96 Q438.558 1131.96 436.104 1132.73 Q433.674 1133.49 430.896 1135.04 L430.896 1130.32 Q433.72 1129.18 436.174 1128.61 Q438.627 1128.03 440.664 1128.03 Q446.035 1128.03 449.229 1130.71 Q452.424 1133.4 452.424 1137.89 Q452.424 1140.02 451.613 1141.94 Q450.826 1143.84 448.72 1146.43 Q448.141 1147.1 445.039 1150.32 Q441.937 1153.51 436.289 1159.28 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip210)\" d=\"M774.594 1131.73 Q770.983 1131.73 769.155 1135.3 Q767.349 1138.84 767.349 1145.97 Q767.349 1153.07 769.155 1156.64 Q770.983 1160.18 774.594 1160.18 Q778.229 1160.18 780.034 1156.64 Q781.863 1153.07 781.863 1145.97 Q781.863 1138.84 780.034 1135.3 Q778.229 1131.73 774.594 1131.73 M774.594 1128.03 Q780.404 1128.03 783.46 1132.63 Q786.539 1137.22 786.539 1145.97 Q786.539 1154.69 783.46 1159.3 Q780.404 1163.88 774.594 1163.88 Q768.784 1163.88 765.705 1159.3 Q762.65 1154.69 762.65 1145.97 Q762.65 1137.22 765.705 1132.63 Q768.784 1128.03 774.594 1128.03 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip210)\" d=\"M1121.29 1159.28 L1137.61 1159.28 L1137.61 1163.21 L1115.67 1163.21 L1115.67 1159.28 Q1118.33 1156.52 1122.91 1151.89 Q1127.52 1147.24 1128.7 1145.9 Q1130.94 1143.37 1131.82 1141.64 Q1132.73 1139.88 1132.73 1138.19 Q1132.73 1135.43 1130.78 1133.7 Q1128.86 1131.96 1125.76 1131.96 Q1123.56 1131.96 1121.11 1132.73 Q1118.67 1133.49 1115.9 1135.04 L1115.9 1130.32 Q1118.72 1129.18 1121.17 1128.61 Q1123.63 1128.03 1125.67 1128.03 Q1131.04 1128.03 1134.23 1130.71 Q1137.42 1133.4 1137.42 1137.89 Q1137.42 1140.02 1136.61 1141.94 Q1135.83 1143.84 1133.72 1146.43 Q1133.14 1147.1 1130.04 1150.32 Q1126.94 1153.51 1121.29 1159.28 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip210)\" d=\"M1481.69 1132.73 L1469.88 1151.17 L1481.69 1151.17 L1481.69 1132.73 M1480.46 1128.65 L1486.34 1128.65 L1486.34 1151.17 L1491.27 1151.17 L1491.27 1155.06 L1486.34 1155.06 L1486.34 1163.21 L1481.69 1163.21 L1481.69 1155.06 L1466.09 1155.06 L1466.09 1150.55 L1480.46 1128.65 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip210)\" d=\"M1831.13 1144.07 Q1827.98 1144.07 1826.13 1146.22 Q1824.3 1148.37 1824.3 1152.12 Q1824.3 1155.85 1826.13 1158.03 Q1827.98 1160.18 1831.13 1160.18 Q1834.28 1160.18 1836.11 1158.03 Q1837.96 1155.85 1837.96 1152.12 Q1837.96 1148.37 1836.11 1146.22 Q1834.28 1144.07 1831.13 1144.07 M1840.41 1129.42 L1840.41 1133.67 Q1838.65 1132.84 1836.85 1132.4 Q1835.06 1131.96 1833.31 1131.96 Q1828.68 1131.96 1826.22 1135.09 Q1823.79 1138.21 1823.44 1144.53 Q1824.81 1142.52 1826.87 1141.45 Q1828.93 1140.36 1831.41 1140.36 Q1836.62 1140.36 1839.62 1143.54 Q1842.66 1146.68 1842.66 1152.12 Q1842.66 1157.45 1839.51 1160.67 Q1836.36 1163.88 1831.13 1163.88 Q1825.13 1163.88 1821.96 1159.3 Q1818.79 1154.69 1818.79 1145.97 Q1818.79 1137.77 1822.68 1132.91 Q1826.57 1128.03 1833.12 1128.03 Q1834.88 1128.03 1836.66 1128.37 Q1838.47 1128.72 1840.41 1129.42 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip210)\" d=\"M1052.57 1208.4 L1039.68 1225.74 L1053.24 1244.04 L1046.34 1244.04 L1035.96 1230.04 L1025.58 1244.04 L1018.68 1244.04 L1032.52 1225.39 L1019.85 1208.4 L1026.76 1208.4 L1036.21 1221.1 L1045.67 1208.4 L1052.57 1208.4 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><polyline clip-path=\"url(#clip212)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n 199.164,1040.27 1872.76,1040.27 \n \"/>\n<polyline clip-path=\"url(#clip212)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n 199.164,848.798 1872.76,848.798 \n \"/>\n<polyline clip-path=\"url(#clip212)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n 199.164,657.322 1872.76,657.322 \n \"/>\n<polyline clip-path=\"url(#clip212)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n 199.164,465.846 1872.76,465.846 \n \"/>\n<polyline clip-path=\"url(#clip212)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n 199.164,274.369 1872.76,274.369 \n \"/>\n<polyline clip-path=\"url(#clip210)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n 199.164,1106.38 199.164,123.472 \n \"/>\n<polyline clip-path=\"url(#clip210)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n 199.164,1040.27 218.061,1040.27 \n \"/>\n<polyline clip-path=\"url(#clip210)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n 199.164,848.798 218.061,848.798 \n \"/>\n<polyline clip-path=\"url(#clip210)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n 199.164,657.322 218.061,657.322 \n \"/>\n<polyline clip-path=\"url(#clip210)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n 199.164,465.846 218.061,465.846 \n \"/>\n<polyline clip-path=\"url(#clip210)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n 199.164,274.369 218.061,274.369 \n \"/>\n<path clip-path=\"url(#clip210)\" d=\"M158.419 1026.07 Q154.808 1026.07 152.979 1029.64 Q151.174 1033.18 151.174 1040.31 Q151.174 1047.42 152.979 1050.98 Q154.808 1054.52 158.419 1054.52 Q162.053 1054.52 163.859 1050.98 Q165.688 1047.42 165.688 1040.31 Q165.688 1033.18 163.859 1029.64 Q162.053 1026.07 158.419 1026.07 M158.419 1022.37 Q164.229 1022.37 167.285 1026.98 Q170.364 1031.56 170.364 1040.31 Q170.364 1049.04 167.285 1053.64 Q164.229 1058.23 158.419 1058.23 Q152.609 1058.23 149.53 1053.64 Q146.475 1049.04 146.475 1040.31 Q146.475 1031.56 149.53 1026.98 Q152.609 1022.37 158.419 1022.37 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip210)\" d=\"M149.461 831.518 L167.817 831.518 L167.817 835.453 L153.743 835.453 L153.743 843.925 Q154.762 843.578 155.78 843.416 Q156.799 843.231 157.817 843.231 Q163.604 843.231 166.984 846.402 Q170.364 849.574 170.364 854.99 Q170.364 860.569 166.891 863.671 Q163.419 866.749 157.1 866.749 Q154.924 866.749 152.655 866.379 Q150.41 866.009 148.003 865.268 L148.003 860.569 Q150.086 861.703 152.308 862.259 Q154.53 862.814 157.007 862.814 Q161.012 862.814 163.35 860.708 Q165.688 858.601 165.688 854.99 Q165.688 851.379 163.35 849.273 Q161.012 847.166 157.007 847.166 Q155.132 847.166 153.257 847.583 Q151.405 848 149.461 848.879 L149.461 831.518 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip210)\" d=\"M119.068 670.667 L126.706 670.667 L126.706 644.301 L118.396 645.968 L118.396 641.708 L126.66 640.042 L131.336 640.042 L131.336 670.667 L138.975 670.667 L138.975 674.602 L119.068 674.602 L119.068 670.667 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip210)\" d=\"M158.419 643.121 Q154.808 643.121 152.979 646.685 Q151.174 650.227 151.174 657.357 Q151.174 664.463 152.979 668.028 Q154.808 671.569 158.419 671.569 Q162.053 671.569 163.859 668.028 Q165.688 664.463 165.688 657.357 Q165.688 650.227 163.859 646.685 Q162.053 643.121 158.419 643.121 M158.419 639.417 Q164.229 639.417 167.285 644.023 Q170.364 648.607 170.364 657.357 Q170.364 666.083 167.285 670.69 Q164.229 675.273 158.419 675.273 Q152.609 675.273 149.53 670.69 Q146.475 666.083 146.475 657.357 Q146.475 648.607 149.53 644.023 Q152.609 639.417 158.419 639.417 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip210)\" d=\"M120.063 479.19 L127.702 479.19 L127.702 452.825 L119.392 454.491 L119.392 450.232 L127.655 448.566 L132.331 448.566 L132.331 479.19 L139.97 479.19 L139.97 483.126 L120.063 483.126 L120.063 479.19 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip210)\" d=\"M149.461 448.566 L167.817 448.566 L167.817 452.501 L153.743 452.501 L153.743 460.973 Q154.762 460.626 155.78 460.464 Q156.799 460.278 157.817 460.278 Q163.604 460.278 166.984 463.45 Q170.364 466.621 170.364 472.038 Q170.364 477.616 166.891 480.718 Q163.419 483.797 157.1 483.797 Q154.924 483.797 152.655 483.426 Q150.41 483.056 148.003 482.315 L148.003 477.616 Q150.086 478.751 152.308 479.306 Q154.53 479.862 157.007 479.862 Q161.012 479.862 163.35 477.755 Q165.688 475.649 165.688 472.038 Q165.688 468.427 163.35 466.32 Q161.012 464.214 157.007 464.214 Q155.132 464.214 153.257 464.63 Q151.405 465.047 149.461 465.927 L149.461 448.566 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip210)\" d=\"M122.285 287.714 L138.604 287.714 L138.604 291.649 L116.66 291.649 L116.66 287.714 Q119.322 284.959 123.905 280.33 Q128.512 275.677 129.692 274.335 Q131.938 271.811 132.817 270.075 Q133.72 268.316 133.72 266.626 Q133.72 263.872 131.776 262.136 Q129.855 260.399 126.753 260.399 Q124.554 260.399 122.1 261.163 Q119.669 261.927 116.892 263.478 L116.892 258.756 Q119.716 257.622 122.169 257.043 Q124.623 256.464 126.66 256.464 Q132.03 256.464 135.225 259.149 Q138.419 261.835 138.419 266.325 Q138.419 268.455 137.609 270.376 Q136.822 272.274 134.716 274.867 Q134.137 275.538 131.035 278.756 Q127.933 281.95 122.285 287.714 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip210)\" d=\"M158.419 260.168 Q154.808 260.168 152.979 263.733 Q151.174 267.274 151.174 274.404 Q151.174 281.51 152.979 285.075 Q154.808 288.617 158.419 288.617 Q162.053 288.617 163.859 285.075 Q165.688 281.51 165.688 274.404 Q165.688 267.274 163.859 263.733 Q162.053 260.168 158.419 260.168 M158.419 256.464 Q164.229 256.464 167.285 261.071 Q170.364 265.654 170.364 274.404 Q170.364 283.131 167.285 287.737 Q164.229 292.321 158.419 292.321 Q152.609 292.321 149.53 287.737 Q146.475 283.131 146.475 274.404 Q146.475 265.654 149.53 261.071 Q152.609 256.464 158.419 256.464 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip210)\" d=\"M44.7993 850.537 Q40.8526 848.341 38.9747 845.285 Q37.0968 842.229 37.0968 838.092 Q37.0968 832.522 41.0117 829.498 Q44.8948 826.474 52.0881 826.474 L73.6042 826.474 L73.6042 832.363 L52.279 832.363 Q47.1546 832.363 44.672 834.177 Q42.1894 835.991 42.1894 839.715 Q42.1894 844.266 45.2131 846.908 Q48.2368 849.55 53.4567 849.55 L73.6042 849.55 L73.6042 855.438 L52.279 855.438 Q47.1228 855.438 44.672 857.253 Q42.1894 859.067 42.1894 862.854 Q42.1894 867.342 45.2449 869.984 Q48.2686 872.626 53.4567 872.626 L73.6042 872.626 L73.6042 878.514 L37.9562 878.514 L37.9562 872.626 L43.4944 872.626 Q40.216 870.621 38.6564 867.82 Q37.0968 865.019 37.0968 861.167 Q37.0968 857.284 39.0702 854.579 Q41.0436 851.842 44.7993 850.537 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip210)\" d=\"M76.9143 799.961 Q83.28 802.444 85.2216 804.799 Q87.1631 807.154 87.1631 811.101 L87.1631 815.78 L82.2615 815.78 L82.2615 812.342 Q82.2615 809.923 81.1157 808.587 Q79.9699 807.25 75.7048 805.627 L73.0312 804.576 L37.9562 818.995 L37.9562 812.788 L65.838 801.648 L37.9562 790.508 L37.9562 784.302 L76.9143 799.961 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip210)\" d=\"M42.0621 741.683 Q42.0621 746.394 45.7542 749.131 Q49.4145 751.868 55.812 751.868 Q62.2095 751.868 65.9017 749.163 Q69.5619 746.426 69.5619 741.683 Q69.5619 737.004 65.8698 734.267 Q62.1777 731.53 55.812 731.53 Q49.4781 731.53 45.786 734.267 Q42.0621 737.004 42.0621 741.683 M37.0968 741.683 Q37.0968 734.044 42.0621 729.684 Q47.0273 725.323 55.812 725.323 Q64.5649 725.323 69.5619 729.684 Q74.5272 734.044 74.5272 741.683 Q74.5272 749.354 69.5619 753.714 Q64.5649 758.043 55.812 758.043 Q47.0273 758.043 42.0621 753.714 Q37.0968 749.354 37.0968 741.683 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip210)\" d=\"M59.5359 716.22 L37.9562 716.22 L37.9562 710.364 L59.3131 710.364 Q64.3739 710.364 66.9202 708.39 Q69.4346 706.417 69.4346 702.47 Q69.4346 697.728 66.4109 694.991 Q63.3872 692.222 58.1673 692.222 L37.9562 692.222 L37.9562 686.365 L73.6042 686.365 L73.6042 692.222 L68.1296 692.222 Q71.3762 694.354 72.9676 697.187 Q74.5272 699.988 74.5272 703.712 Q74.5272 709.855 70.7078 713.037 Q66.8883 716.22 59.5359 716.22 M37.0968 701.484 L37.0968 701.484 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip210)\" d=\"M27.8347 668.509 L37.9562 668.509 L37.9562 656.446 L42.5077 656.446 L42.5077 668.509 L61.8594 668.509 Q66.2199 668.509 67.4613 667.332 Q68.7026 666.122 68.7026 662.462 L68.7026 656.446 L73.6042 656.446 L73.6042 662.462 Q73.6042 669.241 71.0897 671.819 Q68.5434 674.398 61.8594 674.398 L42.5077 674.398 L42.5077 678.694 L37.9562 678.694 L37.9562 674.398 L27.8347 674.398 L27.8347 668.509 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip210)\" d=\"M68.257 643.078 L87.1631 643.078 L87.1631 648.967 L37.9562 648.967 L37.9562 643.078 L43.3671 643.078 Q40.1842 641.232 38.6564 638.431 Q37.0968 635.599 37.0968 631.684 Q37.0968 625.191 42.2531 621.148 Q47.4093 617.074 55.812 617.074 Q64.2147 617.074 69.371 621.148 Q74.5272 625.191 74.5272 631.684 Q74.5272 635.599 72.9994 638.431 Q71.4398 641.232 68.257 643.078 M55.812 623.154 Q49.3508 623.154 45.6905 625.827 Q41.9984 628.469 41.9984 633.116 Q41.9984 637.763 45.6905 640.437 Q49.3508 643.078 55.812 643.078 Q62.2732 643.078 65.9653 640.437 Q69.6256 637.763 69.6256 633.116 Q69.6256 628.469 65.9653 625.827 Q62.2732 623.154 55.812 623.154 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip210)\" d=\"M59.5359 607.971 L37.9562 607.971 L37.9562 602.115 L59.3131 602.115 Q64.3739 602.115 66.9202 600.142 Q69.4346 598.168 69.4346 594.222 Q69.4346 589.479 66.4109 586.742 Q63.3872 583.973 58.1673 583.973 L37.9562 583.973 L37.9562 578.116 L73.6042 578.116 L73.6042 583.973 L68.1296 583.973 Q71.3762 586.105 72.9676 588.938 Q74.5272 591.739 74.5272 595.463 Q74.5272 601.606 70.7078 604.789 Q66.8883 607.971 59.5359 607.971 M37.0968 593.235 L37.0968 593.235 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip210)\" d=\"M27.8347 560.26 L37.9562 560.26 L37.9562 548.197 L42.5077 548.197 L42.5077 560.26 L61.8594 560.26 Q66.2199 560.26 67.4613 559.083 Q68.7026 557.873 68.7026 554.213 L68.7026 548.197 L73.6042 548.197 L73.6042 554.213 Q73.6042 560.993 71.0897 563.571 Q68.5434 566.149 61.8594 566.149 L42.5077 566.149 L42.5077 570.446 L37.9562 570.446 L37.9562 566.149 L27.8347 566.149 L27.8347 560.26 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip210)\" d=\"M37.9562 523.976 L37.9562 517.769 L67.875 506.629 L37.9562 495.489 L37.9562 489.283 L73.6042 502.651 L73.6042 510.608 L37.9562 523.976 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip210)\" d=\"M55.6847 464.998 Q55.6847 472.095 57.3079 474.833 Q58.9312 477.57 62.8461 477.57 Q65.9653 477.57 67.8114 475.533 Q69.6256 473.464 69.6256 469.931 Q69.6256 465.061 66.1881 462.133 Q62.7188 459.173 56.9897 459.173 L55.6847 459.173 L55.6847 464.998 M53.2657 453.317 L73.6042 453.317 L73.6042 459.173 L68.1933 459.173 Q71.4398 461.178 72.9994 464.17 Q74.5272 467.162 74.5272 471.491 Q74.5272 476.965 71.4716 480.212 Q68.3843 483.426 63.2281 483.426 Q57.2125 483.426 54.1569 479.416 Q51.1014 475.374 51.1014 467.385 L51.1014 459.173 L50.5285 459.173 Q46.4862 459.173 44.2901 461.847 Q42.0621 464.488 42.0621 469.295 Q42.0621 472.35 42.7941 475.246 Q43.5262 478.143 44.9903 480.816 L39.5795 480.816 Q38.3381 477.602 37.7334 474.578 Q37.0968 471.554 37.0968 468.69 Q37.0968 460.955 41.1072 457.136 Q45.1176 453.317 53.2657 453.317 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip210)\" d=\"M24.079 441.254 L24.079 435.397 L73.6042 435.397 L73.6042 441.254 L24.079 441.254 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip210)\" d=\"M59.5359 423.748 L37.9562 423.748 L37.9562 417.891 L59.3131 417.891 Q64.3739 417.891 66.9202 415.918 Q69.4346 413.945 69.4346 409.998 Q69.4346 405.256 66.4109 402.518 Q63.3872 399.749 58.1673 399.749 L37.9562 399.749 L37.9562 393.893 L73.6042 393.893 L73.6042 399.749 L68.1296 399.749 Q71.3762 401.882 72.9676 404.714 Q74.5272 407.515 74.5272 411.239 Q74.5272 417.382 70.7078 420.565 Q66.8883 423.748 59.5359 423.748 M37.0968 409.011 L37.0968 409.011 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip210)\" d=\"M54.3161 351.338 L57.1806 351.338 L57.1806 378.265 Q63.2281 377.883 66.4109 374.636 Q69.5619 371.358 69.5619 365.534 Q69.5619 362.16 68.7344 359.009 Q67.9069 355.826 66.2518 352.707 L71.7899 352.707 Q73.1267 355.858 73.827 359.168 Q74.5272 362.478 74.5272 365.884 Q74.5272 374.414 69.5619 379.411 Q64.5967 384.376 56.1303 384.376 Q47.3774 384.376 42.2531 379.665 Q37.0968 374.923 37.0968 366.902 Q37.0968 359.709 41.7438 355.539 Q46.3589 351.338 54.3161 351.338 M52.5973 357.194 Q47.7912 357.258 44.9266 359.9 Q42.0621 362.51 42.0621 366.838 Q42.0621 371.74 44.8312 374.7 Q47.6002 377.628 52.6292 378.074 L52.5973 357.194 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip210)\" d=\"M818.75 12.096 L830.943 12.096 L846.377 53.2532 L861.892 12.096 L874.086 12.096 L874.086 72.576 L866.105 72.576 L866.105 19.4686 L850.509 60.9499 L842.286 60.9499 L826.69 19.4686 L826.69 72.576 L818.75 72.576 L818.75 12.096 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip210)\" d=\"M908.883 76.7889 Q905.723 84.8907 902.725 87.3618 Q899.728 89.8329 894.705 89.8329 L888.75 89.8329 L888.75 83.5945 L893.125 83.5945 Q896.204 83.5945 897.905 82.1361 Q899.606 80.6778 901.672 75.2496 L903.009 71.8468 L884.658 27.2059 L892.558 27.2059 L906.736 62.6918 L920.914 27.2059 L928.813 27.2059 L908.883 76.7889 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip210)\" d=\"M994.478 44.2197 Q997.112 45.1109 999.583 48.0275 Q1002.09 50.9442 1004.61 56.0483 L1012.91 72.576 L1004.12 72.576 L996.382 57.061 Q993.385 50.9847 990.549 48.9997 Q987.754 47.0148 982.893 47.0148 L973.981 47.0148 L973.981 72.576 L965.798 72.576 L965.798 12.096 L984.27 12.096 Q994.641 12.096 999.745 16.4305 Q1004.85 20.7649 1004.85 29.5149 Q1004.85 35.2267 1002.18 38.994 Q999.542 42.7613 994.478 44.2197 M973.981 18.8205 L973.981 40.2903 L984.27 40.2903 Q990.185 40.2903 993.182 37.5762 Q996.22 34.8216 996.22 29.5149 Q996.22 24.2082 993.182 21.5346 Q990.185 18.8205 984.27 18.8205 L973.981 18.8205 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip210)\" d=\"M1058.2 48.0275 L1058.2 51.6733 L1023.93 51.6733 Q1024.41 59.3701 1028.55 63.421 Q1032.72 67.4314 1040.13 67.4314 Q1044.43 67.4314 1048.44 66.3781 Q1052.49 65.3249 1056.46 63.2184 L1056.46 70.267 Q1052.45 71.9684 1048.23 72.8596 Q1044.02 73.7508 1039.69 73.7508 Q1028.83 73.7508 1022.47 67.4314 Q1016.15 61.1119 1016.15 50.3365 Q1016.15 39.1965 1022.15 32.6746 Q1028.18 26.1121 1038.39 26.1121 Q1047.55 26.1121 1052.85 32.0264 Q1058.2 37.9003 1058.2 48.0275 M1050.75 45.84 Q1050.66 39.7232 1047.3 36.0774 Q1043.98 32.4315 1038.47 32.4315 Q1032.23 32.4315 1028.47 35.9558 Q1024.74 39.4801 1024.17 45.8805 L1050.75 45.84 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip210)\" d=\"M1099.36 28.5427 L1099.36 35.5912 Q1096.2 33.9709 1092.79 33.1607 Q1089.39 32.3505 1085.75 32.3505 Q1080.2 32.3505 1077.4 34.0519 Q1074.65 35.7533 1074.65 39.156 Q1074.65 41.7486 1076.63 43.2475 Q1078.62 44.7058 1084.61 46.0426 L1087.16 46.6097 Q1095.1 48.3111 1098.42 51.4303 Q1101.79 54.509 1101.79 60.0587 Q1101.79 66.3781 1096.76 70.0644 Q1091.78 73.7508 1083.03 73.7508 Q1079.39 73.7508 1075.42 73.0216 Q1071.49 72.3329 1067.11 70.9151 L1067.11 63.2184 Q1071.24 65.3654 1075.25 66.4591 Q1079.26 67.5124 1083.19 67.5124 Q1088.46 67.5124 1091.3 65.73 Q1094.13 63.9071 1094.13 60.6258 Q1094.13 57.5877 1092.06 55.9673 Q1090.04 54.3469 1083.11 52.8481 L1080.52 52.2405 Q1073.59 50.7821 1070.51 47.7845 Q1067.44 44.7463 1067.44 39.4801 Q1067.44 33.0797 1071.97 29.5959 Q1076.51 26.1121 1084.85 26.1121 Q1088.99 26.1121 1092.63 26.7198 Q1096.28 27.3274 1099.36 28.5427 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip210)\" d=\"M1112.89 54.671 L1112.89 27.2059 L1120.34 27.2059 L1120.34 54.3874 Q1120.34 60.8284 1122.85 64.0691 Q1125.36 67.2693 1130.39 67.2693 Q1136.42 67.2693 1139.91 63.421 Q1143.43 59.5726 1143.43 52.9291 L1143.43 27.2059 L1150.88 27.2059 L1150.88 72.576 L1143.43 72.576 L1143.43 65.6084 Q1140.72 69.7404 1137.11 71.7658 Q1133.55 73.7508 1128.81 73.7508 Q1120.99 73.7508 1116.94 68.8897 Q1112.89 64.0286 1112.89 54.671 M1131.64 26.1121 L1131.64 26.1121 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip210)\" d=\"M1166.24 9.54393 L1173.69 9.54393 L1173.69 72.576 L1166.24 72.576 L1166.24 9.54393 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip210)\" d=\"M1196.66 14.324 L1196.66 27.2059 L1212.01 27.2059 L1212.01 32.9987 L1196.66 32.9987 L1196.66 57.6282 Q1196.66 63.1779 1198.16 64.7578 Q1199.7 66.3376 1204.36 66.3376 L1212.01 66.3376 L1212.01 72.576 L1204.36 72.576 Q1195.73 72.576 1192.45 69.3758 Q1189.16 66.1351 1189.16 57.6282 L1189.16 32.9987 L1183.7 32.9987 L1183.7 27.2059 L1189.16 27.2059 L1189.16 14.324 L1196.66 14.324 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip210)\" d=\"M1250.74 28.5427 L1250.74 35.5912 Q1247.58 33.9709 1244.18 33.1607 Q1240.77 32.3505 1237.13 32.3505 Q1231.58 32.3505 1228.78 34.0519 Q1226.03 35.7533 1226.03 39.156 Q1226.03 41.7486 1228.01 43.2475 Q1230 44.7058 1235.99 46.0426 L1238.55 46.6097 Q1246.49 48.3111 1249.81 51.4303 Q1253.17 54.509 1253.17 60.0587 Q1253.17 66.3781 1248.15 70.0644 Q1243.16 73.7508 1234.41 73.7508 Q1230.77 73.7508 1226.8 73.0216 Q1222.87 72.3329 1218.49 70.9151 L1218.49 63.2184 Q1222.63 65.3654 1226.64 66.4591 Q1230.65 67.5124 1234.58 67.5124 Q1239.84 67.5124 1242.68 65.73 Q1245.51 63.9071 1245.51 60.6258 Q1245.51 57.5877 1243.45 55.9673 Q1241.42 54.3469 1234.49 52.8481 L1231.9 52.2405 Q1224.97 50.7821 1221.9 47.7845 Q1218.82 44.7463 1218.82 39.4801 Q1218.82 33.0797 1223.35 29.5959 Q1227.89 26.1121 1236.24 26.1121 Q1240.37 26.1121 1244.01 26.7198 Q1247.66 27.3274 1250.74 28.5427 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><polyline clip-path=\"url(#clip212)\" style=\"stroke:#ff0000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:8; stroke-opacity:1; fill:none\" points=\"\n 246.529,415.679 257.197,434.57 267.865,453.179 278.533,471.508 289.201,489.554 299.869,507.32 310.537,524.804 321.205,542.007 331.873,558.929 342.541,575.569 \n 353.209,591.928 363.877,608.006 374.545,623.802 385.213,639.317 395.881,654.551 406.549,669.504 417.217,684.175 427.885,698.564 438.553,712.673 449.221,726.5 \n 459.889,740.046 470.557,753.31 481.225,766.293 491.893,778.995 502.561,791.415 513.229,803.554 523.897,815.412 534.565,826.989 545.233,838.284 555.901,849.298 \n 566.569,860.03 577.237,870.482 587.905,880.651 598.573,890.54 609.241,900.147 619.909,909.473 630.577,918.518 641.245,927.281 651.913,935.763 662.581,943.963 \n 673.248,951.883 683.916,959.521 694.584,966.877 705.252,973.953 715.92,980.747 726.588,987.259 737.256,993.491 747.924,999.441 758.592,1005.11 769.26,1010.5 \n 779.928,1015.6 790.596,1020.43 801.264,1024.97 811.932,1029.23 822.6,1033.21 833.268,1036.91 843.936,1040.33 854.604,1043.47 865.272,1046.32 875.94,1048.9 \n 886.608,1051.19 897.276,1053.2 907.944,1054.93 918.612,1056.38 929.28,1057.55 939.948,1058.43 950.616,1059.04 961.284,1059.36 971.952,1059.4 982.62,1059.17 \n 993.288,1058.65 1003.96,1057.84 1014.62,1056.76 1025.29,1055.4 1035.96,1053.75 1046.63,1051.82 1057.3,1049.61 1067.96,1047.12 1078.63,1044.35 1089.3,1041.3 \n 1099.97,1037.97 1110.64,1034.35 1121.3,1030.46 1131.97,1026.28 1142.64,1021.82 1153.31,1017.08 1163.98,1012.06 1174.64,1006.75 1185.31,1001.17 1195.98,995.305 \n 1206.65,989.158 1217.32,982.73 1227.98,976.02 1238.65,969.029 1249.32,961.757 1259.99,954.204 1270.66,946.369 1281.32,938.253 1291.99,929.855 1302.66,921.176 \n 1313.33,912.216 1324,902.974 1334.66,893.452 1345.33,883.647 1356,873.562 1366.67,863.195 1377.34,852.547 1388,841.618 1398.67,830.407 1409.34,818.915 \n 1420.01,807.141 1430.67,795.087 1441.34,782.751 1452.01,770.133 1462.68,757.234 1473.35,744.054 1484.01,730.593 1494.68,716.85 1505.35,702.826 1516.02,688.521 \n 1526.69,673.934 1537.35,659.066 1548.02,643.917 1558.69,628.486 1569.36,612.774 1580.03,596.781 1590.69,580.507 1601.36,563.951 1612.03,547.113 1622.7,529.995 \n 1633.37,512.595 1644.03,494.914 1654.7,476.951 1665.37,458.707 1676.04,440.182 1686.71,421.376 1697.37,402.288 1708.04,382.919 1718.71,363.268 1729.38,343.336 \n 1740.05,323.123 1750.71,302.629 1761.38,281.853 1772.05,260.796 1782.72,239.457 1793.39,217.838 1804.05,195.936 1814.72,173.754 1825.39,151.29 \n \"/>\n<polyline clip-path=\"url(#clip212)\" style=\"stroke:#0000ff; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" stroke-dasharray=\"16, 10\" points=\"\n 246.529,1078.19 257.197,1077.79 267.865,1077.25 278.533,1076.58 289.201,1075.78 299.869,1074.85 310.537,1073.79 321.205,1072.6 331.873,1071.3 342.541,1069.88 \n 353.209,1068.36 363.877,1066.73 374.545,1065 385.213,1063.18 395.881,1061.28 406.549,1059.31 417.217,1057.26 427.885,1055.15 438.553,1052.98 449.221,1050.77 \n 459.889,1048.52 470.557,1046.24 481.225,1043.94 491.893,1041.62 502.561,1039.3 513.229,1036.99 523.897,1034.68 534.565,1032.4 545.233,1030.14 555.901,1027.92 \n 566.569,1025.75 577.237,1023.63 587.905,1021.57 598.573,1019.58 609.241,1017.67 619.909,1015.84 630.577,1014.1 641.245,1012.45 651.913,1010.91 662.581,1009.47 \n 673.248,1008.15 683.916,1006.95 694.584,1005.87 705.252,1004.91 715.92,1004.09 726.588,1003.39 737.256,1002.84 747.924,1002.42 758.592,1002.14 769.26,1002 \n 779.928,1002 790.596,1002.14 801.264,1002.42 811.932,1002.84 822.6,1003.39 833.268,1004.09 843.936,1004.91 854.604,1005.87 865.272,1006.95 875.94,1008.15 \n 886.608,1009.47 897.276,1010.91 907.944,1012.45 918.612,1014.1 929.28,1015.84 939.948,1017.67 950.616,1019.58 961.284,1021.57 971.952,1023.63 982.62,1025.75 \n 993.288,1027.92 1003.96,1030.14 1014.62,1032.4 1025.29,1034.68 1035.96,1036.99 1046.63,1039.3 1057.3,1041.62 1067.96,1043.94 1078.63,1046.24 1089.3,1048.52 \n 1099.97,1050.77 1110.64,1052.98 1121.3,1055.15 1131.97,1057.26 1142.64,1059.31 1153.31,1061.28 1163.98,1063.18 1174.64,1065 1185.31,1066.73 1195.98,1068.36 \n 1206.65,1069.88 1217.32,1071.3 1227.98,1072.6 1238.65,1073.79 1249.32,1074.85 1259.99,1075.78 1270.66,1076.58 1281.32,1077.25 1291.99,1077.79 1302.66,1078.19 \n 1313.33,1078.44 1324,1078.56 1334.66,1078.54 1345.33,1078.38 1356,1078.07 1366.67,1077.63 1377.34,1077.05 1388,1076.34 1398.67,1075.49 1409.34,1074.51 \n 1420.01,1073.41 1430.67,1072.19 1441.34,1070.85 1452.01,1069.39 1462.68,1067.83 1473.35,1066.17 1484.01,1064.42 1494.68,1062.57 1505.35,1060.64 1516.02,1058.64 \n 1526.69,1056.57 1537.35,1054.45 1548.02,1052.26 1558.69,1050.04 1569.36,1047.78 1580.03,1045.49 1590.69,1043.18 1601.36,1040.86 1612.03,1038.54 1622.7,1036.23 \n 1633.37,1033.93 1644.03,1031.66 1654.7,1029.41 1665.37,1027.21 1676.04,1025.05 1686.71,1022.95 1697.37,1020.91 1708.04,1018.95 1718.71,1017.06 1729.38,1015.26 \n 1740.05,1013.55 1750.71,1011.94 1761.38,1010.43 1772.05,1009.03 1782.72,1007.75 1793.39,1006.58 1804.05,1005.54 1814.72,1004.63 1825.39,1003.85 \n \"/>\n<path clip-path=\"url(#clip210)\" d=\"\nM1522.29 311.756 L1816.97 311.756 L1816.97 156.236 L1522.29 156.236 Z\n \" fill=\"#ffffff\" fill-rule=\"evenodd\" fill-opacity=\"1\"/>\n<polyline clip-path=\"url(#clip210)\" style=\"stroke:#000000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n 1522.29,311.756 1816.97,311.756 1816.97,156.236 1522.29,156.236 1522.29,311.756 \n \"/>\n<polyline clip-path=\"url(#clip210)\" style=\"stroke:#ff0000; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n 1540.88,208.076 1652.46,208.076 \n \"/>\n<path clip-path=\"url(#clip210)\" d=\"M1687.56 189.337 L1687.56 192.879 L1683.48 192.879 Q1681.19 192.879 1680.29 193.805 Q1679.41 194.731 1679.41 197.138 L1679.41 199.43 L1686.42 199.43 L1686.42 202.74 L1679.41 202.74 L1679.41 225.356 L1675.13 225.356 L1675.13 202.74 L1671.05 202.74 L1671.05 199.43 L1675.13 199.43 L1675.13 197.624 Q1675.13 193.296 1677.14 191.328 Q1679.15 189.337 1683.53 189.337 L1687.56 189.337 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip210)\" d=\"M1712.67 209.708 L1712.67 225.356 L1708.41 225.356 L1708.41 209.847 Q1708.41 206.166 1706.98 204.337 Q1705.54 202.509 1702.67 202.509 Q1699.22 202.509 1697.23 204.708 Q1695.24 206.907 1695.24 210.703 L1695.24 225.356 L1690.96 225.356 L1690.96 199.43 L1695.24 199.43 L1695.24 203.458 Q1696.77 201.12 1698.83 199.962 Q1700.91 198.805 1703.62 198.805 Q1708.09 198.805 1710.38 201.583 Q1712.67 204.337 1712.67 209.708 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip210)\" d=\"M1722.58 221.421 L1730.22 221.421 L1730.22 195.055 L1721.91 196.722 L1721.91 192.462 L1730.17 190.796 L1734.85 190.796 L1734.85 221.421 L1742.49 221.421 L1742.49 225.356 L1722.58 225.356 L1722.58 221.421 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip210)\" d=\"M1761.56 189.384 Q1758.46 194.708 1756.95 199.916 Q1755.45 205.124 1755.45 210.472 Q1755.45 215.819 1756.95 221.073 Q1758.48 226.305 1761.56 231.606 L1757.86 231.606 Q1754.39 226.166 1752.65 220.911 Q1750.94 215.657 1750.94 210.472 Q1750.94 205.31 1752.65 200.078 Q1754.36 194.847 1757.86 189.384 L1761.56 189.384 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip210)\" d=\"M1769.15 189.384 L1772.86 189.384 Q1776.33 194.847 1778.04 200.078 Q1779.78 205.31 1779.78 210.472 Q1779.78 215.657 1778.04 220.911 Q1776.33 226.166 1772.86 231.606 L1769.15 231.606 Q1772.23 226.305 1773.74 221.073 Q1775.26 215.819 1775.26 210.472 Q1775.26 205.124 1773.74 199.916 Q1772.23 194.708 1769.15 189.384 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><polyline clip-path=\"url(#clip210)\" style=\"stroke:#0000ff; stroke-linecap:butt; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" stroke-dasharray=\"16, 10\" points=\"\n 1540.88,259.916 1652.46,259.916 \n \"/>\n<path clip-path=\"url(#clip210)\" d=\"M1691.56 252.265 L1691.56 256.247 Q1689.76 255.251 1687.93 254.765 Q1686.12 254.256 1684.27 254.256 Q1680.13 254.256 1677.83 256.895 Q1675.54 259.511 1675.54 264.256 Q1675.54 269.001 1677.83 271.64 Q1680.13 274.256 1684.27 274.256 Q1686.12 274.256 1687.93 273.77 Q1689.76 273.261 1691.56 272.265 L1691.56 276.2 Q1689.78 277.034 1687.86 277.45 Q1685.96 277.867 1683.81 277.867 Q1677.95 277.867 1674.5 274.186 Q1671.05 270.506 1671.05 264.256 Q1671.05 257.913 1674.52 254.279 Q1678.02 250.645 1684.08 250.645 Q1686.05 250.645 1687.93 251.062 Q1689.8 251.455 1691.56 252.265 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip210)\" d=\"M1709.02 254.256 Q1705.59 254.256 1703.6 256.941 Q1701.61 259.603 1701.61 264.256 Q1701.61 268.909 1703.58 271.594 Q1705.57 274.256 1709.02 274.256 Q1712.42 274.256 1714.41 271.571 Q1716.4 268.886 1716.4 264.256 Q1716.4 259.65 1714.41 256.964 Q1712.42 254.256 1709.02 254.256 M1709.02 250.645 Q1714.57 250.645 1717.74 254.256 Q1720.91 257.867 1720.91 264.256 Q1720.91 270.622 1717.74 274.256 Q1714.57 277.867 1709.02 277.867 Q1703.44 277.867 1700.27 274.256 Q1697.12 270.622 1697.12 264.256 Q1697.12 257.867 1700.27 254.256 Q1703.44 250.645 1709.02 250.645 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip210)\" d=\"M1744.5 252.034 L1744.5 256.062 Q1742.7 255.136 1740.75 254.673 Q1738.81 254.21 1736.72 254.21 Q1733.55 254.21 1731.95 255.182 Q1730.38 256.154 1730.38 258.099 Q1730.38 259.58 1731.51 260.437 Q1732.65 261.27 1736.08 262.034 L1737.53 262.358 Q1742.07 263.33 1743.97 265.112 Q1745.89 266.872 1745.89 270.043 Q1745.89 273.654 1743.02 275.761 Q1740.17 277.867 1735.17 277.867 Q1733.09 277.867 1730.82 277.45 Q1728.58 277.057 1726.08 276.247 L1726.08 271.849 Q1728.44 273.075 1730.73 273.7 Q1733.02 274.302 1735.26 274.302 Q1738.27 274.302 1739.89 273.284 Q1741.51 272.242 1741.51 270.367 Q1741.51 268.631 1740.33 267.705 Q1739.18 266.779 1735.22 265.923 L1733.74 265.575 Q1729.78 264.742 1728.02 263.029 Q1726.26 261.293 1726.26 258.284 Q1726.26 254.626 1728.85 252.636 Q1731.45 250.645 1736.21 250.645 Q1738.58 250.645 1740.66 250.992 Q1742.74 251.339 1744.5 252.034 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /></svg>\n"
},
"metadata": {},
"execution_count": 46
}
],
"metadata": {}
},
{
"cell_type": "markdown",
"source": [
"# Types: Integers, Floats, Bools and Others\n",
"\n",
"Julia has many different types of variables: signed integers (like 2 or -5), floating point numbers (2.0 and -5.1), bools (false/true), bitarrays (similar to bools, but with more efficient use of memory), strings (\"hello\"), Dates (2017-04-23) and many more types."
],
"metadata": {}
},
{
"cell_type": "markdown",
"source": [
"## Integers and Floats"
],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 47,
"source": [
"a = 2 #integer, Int (Int64 on most machines)\n",
"b = 2.0 #floating point, (Float64 on most machines)\n",
"A = [1,2]\n",
"B = [1.0,2.0]\n",
"\n",
"println(\"Finding the type of a, b, A and B:\")\n",
"println(typeof(a),\" \",typeof(b),\" \",typeof(A),\" \",typeof(B))"
],
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Finding the type of a, b, A and B:\n",
"Int64 Float64 Vector{Int64} Vector{Float64}\n"
]
}
],
"metadata": {}
},
{
"cell_type": "markdown",
"source": [
"## Bools and BitArrays\n",
"\n",
"Bools are \"true\" or \"false\". BitArrays are (more memory efficient) versions of this."
],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 48,
"source": [
"c = 2 > 1.1\n",
"C = A .> 1.5 #A is an array, so C is too\n",
"\n",
"println(\"Finding the type of c and C:\")\n",
"println(typeof(c),\" \",typeof(C))"
],
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Finding the type of c and C:\n",
"Bool BitVector\n"
]
}
],
"metadata": {}
},
{
"cell_type": "markdown",
"source": [
"## Calculations with Mixed Types\n",
"\n",
"A calculation like \"integer\" + \"float\" works and the type of the result will be a float (the more flexible type). Similarly, \"bool\" + \"integer\" will give an integer. These promotion rules make it easy to have mixed types in calculations, and also provide a simple way of converting a variable from one type to another. (There are also an explicit convert() function that might be quicker.)"
],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 49,
"source": [
"println(1+2.0) #integer + Float\n",
"println((1>0) + 2) #bool + integer"
],
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"3.0\n",
"3\n"
]
}
],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 50,
"source": [
"1 > 2"
],
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"false"
]
},
"metadata": {},
"execution_count": 50
}
],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": null,
"source": [],
"outputs": [],
"metadata": {}
}
],
"metadata": {
"@webio": {
"lastCommId": null,
"lastKernelId": null
},
"anaconda-cloud": {},
"kernelspec": {
"display_name": "Julia 1.7.0-rc1",
"language": "julia",
"name": "julia-1.7"
},
"language_info": {
"file_extension": ".jl",
"name": "julia",
"mimetype": "application/julia",
"version": "1.7.0"
}
},
"nbformat": 4,
"nbformat_minor": 1
}