diff --git a/01_Coursera_1.ipynb b/01_Coursera_1.ipynb new file mode 100644 index 0000000..7438f8d --- /dev/null +++ b/01_Coursera_1.ipynb @@ -0,0 +1,164 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Hello World!\n" + ] + } + ], + "source": [ + "println(\"Hello World!\")" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "14" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "5+9 # 14" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Hello! My word! Hello! My word! \n" + ] + } + ], + "source": [ + "println((\"Hello!\" * \" My word! \")^2)" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "search: \u001b[0m\u001b[1mp\u001b[22m\u001b[0m\u001b[1mr\u001b[22m\u001b[0m\u001b[1mi\u001b[22m\u001b[0m\u001b[1mn\u001b[22m\u001b[0m\u001b[1mt\u001b[22m\u001b[0m\u001b[1ml\u001b[22m\u001b[0m\u001b[1mn\u001b[22m \u001b[0m\u001b[1mp\u001b[22m\u001b[0m\u001b[1mr\u001b[22m\u001b[0m\u001b[1mi\u001b[22m\u001b[0m\u001b[1mn\u001b[22m\u001b[0m\u001b[1mt\u001b[22msty\u001b[0m\u001b[1ml\u001b[22med \u001b[0m\u001b[1mp\u001b[22m\u001b[0m\u001b[1mr\u001b[22m\u001b[0m\u001b[1mi\u001b[22m\u001b[0m\u001b[1mn\u001b[22m\u001b[0m\u001b[1mt\u001b[22m s\u001b[0m\u001b[1mp\u001b[22m\u001b[0m\u001b[1mr\u001b[22m\u001b[0m\u001b[1mi\u001b[22m\u001b[0m\u001b[1mn\u001b[22m\u001b[0m\u001b[1mt\u001b[22m is\u001b[0m\u001b[1mp\u001b[22m\u001b[0m\u001b[1mr\u001b[22m\u001b[0m\u001b[1mi\u001b[22m\u001b[0m\u001b[1mn\u001b[22m\u001b[0m\u001b[1mt\u001b[22m\n", + "\n" + ] + }, + { + "data": { + "text/latex": [ + "\\begin{verbatim}\n", + "println([io::IO], xs...)\n", + "\\end{verbatim}\n", + "Print (using \\href{@ref}{\\texttt{print}}) \\texttt{xs} followed by a newline. If \\texttt{io} is not supplied, prints to \\href{@ref}{\\texttt{stdout}}.\n", + "\n", + "\\section{Examples}\n", + "\\begin{verbatim}\n", + "julia> println(\"Hello, world\")\n", + "Hello, world\n", + "\n", + "julia> io = IOBuffer();\n", + "\n", + "julia> println(io, \"Hello, world\")\n", + "\n", + "julia> String(take!(io))\n", + "\"Hello, world\\n\"\n", + "\\end{verbatim}\n" + ], + "text/markdown": [ + "```\n", + "println([io::IO], xs...)\n", + "```\n", + "\n", + "Print (using [`print`](@ref)) `xs` followed by a newline. If `io` is not supplied, prints to [`stdout`](@ref).\n", + "\n", + "# Examples\n", + "\n", + "```jldoctest\n", + "julia> println(\"Hello, world\")\n", + "Hello, world\n", + "\n", + "julia> io = IOBuffer();\n", + "\n", + "julia> println(io, \"Hello, world\")\n", + "\n", + "julia> String(take!(io))\n", + "\"Hello, world\\n\"\n", + "```\n" + ], + "text/plain": [ + "\u001b[36m println([io::IO], xs...)\u001b[39m\n", + "\n", + " Print (using \u001b[36mprint\u001b[39m) \u001b[36mxs\u001b[39m followed by a newline. If \u001b[36mio\u001b[39m is not supplied, prints\n", + " to \u001b[36mstdout\u001b[39m.\n", + "\n", + "\u001b[1m Examples\u001b[22m\n", + "\u001b[1m ≡≡≡≡≡≡≡≡≡≡\u001b[22m\n", + "\n", + "\u001b[36m julia> println(\"Hello, world\")\u001b[39m\n", + "\u001b[36m Hello, world\u001b[39m\n", + "\u001b[36m \u001b[39m\n", + "\u001b[36m julia> io = IOBuffer();\u001b[39m\n", + "\u001b[36m \u001b[39m\n", + "\u001b[36m julia> println(io, \"Hello, world\")\u001b[39m\n", + "\u001b[36m \u001b[39m\n", + "\u001b[36m julia> String(take!(io))\u001b[39m\n", + "\u001b[36m \"Hello, world\\n\"\u001b[39m" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "?println" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Julia 1.2.0", + "language": "julia", + "name": "julia-1.2" + }, + "language_info": { + "file_extension": ".jl", + "mimetype": "application/julia", + "name": "julia", + "version": "1.2.0" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/01_Coursera_2.ipynb b/01_Coursera_2.ipynb new file mode 100644 index 0000000..5095a06 --- /dev/null +++ b/01_Coursera_2.ipynb @@ -0,0 +1,26 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Julia 1.2.0", + "language": "julia", + "name": "julia-1.2" + }, + "language_info": { + "file_extension": ".jl", + "mimetype": "application/julia", + "name": "julia", + "version": "1.2.0" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/02_Coursera_1.ipynb b/02_Coursera_1.ipynb new file mode 100644 index 0000000..556c17a --- /dev/null +++ b/02_Coursera_1.ipynb @@ -0,0 +1,406 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "-2" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "1-2+3-4" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "5//4" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "1//2+3//4" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0.05" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "1/(2+3)/4" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "4//11" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "1//(2+(3//4))" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "7//8" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "(1//2+3)//4" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "false" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "!true" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "true" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "!false" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "true" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "true && true" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "false" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "true && false" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "true" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "false || true" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "84.0" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "5040 / 60" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "11" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "8+2*3-3" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "10" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "2^2+6" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "10" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "0-6+2^4" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "9" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "2*3+2^1+1" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "true" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "1+3<5||2+2<1" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "true" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "3 & 5 > 0 " + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "false" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "8 & 5 > 0" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "false" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "1 + (2 - 5) - 2 == 0" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Julia 1.2.0", + "language": "julia", + "name": "julia-1.2" + }, + "language_info": { + "file_extension": ".jl", + "mimetype": "application/julia", + "name": "julia", + "version": "1.2.0" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/03_Coursera_1.ipynb b/03_Coursera_1.ipynb new file mode 100644 index 0000000..d32e44a --- /dev/null +++ b/03_Coursera_1.ipynb @@ -0,0 +1,820 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "8" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "length(bitstring(parse(Int8,\"4\")))" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "8" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "length(bitstring(Int8(4)))" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Int8" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "typeof(Int8(3))" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "\"11001110101100010000000000000000\"" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "bitstring('α')" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "2-element Array{Int64,1}:\n", + " 0\n", + " 1" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "digits(10, base = 10)" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "4-element Array{Int64,1}:\n", + " 0\n", + " 1\n", + " 0\n", + " 1" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "digits(10, base = 2)" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "false" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "typeof(2) == typeof(4.0)" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "3-element Array{Int64,1}:\n", + " 4695258384\n", + " 4695258416\n", + " 4695258448" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "Array{Int64}(undef,3)" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "3-element Array{String,1}:\n", + " #undef\n", + " #undef\n", + " #undef" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "Array{String}(undef,3)" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "\"Hello World!\"" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "greeting = \"Hello World!\"" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Hello World!\n" + ] + } + ], + "source": [ + "println(greeting)" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "3-element Array{Int64,1}:\n", + " 1\n", + " 2\n", + " 3" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a = [1,2,3]" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "3-element Array{Int64,1}:\n", + " 1\n", + " 2\n", + " 3" + ] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "b = a" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "5" + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "b[2] = 5" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "3-element Array{Int64,1}:\n", + " 1\n", + " 5\n", + " 3" + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "7" + ] + }, + "execution_count": 25, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a[1] = 7" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "3-element Array{Int64,1}:\n", + " 7\n", + " 5\n", + " 3" + ] + }, + "execution_count": 26, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "b" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "3-element Array{Int64,1}:\n", + " 7\n", + " 5\n", + " 3" + ] + }, + "execution_count": 28, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "c = a[:]" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "9" + ] + }, + "execution_count": 30, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a[3] = 9" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "3-element Array{Int64,1}:\n", + " 7\n", + " 5\n", + " 3" + ] + }, + "execution_count": 31, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "c" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "3-element Array{Int64,1}:\n", + " 7\n", + " 5\n", + " 9" + ] + }, + "execution_count": 32, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a" + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "2×3 Array{Integer,2}:\n", + " #undef #undef #undef\n", + " #undef #undef #undef" + ] + }, + "execution_count": 33, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "abstypevariable = Array{Integer}(undef,2,3)" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Array{Integer,2}" + ] + }, + "execution_count": 34, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "typeof(abstypevariable)" + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "metadata": {}, + "outputs": [ + { + "ename": "UndefRefError", + "evalue": "UndefRefError: access to undefined reference", + "output_type": "error", + "traceback": [ + "UndefRefError: access to undefined reference", + "", + "Stacktrace:", + " [1] getindex(::Array{Integer,2}, ::Int64, ::Int64) at ./array.jl:729", + " [2] top-level scope at In[35]:1" + ] + } + ], + "source": [ + "abstypevariable[2,1]" + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "6" + ] + }, + "execution_count": 38, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "length(abstypevariable)" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(2, 3)" + ] + }, + "execution_count": 39, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "size(abstypevariable)" + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(3,)" + ] + }, + "execution_count": 40, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "size([1,2,3])" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 41, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "abstypevariable[1,1] = 1" + ] + }, + { + "cell_type": "code", + "execution_count": 45, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "5.0" + ] + }, + "execution_count": 45, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "abstypevariable[1,2] = 5.0 #5.3 not possible" + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "2×3 Array{Integer,2}:\n", + " 1 5 #undef\n", + " #undef #undef #undef" + ] + }, + "execution_count": 43, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "abstypevariable" + ] + }, + { + "cell_type": "code", + "execution_count": 46, + "metadata": {}, + "outputs": [ + { + "ename": "MethodError", + "evalue": "MethodError: Cannot `convert` an object of type String to an object of type Integer\nClosest candidates are:\n convert(::Type{T<:Number}, !Matched::T<:Number) where T<:Number at number.jl:6\n convert(::Type{T<:Number}, !Matched::Number) where T<:Number at number.jl:7\n convert(::Type{T<:Integer}, !Matched::Ptr) where T<:Integer at pointer.jl:23\n ...", + "output_type": "error", + "traceback": [ + "MethodError: Cannot `convert` an object of type String to an object of type Integer\nClosest candidates are:\n convert(::Type{T<:Number}, !Matched::T<:Number) where T<:Number at number.jl:6\n convert(::Type{T<:Number}, !Matched::Number) where T<:Number at number.jl:7\n convert(::Type{T<:Integer}, !Matched::Ptr) where T<:Integer at pointer.jl:23\n ...", + "", + "Stacktrace:", + " [1] setindex!(::Array{Integer,2}, ::String, ::Int64, ::Int64) at ./array.jl:768", + " [2] top-level scope at In[46]:1" + ] + } + ], + "source": [ + "abstypevariable[2,2] = \"stringystringstr\"" + ] + }, + { + "cell_type": "code", + "execution_count": 47, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "2×3 Array{Int64,2}:\n", + " 4679027904 4583513520 -1\n", + " 4661545168 1 4311744769" + ] + }, + "execution_count": 47, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "arbconcretevariable = Array{Int64}(undef,2,3)" + ] + }, + { + "cell_type": "code", + "execution_count": 48, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'c': ASCII/Unicode U+0063 (category Ll: Letter, lowercase)" + ] + }, + "execution_count": 48, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "Cake = 'c'" + ] + }, + { + "cell_type": "code", + "execution_count": 49, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "false" + ] + }, + "execution_count": 49, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "'a' === \"a\"" + ] + }, + { + "cell_type": "code", + "execution_count": 51, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "3×2 Array{Integer,2}:\n", + " #undef #undef\n", + " #undef #undef\n", + " #undef #undef" + ] + }, + "execution_count": 51, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a = Array{Integer,2}(undef, 3, 2)" + ] + }, + { + "cell_type": "code", + "execution_count": 52, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "11×12 Array{Int64,2}:\n", + " 4684904288 4671225872 4671226928 … 4671236288 4671236816 4671237344\n", + " 4684904336 4671225920 4671226976 4671236336 4671236864 4671237392\n", + " 4684904384 4671225968 4671227024 4671236384 4671236912 4671237440\n", + " 4684904432 4671226016 4671227504 4671236432 4671236960 4671237488\n", + " 4684904480 4671226064 4671227552 4671236480 4671237008 4671237536\n", + " 4684904528 4671226112 4671227600 … 4671236528 4671237056 4671237584\n", + " 4684904576 4671226160 4671227984 4671236576 4671237104 4671237680\n", + " 4684904624 4671226208 4671228032 4671236624 4671237152 4671237728\n", + " 4684904672 4671226448 4671228080 4671236672 4671237200 4671237776\n", + " 4684904720 4671226496 4671228464 4671236720 4671237248 4671237824\n", + " 4671176608 4671226544 4671228656 … 4671236768 4671237296 4671238352" + ] + }, + "execution_count": 52, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "x = Array{Int64}(undef,11, 12) \n" + ] + }, + { + "cell_type": "code", + "execution_count": 53, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Array{Int64,2}" + ] + }, + "execution_count": 53, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "typeof(x)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Julia 1.2.0", + "language": "julia", + "name": "julia-1.2" + }, + "language_info": { + "file_extension": ".jl", + "mimetype": "application/julia", + "name": "julia", + "version": "1.2.0" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/04_Coursera_1.ipynb b/04_Coursera_1.ipynb new file mode 100644 index 0000000..3d6df75 --- /dev/null +++ b/04_Coursera_1.ipynb @@ -0,0 +1,1102 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Hello world\n" + ] + } + ], + "source": [ + "greeting = \"Hello world\"\n", + "println(greeting)" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(0.9800665778412416, 2.302585092994046, 1.22)" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a,b,c = cos(0.2), log(10), abs(-1.22)" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0.9800665778412416" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "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 \u001b[0m\u001b[1mc\u001b[22m\u001b[0m\u001b[1mo\u001b[22mn\u001b[0m\u001b[1ms\u001b[22mt \u001b[0m\u001b[1mc\u001b[22ml\u001b[0m\u001b[1mo\u001b[22m\u001b[0m\u001b[1ms\u001b[22me is\u001b[0m\u001b[1mc\u001b[22m\u001b[0m\u001b[1mo\u001b[22mn\u001b[0m\u001b[1ms\u001b[22mt\n", + "\n" + ] + }, + { + "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", + "\\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 Array{Float64,2}:\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", + "---\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 Array{Float64,2}:\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", + " ────────────────────────────────────────────────────────────────────────────\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 Array{Float64,2}:\u001b[39m\n", + "\u001b[36m 0.291927 -0.708073\u001b[39m\n", + "\u001b[36m -0.708073 0.291927\u001b[39m" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "? cos" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1.0" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "cos(0)" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "-1.0" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "cos(π)" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "6.123233995736766e-17" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "cos(π/2)" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Irrational{:π}" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "typeof(π)" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "12 methods for generic function muladd:" + ], + "text/plain": [ + "# 12 methods for generic function \"muladd\":\n", + "[1] muladd(a::Float16, b::Float16, c::Float16) in Base at float.jl:406\n", + "[2] muladd(x::Float64, y::Float64, z::Float64) in Base at float.jl:404\n", + "[3] muladd(x::Float32, y::Float32, z::Float32) in Base at float.jl:403\n", + "[4] muladd(z::Complex, w::Complex, x::Complex) in Base at complex.jl:272\n", + "[5] muladd(x::Real, z::Complex, y::Number) in Base at complex.jl:315\n", + "[6] muladd(z::Complex, x::Real, y::Real) in Base at complex.jl:316\n", + "[7] muladd(z::Complex, x::Real, w::Complex) in Base at complex.jl:317\n", + "[8] muladd(x::Real, y::Real, z::Complex) in Base at complex.jl:319\n", + "[9] muladd(z::Complex, w::Complex, x::Real) in Base at complex.jl:320\n", + "[10] muladd(x::T, y::T, z::T) where T<:Number in Base at promotion.jl:397\n", + "[11] muladd(x::Number, y::Number, z::Number) in Base at promotion.jl:348\n", + "[12] muladd(x, y, z) in Base.Math at math.jl:1012" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "methods(muladd)" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "myfunc (generic function with 1 method)" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "myfunc(firstvar) = 20* firstvar" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "6664.4439999999995" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "myfunc(333.2222)" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "addxtoy (generic function with 1 method)" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "addxtoy(x,y) = x + y" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "18.8" + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "addxtoy(22,-3.2)" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "nextfunc (generic function with 1 method)" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "function nextfunc(x,y,z)\n", + " x+y*z\n", + "end" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "showdebugprintln (generic function with 1 method)" + ] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "function showdebugprintln(testvar)\n", + " println(\"Show inside the showdebugprintln() now\")\n", + " println(\"The type of testvar is $(typeof(testvar)) and the value of testvar is $testvar\")\n", + "end" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "2-element Array{Any,1}:\n", + " '1'\n", + " 2.0 " + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a = ['1',2.]" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Show inside the showdebugprintln() now\n", + "The type of testvar is Array{Any,1} and the value of testvar is Any['1', 2.0]\n" + ] + } + ], + "source": [ + "showdebugprintln(a)" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "mycos (generic function with 1 method)" + ] + }, + "execution_count": 28, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "mycos(x) = cos(x)" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0.955336489125606" + ] + }, + "execution_count": 29, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "mycos(.3)" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "mycos (generic function with 2 methods)" + ] + }, + "execution_count": 30, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "mycos(adj,hyp) = adj/hyp" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0.9230769230769231" + ] + }, + "execution_count": 32, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "mycos(12,13)" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "2 methods for generic function mycos:" + ], + "text/plain": [ + "# 2 methods for generic function \"mycos\":\n", + "[1] mycos(x) in Main at In[28]:1\n", + "[2] mycos(adj, hyp) in Main at In[30]:1" + ] + }, + "execution_count": 31, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "methods(mycos)" + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "mycos (generic function with 3 methods)" + ] + }, + "execution_count": 33, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "mycos(thet::Float64) = cos(thet)" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "84.0" + ] + }, + "execution_count": 34, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "60 \\ 5040" + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "search: \u001b[0m\u001b[1m\\\u001b[22m\n", + "\n" + ] + }, + { + "data": { + "text/latex": [ + "\\begin{verbatim}\n", + "\\(x, y)\n", + "\\end{verbatim}\n", + "Left division operator: multiplication of \\texttt{y} by the inverse of \\texttt{x} on the left. Gives floating-point results for integer arguments.\n", + "\n", + "\\section{Examples}\n", + "\\begin{verbatim}\n", + "julia> 3 \\ 6\n", + "2.0\n", + "\n", + "julia> inv(3) * 6\n", + "2.0\n", + "\n", + "julia> A = [4 3; 2 1]; x = [5, 6];\n", + "\n", + "julia> A \\ x\n", + "2-element Array{Float64,1}:\n", + " 6.5\n", + " -7.0\n", + "\n", + "julia> inv(A) * x\n", + "2-element Array{Float64,1}:\n", + " 6.5\n", + " -7.0\n", + "\\end{verbatim}\n", + "\\rule{\\textwidth}{1pt}\n", + "\\begin{verbatim}\n", + "\\(A, B)\n", + "\\end{verbatim}\n", + "Matrix division using a polyalgorithm. For input matrices \\texttt{A} and \\texttt{B}, the result \\texttt{X} is such that \\texttt{A*X == B} when \\texttt{A} is square. The solver that is used depends upon the structure of \\texttt{A}. If \\texttt{A} is upper or lower triangular (or diagonal), no factorization of \\texttt{A} is required and the system is solved with either forward or backward substitution. For non-triangular square matrices, an LU factorization is used.\n", + "\n", + "For rectangular \\texttt{A} the result is the minimum-norm least squares solution computed by a pivoted QR factorization of \\texttt{A} and a rank estimate of \\texttt{A} based on the R factor.\n", + "\n", + "When \\texttt{A} is sparse, a similar polyalgorithm is used. For indefinite matrices, the \\texttt{LDLt} factorization does not use pivoting during the numerical factorization and therefore the procedure can fail even for invertible matrices.\n", + "\n", + "\\section{Examples}\n", + "\\begin{verbatim}\n", + "julia> A = [1 0; 1 -2]; B = [32; -4];\n", + "\n", + "julia> X = A \\ B\n", + "2-element Array{Float64,1}:\n", + " 32.0\n", + " 18.0\n", + "\n", + "julia> A * X == B\n", + "true\n", + "\\end{verbatim}\n", + "\\rule{\\textwidth}{1pt}\n", + "\\begin{verbatim}\n", + "(\\)(F::QRSparse, B::StridedVecOrMat)\n", + "\\end{verbatim}\n", + "Solve the least squares problem $\\min\\|Ax - b\\|^2$ or the linear system of equations $Ax=b$ when \\texttt{F} is the sparse QR factorization of $A$. A basic solution is returned when the problem is underdetermined.\n", + "\n", + "\\section{Examples}\n", + "\\begin{verbatim}\n", + "julia> A = sparse([1,2,4], [1,1,1], [1.0,1.0,1.0], 4, 2)\n", + "4×2 SparseMatrixCSC{Float64,Int64} with 3 stored entries:\n", + " [1, 1] = 1.0\n", + " [2, 1] = 1.0\n", + " [4, 1] = 1.0\n", + "\n", + "julia> qr(A)\\fill(1.0, 4)\n", + "2-element Array{Float64,1}:\n", + " 1.0\n", + " 0.0\n", + "\\end{verbatim}\n" + ], + "text/markdown": [ + "```\n", + "\\(x, y)\n", + "```\n", + "\n", + "Left division operator: multiplication of `y` by the inverse of `x` on the left. Gives floating-point results for integer arguments.\n", + "\n", + "# Examples\n", + "\n", + "```jldoctest\n", + "julia> 3 \\ 6\n", + "2.0\n", + "\n", + "julia> inv(3) * 6\n", + "2.0\n", + "\n", + "julia> A = [4 3; 2 1]; x = [5, 6];\n", + "\n", + "julia> A \\ x\n", + "2-element Array{Float64,1}:\n", + " 6.5\n", + " -7.0\n", + "\n", + "julia> inv(A) * x\n", + "2-element Array{Float64,1}:\n", + " 6.5\n", + " -7.0\n", + "```\n", + "\n", + "---\n", + "\n", + "```\n", + "\\(A, B)\n", + "```\n", + "\n", + "Matrix division using a polyalgorithm. For input matrices `A` and `B`, the result `X` is such that `A*X == B` when `A` is square. The solver that is used depends upon the structure of `A`. If `A` is upper or lower triangular (or diagonal), no factorization of `A` is required and the system is solved with either forward or backward substitution. For non-triangular square matrices, an LU factorization is used.\n", + "\n", + "For rectangular `A` the result is the minimum-norm least squares solution computed by a pivoted QR factorization of `A` and a rank estimate of `A` based on the R factor.\n", + "\n", + "When `A` is sparse, a similar polyalgorithm is used. For indefinite matrices, the `LDLt` factorization does not use pivoting during the numerical factorization and therefore the procedure can fail even for invertible matrices.\n", + "\n", + "# Examples\n", + "\n", + "```jldoctest\n", + "julia> A = [1 0; 1 -2]; B = [32; -4];\n", + "\n", + "julia> X = A \\ B\n", + "2-element Array{Float64,1}:\n", + " 32.0\n", + " 18.0\n", + "\n", + "julia> A * X == B\n", + "true\n", + "```\n", + "\n", + "---\n", + "\n", + "```\n", + "(\\)(F::QRSparse, B::StridedVecOrMat)\n", + "```\n", + "\n", + "Solve the least squares problem $\\min\\|Ax - b\\|^2$ or the linear system of equations $Ax=b$ when `F` is the sparse QR factorization of $A$. A basic solution is returned when the problem is underdetermined.\n", + "\n", + "# Examples\n", + "\n", + "```jldoctest\n", + "julia> A = sparse([1,2,4], [1,1,1], [1.0,1.0,1.0], 4, 2)\n", + "4×2 SparseMatrixCSC{Float64,Int64} with 3 stored entries:\n", + " [1, 1] = 1.0\n", + " [2, 1] = 1.0\n", + " [4, 1] = 1.0\n", + "\n", + "julia> qr(A)\\fill(1.0, 4)\n", + "2-element Array{Float64,1}:\n", + " 1.0\n", + " 0.0\n", + "```\n" + ], + "text/plain": [ + "\u001b[36m \\(x, y)\u001b[39m\n", + "\n", + " Left division operator: multiplication of \u001b[36my\u001b[39m by the inverse of \u001b[36mx\u001b[39m on the left.\n", + " Gives floating-point results for integer arguments.\n", + "\n", + "\u001b[1m Examples\u001b[22m\n", + "\u001b[1m ≡≡≡≡≡≡≡≡≡≡\u001b[22m\n", + "\n", + "\u001b[36m julia> 3 \\ 6\u001b[39m\n", + "\u001b[36m 2.0\u001b[39m\n", + "\u001b[36m \u001b[39m\n", + "\u001b[36m julia> inv(3) * 6\u001b[39m\n", + "\u001b[36m 2.0\u001b[39m\n", + "\u001b[36m \u001b[39m\n", + "\u001b[36m julia> A = [4 3; 2 1]; x = [5, 6];\u001b[39m\n", + "\u001b[36m \u001b[39m\n", + "\u001b[36m julia> A \\ x\u001b[39m\n", + "\u001b[36m 2-element Array{Float64,1}:\u001b[39m\n", + "\u001b[36m 6.5\u001b[39m\n", + "\u001b[36m -7.0\u001b[39m\n", + "\u001b[36m \u001b[39m\n", + "\u001b[36m julia> inv(A) * x\u001b[39m\n", + "\u001b[36m 2-element Array{Float64,1}:\u001b[39m\n", + "\u001b[36m 6.5\u001b[39m\n", + "\u001b[36m -7.0\u001b[39m\n", + "\n", + " ────────────────────────────────────────────────────────────────────────────\n", + "\n", + "\u001b[36m \\(A, B)\u001b[39m\n", + "\n", + " Matrix division using a polyalgorithm. For input matrices \u001b[36mA\u001b[39m and \u001b[36mB\u001b[39m, the\n", + " result \u001b[36mX\u001b[39m is such that \u001b[36mA*X == B\u001b[39m when \u001b[36mA\u001b[39m is square. The solver that is used\n", + " depends upon the structure of \u001b[36mA\u001b[39m. If \u001b[36mA\u001b[39m is upper or lower triangular (or\n", + " diagonal), no factorization of \u001b[36mA\u001b[39m is required and the system is solved with\n", + " either forward or backward substitution. For non-triangular square matrices,\n", + " an LU factorization is used.\n", + "\n", + " For rectangular \u001b[36mA\u001b[39m the result is the minimum-norm least squares solution\n", + " computed by a pivoted QR factorization of \u001b[36mA\u001b[39m and a rank estimate of \u001b[36mA\u001b[39m based\n", + " on the R factor.\n", + "\n", + " When \u001b[36mA\u001b[39m is sparse, a similar polyalgorithm is used. For indefinite matrices,\n", + " the \u001b[36mLDLt\u001b[39m factorization does not use pivoting during the numerical\n", + " factorization and therefore the procedure can fail even for invertible\n", + " matrices.\n", + "\n", + "\u001b[1m Examples\u001b[22m\n", + "\u001b[1m ≡≡≡≡≡≡≡≡≡≡\u001b[22m\n", + "\n", + "\u001b[36m julia> A = [1 0; 1 -2]; B = [32; -4];\u001b[39m\n", + "\u001b[36m \u001b[39m\n", + "\u001b[36m julia> X = A \\ B\u001b[39m\n", + "\u001b[36m 2-element Array{Float64,1}:\u001b[39m\n", + "\u001b[36m 32.0\u001b[39m\n", + "\u001b[36m 18.0\u001b[39m\n", + "\u001b[36m \u001b[39m\n", + "\u001b[36m julia> A * X == B\u001b[39m\n", + "\u001b[36m true\u001b[39m\n", + "\n", + " ────────────────────────────────────────────────────────────────────────────\n", + "\n", + "\u001b[36m (\\)(F::QRSparse, B::StridedVecOrMat)\u001b[39m\n", + "\n", + " Solve the least squares problem \u001b[35m\\min\\|Ax - b\\|^2\u001b[39m or the linear system of\n", + " equations \u001b[35mAx=b\u001b[39m when \u001b[36mF\u001b[39m is the sparse QR factorization of \u001b[35mA\u001b[39m. A basic solution\n", + " is returned when the problem is underdetermined.\n", + "\n", + "\u001b[1m Examples\u001b[22m\n", + "\u001b[1m ≡≡≡≡≡≡≡≡≡≡\u001b[22m\n", + "\n", + "\u001b[36m julia> A = sparse([1,2,4], [1,1,1], [1.0,1.0,1.0], 4, 2)\u001b[39m\n", + "\u001b[36m 4×2 SparseMatrixCSC{Float64,Int64} with 3 stored entries:\u001b[39m\n", + "\u001b[36m [1, 1] = 1.0\u001b[39m\n", + "\u001b[36m [2, 1] = 1.0\u001b[39m\n", + "\u001b[36m [4, 1] = 1.0\u001b[39m\n", + "\u001b[36m \u001b[39m\n", + "\u001b[36m julia> qr(A)\\fill(1.0, 4)\u001b[39m\n", + "\u001b[36m 2-element Array{Float64,1}:\u001b[39m\n", + "\u001b[36m 1.0\u001b[39m\n", + "\u001b[36m 0.0\u001b[39m" + ] + }, + "execution_count": 35, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "? \\" + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "84.0" + ] + }, + "execution_count": 36, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "5040/60" + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "addone (generic function with 1 method)" + ] + }, + "execution_count": 38, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "addone(x::Int64) = x+1" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "metadata": {}, + "outputs": [ + { + "ename": "MethodError", + "evalue": "MethodError: no method matching addone(::Float64)\nClosest candidates are:\n addone(!Matched::Int64) at In[38]:1", + "output_type": "error", + "traceback": [ + "MethodError: no method matching addone(::Float64)\nClosest candidates are:\n addone(!Matched::Int64) at In[38]:1", + "", + "Stacktrace:", + " [1] top-level scope at In[42]:1" + ] + } + ], + "source": [ + "addone(ceil(1.2)*10)" + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(1, 2)" + ] + }, + "execution_count": 43, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a,b=1,2" + ] + }, + { + "cell_type": "code", + "execution_count": 44, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(2, 1)" + ] + }, + "execution_count": 44, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a,b=b,a" + ] + }, + { + "cell_type": "code", + "execution_count": 46, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "2" + ] + }, + "execution_count": 46, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a" + ] + }, + { + "cell_type": "code", + "execution_count": 47, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "22\n" + ] + } + ], + "source": [ + "function test(input)\n", + " println(\"$input\"^2)\n", + "end\n", + "\n", + "test(2)" + ] + }, + { + "cell_type": "code", + "execution_count": 48, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "22\n" + ] + }, + { + "data": { + "text/plain": [ + "Nothing" + ] + }, + "execution_count": 48, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "typeof(test(2))" + ] + }, + { + "cell_type": "code", + "execution_count": 56, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "add2 (generic function with 1 method)" + ] + }, + "execution_count": 56, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "add2(x,y) = return x + y" + ] + }, + { + "cell_type": "code", + "execution_count": 57, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "12\n" + ] + } + ], + "source": [ + "println(add2(5, 7))" + ] + }, + { + "cell_type": "code", + "execution_count": 58, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "coordinates (generic function with 3 methods)" + ] + }, + "execution_count": 58, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "function coordinates(x, y=0, z=0)\n", + " println(\"($x, $y, $z)\")\n", + "end" + ] + }, + { + "cell_type": "code", + "execution_count": 59, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "(1, 0, 2)\n" + ] + } + ], + "source": [ + "coordinates(1,0,2)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Julia 1.2.0", + "language": "julia", + "name": "julia-1.2" + }, + "language_info": { + "file_extension": ".jl", + "mimetype": "application/julia", + "name": "julia", + "version": "1.2.0" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/05_Coursera_1.ipynb b/05_Coursera_1.ipynb new file mode 100644 index 0000000..1f1f18b --- /dev/null +++ b/05_Coursera_1.ipynb @@ -0,0 +1,505 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "36" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "3^2^1^5+3^3" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "Int64" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "typeof(3^2^1^5+3^3)" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "36\n" + ] + } + ], + "source": [ + "println(\"$(6*6)\")" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "36\n" + ] + }, + { + "data": { + "text/plain": [ + "Nothing" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "typeof(println(\"$(6*6)\"))" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "240" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "2^2^3-2^4" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "48" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "(2^2)^3-2^4" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "(5 - 7) * 2 + 4" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "false" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "1 + 3 < 5 && 2^2 === 4.0" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "false" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "2^2 === 4.0" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "false" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "x = 4\n", + "\n", + "x > 0 && x <= 3" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "true" + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "((true && false) && false) || true" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "false" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "(true && false) && (false || true)" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "true" + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "true && ((false && false) || true)" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "15×2 Array{Float64,2}:\n", + " 1.68005 -1.6417 \n", + " 0.501309 -0.977698\n", + " 1.52801 0.527711\n", + " 1.70012 1.71152 \n", + " 1.99249 1.891 \n", + " 2.70608 -0.463428\n", + " 2.99493 -0.443567\n", + " 3.49185 -1.27518 \n", + " 3.50119 -0.6905 \n", + " 4.45992 -5.51613 \n", + " 4.93697 -6.0017 \n", + " 5.02329 -8.36417 \n", + " 5.04234 -7.92448 \n", + " 5.50739 -10.7748 \n", + " 5.56867 -10.9172 " + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "data = [1.6800483 -1.641695388; \n", + " 0.501309281 -0.977697538; \n", + " 1.528012113 0.52771122;\n", + " 1.70012253 1.711524991; \n", + " 1.992493625 1.891000015;\n", + " 2.706075824 -0.463427794;\n", + " 2.994931927 -0.443566619;\n", + " 3.491852811 -1.275179133;\n", + " 3.501191722 -0.690499597;\n", + " 4.459924502 -5.516130799;\n", + " 4.936965851 -6.001703074;\n", + " 5.023289852 -8.36416901;\n", + " 5.04233698 -7.924477517;\n", + " 5.50739285 -10.77482371;\n", + " 5.568665171 -10.9171878]" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "15-element Array{Float64,1}:\n", + " 1.6800483 \n", + " 0.501309281\n", + " 1.528012113\n", + " 1.70012253 \n", + " 1.992493625\n", + " 2.706075824\n", + " 2.994931927\n", + " 3.491852811\n", + " 3.501191722\n", + " 4.459924502\n", + " 4.936965851\n", + " 5.023289852\n", + " 5.04233698 \n", + " 5.50739285 \n", + " 5.568665171" + ] + }, + "execution_count": 25, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "data[:,1]" + ] + }, + { + "cell_type": "code", + "execution_count": 44, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "coordinates (generic function with 1 method)" + ] + }, + "execution_count": 44, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "function coordinates(x, y, z)\n", + " if x==0 && z == 0 && y==0\n", + " println(\"origin\")\n", + " else\n", + " println(\"($x, $y, $z)\")\n", + " end\n", + "end" + ] + }, + { + "cell_type": "code", + "execution_count": 45, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "(0, 0, 2)\n" + ] + } + ], + "source": [ + "coordinates(0,0,2)" + ] + }, + { + "cell_type": "code", + "execution_count": 46, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "origin\n" + ] + } + ], + "source": [ + "coordinates(0,0,0)" + ] + }, + { + "cell_type": "code", + "execution_count": 47, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(19, 3)" + ] + }, + "execution_count": 47, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a, b = 2, 3 \n", + "function f(x) \n", + " b = 5 \n", + " a*x + b\n", + "end\n", + "f(7), b" + ] + }, + { + "cell_type": "code", + "execution_count": 50, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "f (generic function with 1 method)" + ] + }, + "execution_count": 50, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "function f(x)\n", + " return 2x\n", + " 3x\n", + " print(\"5\")\n", + "end" + ] + }, + { + "cell_type": "code", + "execution_count": 51, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "10" + ] + }, + "execution_count": 51, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "f(5)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Julia 1.2.0", + "language": "julia", + "name": "julia-1.2" + }, + "language_info": { + "file_extension": ".jl", + "mimetype": "application/julia", + "name": "julia", + "version": "1.2.0" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +}