{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Eliminate from (general) A to (upper triangular) U" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Demonstrate Gaussian Elimination (page 51 of GS)\n", "\n", "(Reminder: Julia programming syntax will not be tested in this class, but that doesn't mean you can't learn from watching the code being executed)" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "using Plots" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "lookat (generic function with 1 method)" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# nice viz for matrices\n", "function lookat(A; redrow=0, rounding=2, showtext=true)\n", " n = size(A,1)\n", " plot(legend=false, axis=false)\n", " rowcolor = redrow > 0 ? :red : :black \n", " for i=1:n, j=1:n \n", " scatter!( [j],[i], ann= showtext ? (j,i,round(A[i,j],digits=rounding), :white ) : (j,i,\"\") ,\n", " color=abs(A[i,j]) > .0001 ? (i==redrow ? rowcolor : :black) : :white, \n", " marker=:square, markersize=30, aspectratio=1, yflip=true, yaxis=[.5,n+.5],xaxis=[.5,n+.5])\n", " end\n", " plot!()\n", "end" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "4×4 Array{Float64,2}:\n", " 2.0 12.0 4.0 7.0\n", " 29.0 12.0 69.0 24.0\n", " 7.0 7.0 7.0 7.0\n", " 3.0 7.0 5.0 2.0" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "A = [2 12 4 7; 29 12 69 24 ; 7 7 7 7; 3 7 5 2]\n", "A = A*1.0" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "2.0\n", "\n", "\n", "12.0\n", "\n", "\n", "4.0\n", "\n", "\n", "7.0\n", "\n", "\n", "29.0\n", "\n", "\n", "12.0\n", "\n", "\n", "69.0\n", "\n", "\n", "24.0\n", "\n", "\n", "7.0\n", "\n", "\n", "7.0\n", "\n", "\n", "7.0\n", "\n", "\n", "7.0\n", "\n", "\n", "3.0\n", "\n", "\n", "7.0\n", "\n", "\n", "5.0\n", "\n", "\n", "2.0\n", "\n", "\n" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "lookat(A)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## What multiple of the first row must i subtract from the second row to zero out the (2,1) entry?" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "4×4 Array{Float64,2}:\n", " 0.0 0.0 0.0 0.0\n", " 0.0 0.0 0.0 0.0\n", " 0.0 0.0 0.0 0.0\n", " 0.0 0.0 0.0 0.0" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "L = fill(0.0, 4,4)" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "14.5" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "L[2,1] = A[2,1]/A[1,1]" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "2.0\n", "\n", "\n", "12.0\n", "\n", "\n", "4.0\n", "\n", "\n", "7.0\n", "\n", "\n", "0.0\n", "\n", "\n", "-162.0\n", "\n", "\n", "11.0\n", "\n", "\n", "-77.5\n", "\n", "\n", "7.0\n", "\n", "\n", "7.0\n", "\n", "\n", "7.0\n", "\n", "\n", "7.0\n", "\n", "\n", "3.0\n", "\n", "\n", "7.0\n", "\n", "\n", "5.0\n", "\n", "\n", "2.0\n", "\n", "\n" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "A[2,:] -= L[2,1]*A[1,:]; # subtract the multiplier times the first row from the second row\n", "lookat(A, redrow=2)" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "3.5" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "L[3,1] = A[3,1]/A[1,1] # the diagonal entry that we divide by is called the \"pivot\"" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "2.0\n", "\n", "\n", "12.0\n", "\n", "\n", "4.0\n", "\n", "\n", "7.0\n", "\n", "\n", "0.0\n", "\n", "\n", "-162.0\n", "\n", "\n", "11.0\n", "\n", "\n", "-77.5\n", "\n", "\n", "0.0\n", "\n", "\n", "-35.0\n", "\n", "\n", "-7.0\n", "\n", "\n", "-17.5\n", "\n", "\n", "3.0\n", "\n", "\n", "7.0\n", "\n", "\n", "5.0\n", "\n", "\n", "2.0\n", "\n", "\n" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "A[3,:] -= L[3,1]*A[1,:]; # subtract the multiplier times the first row from the second row\n", "lookat(A, redrow=3)" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "2.0\n", "\n", "\n", "12.0\n", "\n", "\n", "4.0\n", "\n", "\n", "7.0\n", "\n", "\n", "0.0\n", "\n", "\n", "-162.0\n", "\n", "\n", "11.0\n", "\n", "\n", "-77.5\n", "\n", "\n", "0.0\n", "\n", "\n", "-35.0\n", "\n", "\n", "-7.0\n", "\n", "\n", "-17.5\n", "\n", "\n", "0.0\n", "\n", "\n", "-11.0\n", "\n", "\n", "-1.0\n", "\n", "\n", "-8.5\n", "\n", "\n" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "L[4,1] = A[4,1]/A[1,1] \n", "A[4,:] -= L[4,1]*A[1,:]; # subtract the multiplier times the first row from the second row\n", "lookat(A, redrow=4)" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "2.0\n", "\n", "\n", "12.0\n", "\n", "\n", "4.0\n", "\n", "\n", "7.0\n", "\n", "\n", "0.0\n", "\n", "\n", "-162.0\n", "\n", "\n", "11.0\n", "\n", "\n", "-77.5\n", "\n", "\n", "0.0\n", "\n", "\n", "0.0\n", "\n", "\n", "-9.38\n", "\n", "\n", "-0.76\n", "\n", "\n", "0.0\n", "\n", "\n", "-11.0\n", "\n", "\n", "-1.0\n", "\n", "\n", "-8.5\n", "\n", "\n" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "L[3,2] = A[3,2]/A[2,2] \n", "A[3,:] -= L[3,2]*A[2,:]; # subtract the multiplier times the first row from the second row\n", "lookat(A, redrow=3)" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "2.0\n", "\n", "\n", "12.0\n", "\n", "\n", "4.0\n", "\n", "\n", "7.0\n", "\n", "\n", "0.0\n", "\n", "\n", "-162.0\n", "\n", "\n", "11.0\n", "\n", "\n", "-77.5\n", "\n", "\n", "0.0\n", "\n", "\n", "0.0\n", "\n", "\n", "-9.38\n", "\n", "\n", "-0.76\n", "\n", "\n", "0.0\n", "\n", "\n", "0.0\n", "\n", "\n", "-1.75\n", "\n", "\n", "-3.24\n", "\n", "\n" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "L[4,2] = A[4,2]/A[2,2] \n", "A[4,:] -= L[4,2]*A[2,:]; # subtract the multiplier times the first row from the second row\n", "lookat(A, redrow=4)" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", " \n", " \n", " \n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "2.0\n", "\n", "\n", "12.0\n", "\n", "\n", "4.0\n", "\n", "\n", "7.0\n", "\n", "\n", "0.0\n", "\n", "\n", "-162.0\n", "\n", "\n", "11.0\n", "\n", "\n", "-77.5\n", "\n", "\n", "0.0\n", "\n", "\n", "0.0\n", "\n", "\n", "-9.38\n", "\n", "\n", "-0.76\n", "\n", "\n", "0.0\n", "\n", "\n", "0.0\n", "\n", "\n", "0.0\n", "\n", "\n", "-3.1\n", "\n", "\n" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "L[4,3] = A[4,3]/A[3,3] \n", "A[4,:] -= L[4,3]*A[3,:]; # subtract the multiplier times the first row from the second row\n", "lookat(A, redrow=4)" ] }, { "cell_type": "code", "execution_count": 27, "metadata": {}, "outputs": [], "source": [ "n = 6\n", "A = rand(n,n)\n", "keepA = [copy(A)]\n", "row = [0]\n", "L = fill(0.0,n,n)\n", "for j=1:n, i=j+1:n\n", " L[i,j] = A[i,j] / A[j,j]\n", " A[i,:] -= L[i,j] * A[j,:]\n", " push!(keepA,copy(A))\n", " push!(row,i)\n", "end" ] }, { "cell_type": "code", "execution_count": 28, "metadata": {}, "outputs": [], "source": [ "using Interact" ] }, { "cell_type": "code", "execution_count": 29, "metadata": {}, "outputs": [ { "data": { "application/vnd.webio.node+json": { "children": [ { "children": [ { "children": [ { "children": [ { "children": [ { "children": [ "i" ], "instanceArgs": { "namespace": "html", "tag": "label" }, "nodeType": "DOM", "props": { "className": "interact ", "style": { "padding": "5px 10px 0px 10px" } }, "type": "node" } ], "instanceArgs": { "namespace": "html", "tag": "div" }, "nodeType": "DOM", "props": { "className": "interact-flex-row-left" }, "type": "node" }, { "children": [ { "children": [], "instanceArgs": { "namespace": "html", "tag": "input" }, "nodeType": "DOM", "props": { "attributes": { "data-bind": "numericValue: index, valueUpdate: 'input', event: {change: function (){this.changes(this.changes()+1)}}", "orient": "horizontal", "type": "range" }, "className": "slider slider is-fullwidth", "max": 16, "min": 1, "step": 1, "style": {} }, "type": "node" } ], "instanceArgs": { "namespace": "html", "tag": "div" }, "nodeType": "DOM", "props": { "className": "interact-flex-row-center" }, "type": "node" }, { "children": [ { "children": [], "instanceArgs": { "namespace": "html", "tag": "p" }, "nodeType": "DOM", "props": { "attributes": { "data-bind": "text: formatted_val" } }, "type": "node" } ], "instanceArgs": { "namespace": "html", "tag": "div" }, "nodeType": "DOM", "props": { "className": "interact-flex-row-right" }, "type": "node" } ], "instanceArgs": { "namespace": "html", "tag": "div" }, "nodeType": "DOM", "props": { "className": "interact-flex-row interact-widget" }, "type": "node" } ], "instanceArgs": { "handlers": { "changes": [ "(function (val){return (val!=this.model[\"changes\"]()) ? (this.valueFromJulia[\"changes\"]=true, this.model[\"changes\"](val)) : undefined})" ], "index": [ "(function (val){return (val!=this.model[\"index\"]()) ? (this.valueFromJulia[\"index\"]=true, this.model[\"index\"](val)) : undefined})" ] }, "id": "12019567677823032763", "imports": { "data": [ { "name": "knockout", "type": "js", "url": "/assetserver/2618192f019dfcc40a9013ef31cb09a511d8ea26-knockout.js" }, { "name": "knockout_punches", "type": "js", "url": "/assetserver/df29ad18e8884e98d1d36dd0c339f642f729bf96-knockout_punches.js" }, { "name": null, "type": "js", "url": "/assetserver/860bb4a9e1927248d6fb4a7d59e926f541e3bfc2-all.js" }, { "name": null, "type": "css", "url": "/assetserver/4b164c07c3632d5e274899a8ab8726c70dab4aff-style.css" }, { "name": null, "type": "css", "url": "/assetserver/67252656a23d4f0f6f4ba7ab8e8eb9ffc4ae9b5d-bulma_confined.min.css" } ], "type": "async_block" }, "mount_callbacks": [ "function () {\n var handler = (function (ko, koPunches) {\n ko.punches.enableAll();\n ko.bindingHandlers.numericValue = {\n init: function(element, valueAccessor, allBindings, data, context) {\n var stringified = ko.observable(ko.unwrap(valueAccessor()));\n stringified.subscribe(function(value) {\n var val = parseFloat(value);\n if (!isNaN(val)) {\n valueAccessor()(val);\n }\n });\n valueAccessor().subscribe(function(value) {\n var str = JSON.stringify(value);\n if ((str == \"0\") && ([\"-0\", \"-0.\"].indexOf(stringified()) >= 0))\n return;\n if ([\"null\", \"\"].indexOf(str) >= 0)\n return;\n stringified(str);\n });\n ko.applyBindingsToNode(\n element,\n {\n value: stringified,\n valueUpdate: allBindings.get('valueUpdate'),\n },\n context,\n );\n }\n };\n var json_data = {\"formatted_vals\":[\"1\",\"2\",\"3\",\"4\",\"5\",\"6\",\"7\",\"8\",\"9\",\"10\",\"11\",\"12\",\"13\",\"14\",\"15\",\"16\"],\"changes\":WebIO.getval({\"name\":\"changes\",\"scope\":\"12019567677823032763\",\"id\":\"ob_18\",\"type\":\"observable\"}),\"index\":WebIO.getval({\"name\":\"index\",\"scope\":\"12019567677823032763\",\"id\":\"ob_17\",\"type\":\"observable\"})};\n var self = this;\n function AppViewModel() {\n for (var key in json_data) {\n var el = json_data[key];\n this[key] = Array.isArray(el) ? ko.observableArray(el) : ko.observable(el);\n }\n \n [this[\"formatted_val\"]=ko.computed( function(){\n return this.formatted_vals()[parseInt(this.index())-(1)];\n }\n,this)]\n [this[\"changes\"].subscribe((function (val){!(this.valueFromJulia[\"changes\"]) ? (WebIO.setval({\"name\":\"changes\",\"scope\":\"12019567677823032763\",\"id\":\"ob_18\",\"type\":\"observable\"},val)) : undefined; return this.valueFromJulia[\"changes\"]=false}),self),this[\"index\"].subscribe((function (val){!(this.valueFromJulia[\"index\"]) ? (WebIO.setval({\"name\":\"index\",\"scope\":\"12019567677823032763\",\"id\":\"ob_17\",\"type\":\"observable\"},val)) : undefined; return this.valueFromJulia[\"index\"]=false}),self)]\n \n }\n self.model = new AppViewModel();\n self.valueFromJulia = {};\n for (var key in json_data) {\n self.valueFromJulia[key] = false;\n }\n ko.applyBindings(self.model, self.dom);\n}\n);\n (WebIO.importBlock({\"data\":[{\"name\":\"knockout\",\"type\":\"js\",\"url\":\"/assetserver/2618192f019dfcc40a9013ef31cb09a511d8ea26-knockout.js\"},{\"name\":\"knockout_punches\",\"type\":\"js\",\"url\":\"/assetserver/df29ad18e8884e98d1d36dd0c339f642f729bf96-knockout_punches.js\"}],\"type\":\"async_block\"})).then((imports) => handler.apply(this, imports));\n}\n" ], "observables": { "changes": { "id": "ob_18", "sync": false, "value": 0 }, "index": { "id": "ob_17", "sync": true, "value": 8 } }, "systemjs_options": null }, "nodeType": "Scope", "props": {}, "type": "node" } ], "instanceArgs": { "namespace": "html", "tag": "div" }, "nodeType": "DOM", "props": { "className": "field interact-widget" }, "type": "node" }, { "children": [ { "children": [], "instanceArgs": { "id": "ob_24", "name": "obs-node" }, "nodeType": "ObservableNode", "props": {}, "type": "node" } ], "instanceArgs": { "handlers": {}, "id": "4433206657539994618", "imports": { "data": [], "type": "async_block" }, "mount_callbacks": [], "observables": { "obs-node": { "id": "ob_24", "sync": false, "value": { "children": [ { "children": [], "instanceArgs": { "namespace": "html", "tag": "div" }, "nodeType": "DOM", "props": { "setInnerHtml": "\n\n\n \n \n \n\n\n\n \n \n \n\n\n\n \n \n \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n0.6\n\n\n0.72\n\n\n0.05\n\n\n0.66\n\n\n0.18\n\n\n0.86\n\n\n-0.0\n\n\n0.06\n\n\n0.93\n\n\n0.2\n\n\n0.73\n\n\n-0.18\n\n\n-0.0\n\n\n0.0\n\n\n0.4\n\n\n0.23\n\n\n1.2\n\n\n-0.04\n\n\n0.0\n\n\n0.0\n\n\n-5.25\n\n\n-0.81\n\n\n-4.35\n\n\n1.33\n\n\n0.0\n\n\n-0.35\n\n\n-0.0\n\n\n-0.45\n\n\n0.51\n\n\n-0.89\n\n\n0.0\n\n\n-0.28\n\n\n0.03\n\n\n-0.28\n\n\n0.7\n\n\n0.51\n\n\n" }, "type": "node" } ], "instanceArgs": { "namespace": "html", "tag": "div" }, "nodeType": "DOM", "props": { "className": "interact-flex-row interact-widget" }, "type": "node" } } }, "systemjs_options": null }, "nodeType": "Scope", "props": {}, "type": "node" } ], "instanceArgs": { "namespace": "html", "tag": "div" }, "nodeType": "DOM", "props": {}, "type": "node" }, "text/html": [ "\n", " \n", "\n" ], "text/plain": [ "Node{WebIO.DOM}(WebIO.DOM(:html, :div), Any[Node{WebIO.DOM}(WebIO.DOM(:html, :div), Any[Scope(Node{WebIO.DOM}(WebIO.DOM(:html, :div), Any[Node{WebIO.DOM}(WebIO.DOM(:html, :div), Any[Node{WebIO.DOM}(WebIO.DOM(:html, :label), Any[\"i\"], Dict{Symbol,Any}(:className => \"interact \",:style => Dict{Any,Any}(:padding => \"5px 10px 0px 10px\")))], Dict{Symbol,Any}(:className => \"interact-flex-row-left\")), Node{WebIO.DOM}(WebIO.DOM(:html, :div), Any[Node{WebIO.DOM}(WebIO.DOM(:html, :input), Any[], Dict{Symbol,Any}(:max => 16,:min => 1,:attributes => Dict{Any,Any}(:type => \"range\",Symbol(\"data-bind\") => \"numericValue: index, valueUpdate: 'input', event: {change: function (){this.changes(this.changes()+1)}}\",\"orient\" => \"horizontal\"),:step => 1,:className => \"slider slider is-fullwidth\",:style => Dict{Any,Any}()))], Dict{Symbol,Any}(:className => \"interact-flex-row-center\")), Node{WebIO.DOM}(WebIO.DOM(:html, :div), Any[Node{WebIO.DOM}(WebIO.DOM(:html, :p), Any[], Dict{Symbol,Any}(:attributes => Dict(\"data-bind\" => \"text: formatted_val\")))], Dict{Symbol,Any}(:className => \"interact-flex-row-right\"))], Dict{Symbol,Any}(:className => \"interact-flex-row interact-widget\")), Dict{String,Tuple{Observables.AbstractObservable,Union{Nothing, Bool}}}(\"changes\" => (Observable{Int64} with 1 listeners. Value:\n", "0, nothing),\"index\" => (Observable{Int64} with 2 listeners. Value:\n", "8, nothing)), Set(String[]), nothing, Asset[Asset(\"js\", \"knockout\", \"/Users/alanedelman/.julia/packages/Knockout/1sDlc/src/../assets/knockout.js\"), Asset(\"js\", \"knockout_punches\", \"/Users/alanedelman/.julia/packages/Knockout/1sDlc/src/../assets/knockout_punches.js\"), Asset(\"js\", nothing, \"/Users/alanedelman/.julia/packages/InteractBase/9mFwe/src/../assets/all.js\"), Asset(\"css\", nothing, \"/Users/alanedelman/.julia/packages/InteractBase/9mFwe/src/../assets/style.css\"), Asset(\"css\", nothing, \"/Users/alanedelman/.julia/packages/Interact/SbgIk/src/../assets/bulma_confined.min.css\")], Dict{Any,Any}(\"changes\" => Any[WebIO.JSString(\"(function (val){return (val!=this.model[\\\"changes\\\"]()) ? (this.valueFromJulia[\\\"changes\\\"]=true, this.model[\\\"changes\\\"](val)) : undefined})\")],\"index\" => Any[WebIO.JSString(\"(function (val){return (val!=this.model[\\\"index\\\"]()) ? (this.valueFromJulia[\\\"index\\\"]=true, this.model[\\\"index\\\"](val)) : undefined})\")]), WebIO.ConnectionPool(Channel{Any}(sz_max:32,sz_curr:0), Set(AbstractConnection[]), Base.GenericCondition{Base.AlwaysLockedST}(Base.InvasiveLinkedList{Task}(Task (runnable) @0x000000011760e650, Task (runnable) @0x000000011760e650), Base.AlwaysLockedST(1))), WebIO.JSString[WebIO.JSString(\"function () {\\n var handler = (function (ko, koPunches) {\\n ko.punches.enableAll();\\n ko.bindingHandlers.numericValue = {\\n init: function(element, valueAccessor, allBindings, data, context) {\\n var stringified = ko.observable(ko.unwrap(valueAccessor()));\\n stringified.subscribe(function(value) {\\n var val = parseFloat(value);\\n if (!isNaN(val)) {\\n valueAccessor()(val);\\n }\\n });\\n valueAccessor().subscribe(function(value) {\\n var str = JSON.stringify(value);\\n if ((str == \\\"0\\\") && ([\\\"-0\\\", \\\"-0.\\\"].indexOf(stringified()) >= 0))\\n return;\\n if ([\\\"null\\\", \\\"\\\"].indexOf(str) >= 0)\\n return;\\n stringified(str);\\n });\\n ko.applyBindingsToNode(\\n element,\\n {\\n value: stringified,\\n valueUpdate: allBindings.get('valueUpdate'),\\n },\\n context,\\n );\\n }\\n };\\n var json_data = {\\\"formatted_vals\\\":[\\\"1\\\",\\\"2\\\",\\\"3\\\",\\\"4\\\",\\\"5\\\",\\\"6\\\",\\\"7\\\",\\\"8\\\",\\\"9\\\",\\\"10\\\",\\\"11\\\",\\\"12\\\",\\\"13\\\",\\\"14\\\",\\\"15\\\",\\\"16\\\"],\\\"changes\\\":WebIO.getval({\\\"name\\\":\\\"changes\\\",\\\"scope\\\":\\\"12019567677823032763\\\",\\\"id\\\":\\\"ob_18\\\",\\\"type\\\":\\\"observable\\\"}),\\\"index\\\":WebIO.getval({\\\"name\\\":\\\"index\\\",\\\"scope\\\":\\\"12019567677823032763\\\",\\\"id\\\":\\\"ob_17\\\",\\\"type\\\":\\\"observable\\\"})};\\n var self = this;\\n function AppViewModel() {\\n for (var key in json_data) {\\n var el = json_data[key];\\n this[key] = Array.isArray(el) ? ko.observableArray(el) : ko.observable(el);\\n }\\n \\n [this[\\\"formatted_val\\\"]=ko.computed( function(){\\n return this.formatted_vals()[parseInt(this.index())-(1)];\\n }\\n,this)]\\n [this[\\\"changes\\\"].subscribe((function (val){!(this.valueFromJulia[\\\"changes\\\"]) ? (WebIO.setval({\\\"name\\\":\\\"changes\\\",\\\"scope\\\":\\\"12019567677823032763\\\",\\\"id\\\":\\\"ob_18\\\",\\\"type\\\":\\\"observable\\\"},val)) : undefined; return this.valueFromJulia[\\\"changes\\\"]=false}),self),this[\\\"index\\\"].subscribe((function (val){!(this.valueFromJulia[\\\"index\\\"]) ? (WebIO.setval({\\\"name\\\":\\\"index\\\",\\\"scope\\\":\\\"12019567677823032763\\\",\\\"id\\\":\\\"ob_17\\\",\\\"type\\\":\\\"observable\\\"},val)) : undefined; return this.valueFromJulia[\\\"index\\\"]=false}),self)]\\n \\n }\\n self.model = new AppViewModel();\\n self.valueFromJulia = {};\\n for (var key in json_data) {\\n self.valueFromJulia[key] = false;\\n }\\n ko.applyBindings(self.model, self.dom);\\n}\\n);\\n (WebIO.importBlock({\\\"data\\\":[{\\\"name\\\":\\\"knockout\\\",\\\"type\\\":\\\"js\\\",\\\"url\\\":\\\"/assetserver/2618192f019dfcc40a9013ef31cb09a511d8ea26-knockout.js\\\"},{\\\"name\\\":\\\"knockout_punches\\\",\\\"type\\\":\\\"js\\\",\\\"url\\\":\\\"/assetserver/df29ad18e8884e98d1d36dd0c339f642f729bf96-knockout_punches.js\\\"}],\\\"type\\\":\\\"async_block\\\"})).then((imports) => handler.apply(this, imports));\\n}\\n\")])], Dict{Symbol,Any}(:className => \"field interact-widget\")), Observable{Any} with 0 listeners. Value:\n", "Node{WebIO.DOM}(WebIO.DOM(:html, :div), Any[Plot{Plots.GRBackend() n=36}], Dict{Symbol,Any}(:className => \"interact-flex-row interact-widget\"))], Dict{Symbol,Any}())" ] }, "execution_count": 29, "metadata": { "application/vnd.webio.node+json": { "kernelId": "0460c48b-c1ce-4198-9750-65eccae2357d" } }, "output_type": "execute_result" } ], "source": [ "@manipulate for i =1: length(keepA)\n", " lookat( keepA[i], redrow=row[i])\n", "end" ] }, { "cell_type": "code", "execution_count": 30, "metadata": {}, "outputs": [], "source": [ "using LinearAlgebra" ] }, { "cell_type": "code", "execution_count": 33, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "6×6 Array{Float64,2}:\n", " 0.601848 0.719816 0.0549105 0.664714 0.184826 0.856158\n", " 0.373551 0.503678 0.964187 0.613921 0.840482 0.349087\n", " 0.139154 0.146278 0.0863354 0.315124 0.982249 0.226666\n", " 0.176656 0.560782 0.473594 0.625323 0.164821 0.457171\n", " 0.919038 0.751709 0.0796167 0.569861 0.793574 0.418587\n", " 0.288685 0.0699438 0.0534446 0.0420711 0.788685 0.921932" ] }, "execution_count": 33, "metadata": {}, "output_type": "execute_result" } ], "source": [ "A = keepA[1]" ] }, { "cell_type": "code", "execution_count": 34, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "6×6 Array{Float64,2}:\n", " 0.601848 0.719816 0.0549105 0.664714 0.184826 0.856158 \n", " -5.55112e-17 0.0569073 0.930105 0.201351 0.725765 -0.182307 \n", " -1.96573e-17 0.0 0.403003 0.232736 1.19652 -0.0358447\n", " 8.46105e-17 0.0 0.0 2.22829 11.2549 0.858134 \n", " 3.25219e-17 0.0 0.0 0.0 0.685981 -0.537103 \n", " 3.55852e-18 0.0 0.0 0.0 -5.55112e-17 1.1249 " ] }, "execution_count": 34, "metadata": {}, "output_type": "execute_result" } ], "source": [ "U = keepA[end]" ] }, { "cell_type": "code", "execution_count": 35, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "6×6 Array{Float64,2}:\n", " 0.0 0.0 0.0 0.0 0.0 0.0\n", " 0.620673 0.0 0.0 0.0 0.0 0.0\n", " 0.231211 -0.354114 0.0 0.0 0.0 0.0\n", " 0.293522 6.14156 -13.0392 0.0 0.0 0.0\n", " 1.52703 -6.10589 14.0815 -1.11881 0.0 0.0\n", " 0.479664 -4.83816 11.2334 -0.860311 0.660471 0.0" ] }, "execution_count": 35, "metadata": {}, "output_type": "execute_result" } ], "source": [ "L" ] }, { "cell_type": "code", "execution_count": 36, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "6×6 Array{Float64,2}:\n", " 1.0 0.0 0.0 0.0 0.0 0.0\n", " 0.620673 1.0 0.0 0.0 0.0 0.0\n", " 0.231211 -0.354114 1.0 0.0 0.0 0.0\n", " 0.293522 6.14156 -13.0392 1.0 0.0 0.0\n", " 1.52703 -6.10589 14.0815 -1.11881 1.0 0.0\n", " 0.479664 -4.83816 11.2334 -0.860311 0.660471 1.0" ] }, "execution_count": 36, "metadata": {}, "output_type": "execute_result" } ], "source": [ "L += I" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## First view of the LU decomposition" ] }, { "cell_type": "code", "execution_count": 37, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "6×6 Array{Float64,2}:\n", " 0.601848 0.719816 0.0549105 0.664714 0.184826 0.856158\n", " 0.373551 0.503678 0.964187 0.613921 0.840482 0.349087\n", " 0.139154 0.146278 0.0863354 0.315124 0.982249 0.226666\n", " 0.176656 0.560782 0.473594 0.625323 0.164821 0.457171\n", " 0.919038 0.751709 0.0796167 0.569861 0.793574 0.418587\n", " 0.288685 0.0699438 0.0534446 0.0420711 0.788685 0.921932" ] }, "execution_count": 37, "metadata": {}, "output_type": "execute_result" } ], "source": [ "A" ] }, { "cell_type": "code", "execution_count": 38, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "6×6 Array{Float64,2}:\n", " 0.601848 0.719816 0.0549105 0.664714 0.184826 0.856158\n", " 0.373551 0.503678 0.964187 0.613921 0.840482 0.349087\n", " 0.139154 0.146278 0.0863354 0.315124 0.982249 0.226666\n", " 0.176656 0.560782 0.473594 0.625323 0.164821 0.457171\n", " 0.919038 0.751709 0.0796167 0.569861 0.793574 0.418587\n", " 0.288685 0.0699438 0.0534446 0.0420711 0.788685 0.921932" ] }, "execution_count": 38, "metadata": {}, "output_type": "execute_result" } ], "source": [ "L * U" ] }, { "cell_type": "code", "execution_count": 39, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "true" ] }, "execution_count": 39, "metadata": {}, "output_type": "execute_result" } ], "source": [ "A ≈ L * U" ] }, { "cell_type": "code", "execution_count": 40, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "4×4 Array{Int64,2}:\n", " 2 12 4 7\n", " 29 12 69 24\n", " 7 7 7 7\n", " 3 7 5 2" ] }, "execution_count": 40, "metadata": {}, "output_type": "execute_result" } ], "source": [ "A = [2 12 4 7; 29 12 69 24 ; 7 7 7 7; 3 7 5 2]" ] }, { "cell_type": "code", "execution_count": 41, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "4×4 Adjoint{Int64,Array{Int64,2}}:\n", " 2 29 7 3\n", " 12 12 7 7\n", " 4 69 7 5\n", " 7 24 7 2" ] }, "execution_count": 41, "metadata": {}, "output_type": "execute_result" } ], "source": [ "A'\n" ] }, { "cell_type": "code", "execution_count": 42, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "2×3 Array{Int64,2}:\n", " 1 2 3\n", " 4 5 6" ] }, "execution_count": 42, "metadata": {}, "output_type": "execute_result" } ], "source": [ "A= [ 1 2 3; 4 5 6]" ] }, { "cell_type": "code", "execution_count": 43, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "3×2 Adjoint{Int64,Array{Int64,2}}:\n", " 1 4\n", " 2 5\n", " 3 6" ] }, "execution_count": 43, "metadata": {}, "output_type": "execute_result" } ], "source": [ "A'\n", "\n" ] }, { "cell_type": "code", "execution_count": 44, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Adjoint{Int64,Array{Int64,2}}\n", " parent: Array{Int64}((2, 3)) [1 2 3; 4 5 6]\n" ] } ], "source": [ "dump(A')" ] }, { "cell_type": "code", "execution_count": 45, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "2×3×4 Array{Int64,3}:\n", "[:, :, 1] =\n", " 2 8 3\n", " 7 5 3\n", "\n", "[:, :, 2] =\n", " 7 5 8\n", " 3 4 5\n", "\n", "[:, :, 3] =\n", " 4 2 8\n", " 8 4 2\n", "\n", "[:, :, 4] =\n", " 8 3 8\n", " 7 4 9" ] }, "execution_count": 45, "metadata": {}, "output_type": "execute_result" } ], "source": [ "A = rand( 1:9, 2,3,4)" ] }, { "cell_type": "code", "execution_count": 46, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "4×3×2 Array{Int64,3}:\n", "[:, :, 1] =\n", " 2 8 3\n", " 7 5 8\n", " 4 2 8\n", " 8 3 8\n", "\n", "[:, :, 2] =\n", " 7 5 3\n", " 3 4 5\n", " 8 4 2\n", " 7 4 9" ] }, "execution_count": 46, "metadata": {}, "output_type": "execute_result" } ], "source": [ "permutedims(A, [3 2 1])" ] }, { "cell_type": "code", "execution_count": 47, "metadata": {}, "outputs": [ { "ename": "DimensionMismatch", "evalue": "DimensionMismatch(\"matrix is not square: dimensions are (4, 6)\")", "output_type": "error", "traceback": [ "DimensionMismatch(\"matrix is not square: dimensions are (4, 6)\")", "", "Stacktrace:", " [1] inv(::Array{Float64,2}) at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.3/LinearAlgebra/src/LinearAlgebra.jl:221", " [2] top-level scope at In[47]:1" ] } ], "source": [ "inv( rand(4,6))" ] }, { "cell_type": "code", "execution_count": 48, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "3×3 Array{Float64,2}:\n", " 0.961711 0.705796 0.334855 \n", " 0.825322 0.76569 0.0211825\n", " 0.22131 0.162853 0.357397 " ] }, "execution_count": 48, "metadata": {}, "output_type": "execute_result" } ], "source": [ "A = rand(3,3)" ] }, { "cell_type": "code", "execution_count": 49, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "3×3 Array{Float64,2}:\n", " 0.466144 0.282758 0.176453 \n", " 0.804355 0.748308 0.9467 \n", " 0.764508 0.457893 0.0473501" ] }, "execution_count": 49, "metadata": {}, "output_type": "execute_result" } ], "source": [ "B = rand(3,3)" ] }, { "cell_type": "code", "execution_count": 50, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "3×3 Array{Float64,2}:\n", " 110.378 -81.0345 -112.35 \n", " -191.261 138.822 201.288 \n", " 50.3087 -34.295 -57.3957" ] }, "execution_count": 50, "metadata": {}, "output_type": "execute_result" } ], "source": [ "inv( A*B )" ] }, { "cell_type": "code", "execution_count": 51, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "3×3 Array{Float64,2}:\n", " 110.378 -81.0345 -112.35 \n", " -191.261 138.822 201.288 \n", " 50.3087 -34.295 -57.3957" ] }, "execution_count": 51, "metadata": {}, "output_type": "execute_result" } ], "source": [ "inv(B) * inv(A)" ] }, { "cell_type": "code", "execution_count": 52, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "1:10" ] }, "execution_count": 52, "metadata": {}, "output_type": "execute_result" } ], "source": [ "x = 1:10\n" ] }, { "cell_type": "code", "execution_count": 53, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "10×10 Array{Int64,2}:\n", " 1 2 3 4 5 6 7 8 9 10\n", " 2 4 6 8 10 12 14 16 18 20\n", " 3 6 9 12 15 18 21 24 27 30\n", " 4 8 12 16 20 24 28 32 36 40\n", " 5 10 15 20 25 30 35 40 45 50\n", " 6 12 18 24 30 36 42 48 54 60\n", " 7 14 21 28 35 42 49 56 63 70\n", " 8 16 24 32 40 48 56 64 72 80\n", " 9 18 27 36 45 54 63 72 81 90\n", " 10 20 30 40 50 60 70 80 90 100" ] }, "execution_count": 53, "metadata": {}, "output_type": "execute_result" } ], "source": [ "x * x'" ] }, { "cell_type": "code", "execution_count": 63, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "4-element Array{Int64,1}:\n", " 1\n", " 2\n", " 4\n", " 5" ] }, "execution_count": 63, "metadata": {}, "output_type": "execute_result" } ], "source": [ "x =[ 1 ,2 ,4, 5]" ] }, { "cell_type": "code", "execution_count": 64, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "3-element Array{Int64,1}:\n", " 2\n", " 4\n", " 6" ] }, "execution_count": 64, "metadata": {}, "output_type": "execute_result" } ], "source": [ "y = [ 2, 4, 6]" ] }, { "cell_type": "code", "execution_count": 66, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "4×3 Array{Int64,2}:\n", " 2 4 6\n", " 4 8 12\n", " 8 16 24\n", " 10 20 30" ] }, "execution_count": 66, "metadata": {}, "output_type": "execute_result" } ], "source": [ "x * y'" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "@webio": { "lastCommId": "20e37d08220749748154c409ff8f06a0", "lastKernelId": "0460c48b-c1ce-4198-9750-65eccae2357d" }, "kernelspec": { "display_name": "Julia 1.3.1", "language": "julia", "name": "julia-1.3" }, "language_info": { "file_extension": ".jl", "mimetype": "application/julia", "name": "julia", "version": "1.3.1" } }, "nbformat": 4, "nbformat_minor": 2 }