[{"created":"20210108064810986","text":"# A Forward Eulwr code for solving IVPs\nimport numpy as np\nimport matplotlib.pyplot as plt\n\n# Concentration over time\nN = lambda t: N0 * np.exp(-k * t)\n# dN/dt\ndef dx_dt(x):\n    return -k * x\n\nk = .5\nh = 0.001\nN0 = 100.\n\nt = np.arange(0, 10, h)\ny = np.zeros(len(t))\n\ny[0] = N0\nfor i in range(1, len(t)):\n    # Euler's method\n    y[i] = y[i-1] + dx_dt(y[i-1]) * h\n\nmax_error = abs(y-N(t)).max()\nprint(\"Max difference between the exact solution and \\nEuler's approximation with step size h=0.001:\")\nprint('{0:.15}'.format(max_error))\n\n\n# Create some point from exact solution for comparison\nte = np.linspace(0, 10, 10)\nye = N(te)\n\nplt.plot(t, y, 'b-', te, ye, 'ro')\n","tags":"lines","title":"euler.py","modified":"20210108093939650","type":"text/plain"},{"created":"20210108065138847","text":"<div class=\"test\">\n<<showLinesc \"euler.py\" 1 7 python>>\n<span class=\"opac\"><<showLinesc \"euler.py\" 8 9 python>></span>\n<<showLines \"euler.py\" 10 17 python>>\n<span class=\"opac\"><<showLinesc \"euler.py\" 18 21 python>></span>\n<<showLinesc \"euler.py\" 22 33 python>>\n</div>\n\n\n\n<style>\n.test{\n   background-color:<<colour page-background>>;\n\t border:1px solid <<colour pre-border>>;\n}\n.test  ol{\n\t\tmargin-top:0;\n\t\tmargin-bottom:0;\n}\n.test  pre {\n    padding:0 0 0 5px;\n\t\tmargin:0;\n\t\tborder:none;\n\t\t\n\t background-color:unset;\n\t opacity:0.4;\n}\n.test .opac pre{\n\t\topacity:1;\n}\n\n.test .opac ol{\n\t\tbackground-color:<<colour background>>;\n}\n\n</style>","tags":"lines","title":"test/code-lines","modified":"20210108094031068","type":"text/vnd.tiddlywiki","revision":"327","bag":"default"},{"created":"20210108093915901","text":"\\define showLinesc(tid,from,to,language)\n<$vars length={{{ [[$to$]subtract[$from$]add[1]] }}}>\n<$set name=\"lines\" filter=\"[[$tid$]get[text]splitregexp[\\n]addsuffix[ ]first[$to$]last<length>]\">\n<ol start=\"$from$\"><$list filter=\"[enlist:raw<lines>]\" variable=\"line\"><li><$codeblock code=<<line>> language=<<__language__>>/></li></$list></ol>\n</$set>\n</$vars>\n\\end","title":"macros/showLinesc","modified":"20210108094008564","type":"text/vnd.tiddlywiki","tags":"$:/tags/Macro lines"}]