Skip to content

Instantly share code, notes, and snippets.

@ileasile
Last active July 10, 2023 12:57
Show Gist options
  • Save ileasile/56d34ad232ef16dba578141f02fabc24 to your computer and use it in GitHub Desktop.
Save ileasile/56d34ad232ef16dba578141f02fabc24 to your computer and use it in GitHub Desktop.
Curve fitting
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": []
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
" <div id=\"kotlin_out_0\"></div>\n",
" <script type=\"text/javascript\">\n",
" if(!window.kotlinQueues) {\n",
" window.kotlinQueues = {};\n",
" }\n",
" if(!window.kotlinQueues[\"kandyLetsPlot\"]) {\n",
" var resQueue = [];\n",
" window.kotlinQueues[\"kandyLetsPlot\"] = resQueue;\n",
" window[\"call_kandyLetsPlot\"] = function(f) {\n",
" resQueue.push(f);\n",
" }\n",
" }\n",
" (function (){\n",
" var modifiers = [(function(script) {\n",
" script.src = \"https://cdn.jsdelivr.net/gh/JetBrains/lets-plot@v3.1.0/js-package/distr/lets-plot.min.js\"\n",
" script.type = \"text/javascript\";\n",
"})];\n",
" var e = document.getElementById(\"kotlin_out_0\");\n",
" modifiers.forEach(function (gen) {\n",
" var script = document.createElement(\"script\");\n",
" gen(script)\n",
" script.addEventListener(\"load\", function() {\n",
" window[\"call_kandyLetsPlot\"] = function(f) {f();};\n",
" window.kotlinQueues[\"kandyLetsPlot\"].forEach(function(f) {f();});\n",
" window.kotlinQueues[\"kandyLetsPlot\"] = [];\n",
" }, false);\n",
" script.addEventListener(\"error\", function() {\n",
" window[\"call_kandyLetsPlot\"] = function(f) {};\n",
" window.kotlinQueues[\"kandyLetsPlot\"] = [];\n",
" var div = document.createElement(\"div\");\n",
" div.style.color = 'darkred';\n",
" div.textContent = 'Error loading resource kandyLetsPlot';\n",
" document.getElementById(\"kotlin_out_0\").appendChild(div);\n",
" }, false);\n",
" \n",
" e.appendChild(script);\n",
" });\n",
" })();\n",
" </script>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"%useLatestDescriptors\n",
"%use kandy"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"@file:DependsOn(\"org.apache.commons:commons-math3:3.6.1\")"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"import org.apache.commons.math3.fitting.PolynomialCurveFitter\n",
"import org.apache.commons.math3.fitting.WeightedObservedPoints"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Polynomial coefficients:\n",
"Coefficient 0: 12.714285714285442\n",
"Coefficient 1: -18.397186147185792\n",
"Coefficient 2: 10.874999999999847\n",
"Coefficient 3: -2.159090909090883\n",
"Coefficient 4: 0.14015151515151358\n"
]
}
],
"source": [
"val data = mapOf(\n",
" 1 to 3,\n",
" 2 to 5,\n",
" 3 to 8,\n",
" 4 to 10,\n",
" 5 to 12,\n",
" 6 to 8,\n",
" 7 to 13\n",
")\n",
"\n",
"// Prepare the observed data points\n",
"val obs = WeightedObservedPoints()\n",
"data.forEach { (x, y) ->\n",
" obs.add(x.toDouble(), y.toDouble())\n",
"}\n",
"\n",
"// Perform polynomial regression\n",
"val degree = 4 // Change the degree as per your requirement\n",
"val fitter = PolynomialCurveFitter.create(degree)\n",
"val coefficients = fitter.fit(obs.toList())\n",
"\n",
"// Print the coefficients\n",
"println(\"Polynomial coefficients:\")\n",
"coefficients.forEachIndexed { index, coefficient ->\n",
" println(\"Coefficient $index: $coefficient\")\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"fun buildPolynomialFunction(coefficients: DoubleArray): (Double) -> Double {\n",
" return { x ->\n",
" var result = 0.0\n",
" for (i in coefficients.indices.reversed()) {\n",
" result += result * x + coefficients[i]\n",
" }\n",
" result\n",
" }\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"val f = buildPolynomialFunction(coefficients)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"10.822510822510797"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"f(3.0)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"30.14285714285692"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"f(7.0)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"application/plot+json": {
"apply_color_scheme": true,
"output": {
"data": {
"x": [
-1,
-0.945,
-0.89,
-0.835,
-0.78,
-0.725,
-0.6699999999999999,
-0.615,
-0.56,
-0.505,
-0.44999999999999996,
-0.395,
-0.33999999999999997,
-0.28500000000000003,
-0.22999999999999998,
-0.17500000000000004,
-0.12,
-0.06499999999999995,
-0.010000000000000009,
0.04499999999999993,
0.10000000000000009,
0.15500000000000003,
0.20999999999999996,
0.2649999999999999,
0.32000000000000006,
0.375,
0.42999999999999994,
0.4850000000000001,
0.54,
0.595,
0.6499999999999999,
0.7050000000000001,
0.76,
0.815,
0.8700000000000001,
0.925,
0.98,
1.0350000000000001,
1.0899999999999999,
1.145,
1.2000000000000002,
1.255,
1.31,
1.3650000000000002,
1.42,
1.475,
1.5299999999999998,
1.585,
1.6400000000000001,
1.6949999999999998,
1.75,
1.8050000000000002,
1.8599999999999999,
1.915,
1.9700000000000002,
2.025,
2.08,
2.135,
2.19,
2.245,
2.3,
2.355,
2.41,
2.465,
2.52,
2.575,
2.63,
2.685,
2.74,
2.795,
2.85,
2.905,
2.96,
3.0149999999999997,
3.0700000000000003,
3.125,
3.1799999999999997,
3.2350000000000003,
3.29,
3.3449999999999998,
3.4000000000000004,
3.455,
3.51,
3.5650000000000004,
3.62,
3.675,
3.7300000000000004,
3.785,
3.84,
3.8949999999999996,
3.95,
4.005,
4.06,
4.115,
4.17,
4.225,
4.28,
4.335,
4.39,
4.445,
4.5,
4.555,
4.61,
4.665,
4.72,
4.775,
4.83,
4.885,
4.94,
4.995,
5.05,
5.105,
5.16,
5.215,
5.27,
5.325,
5.38,
5.435,
5.49,
5.545,
5.6,
5.655,
5.71,
5.765,
5.82,
5.875,
5.93,
5.985,
6.04,
6.095,
6.15,
6.205,
6.26,
6.315,
6.37,
6.425,
6.48,
6.535,
6.59,
6.645,
6.7,
6.755,
6.81,
6.865,
6.92,
6.975,
7.029999999999999,
7.085000000000001,
7.140000000000001,
7.195,
7.25,
7.305,
7.359999999999999,
7.414999999999999,
7.470000000000001,
7.525,
7.58,
7.635,
7.6899999999999995,
7.744999999999999,
7.800000000000001,
7.855,
7.91,
7.965,
8.02,
8.075,
8.13,
8.185,
8.24,
8.295,
8.35,
8.405,
8.46,
8.515,
8.57,
8.625,
8.68,
8.735,
8.79,
8.845,
8.9,
8.955,
9.01,
9.065,
9.12,
9.175,
9.23,
9.285,
9.34,
9.395,
9.45,
9.505,
9.56,
9.615,
9.67,
9.725,
9.78,
9.835,
9.89,
9.945,
10
],
"y": [
12.714285714285442,
11.734979414914179,
10.819329507678336,
9.965226849140407,
9.170593075237896,
8.433380601283297,
7.751572621964115,
7.123183111342847,
6.546256822857,
6.018869289319067,
5.539126822916549,
5.105166515211945,
4.715156237142759,
4.367294639021489,
4.059811150535635,
3.790965980747698,
3.5590501180951772,
3.3623853303905715,
3.199324164821382,
3.068249947950111,
2.967576785714252,
2.8957495634263086,
2.8512439457737866,
2.83256637681918,
2.8382540799999862,
2.8668750581287075,
2.917028093392851,
2.987342747354904,
3.076479360952379,
3.18312905449777,
3.3060137276785735,
3.443886059557295,
3.595529508571433,
3.7597583125334904,
3.935417488630959,
4.121382833426348,
4.316560922857152,
4.519889112235874,
4.730335536250009,
4.946899108962064,
5.168609523809534,
5.39452725360492,
5.623743550535721,
5.8553804461644425,
6.088590751428583,
6.322558056640635,
6.556496731488095,
6.789651925033488,
7.021299565714288,
7.250746361343014,
7.477329799107137,
7.700418145569193,
7.919410446666671,
8.13373652771205,
8.342856993392854,
8.54626322777157,
8.743477394285701,
8.934052435747756,
9.11757207434523,
9.293650811640616,
9.461933928571405,
9.622097485450137,
9.773848321964273,
9.916924057176324,
10.051093089523789,
10.17615459681917,
10.291938536249976,
10.3983056443787,
10.495147437142837,
10.582386209854876,
10.659975037202358,
10.727897773247747,
10.786169051428555,
10.834834284557271,
10.873969664821406,
10.903682163783447,
10.924109532380925,
10.935420300926308,
10.93781377910712,
10.931520055985832,
10.916799999999967,
10.893945258962034,
10.863278260059488,
10.825152209854897,
10.779951094285659,
10.728089678664409,
10.670013507678526,
10.606198905390603,
10.537152975238055,
10.463413600033437,
10.385549441964265,
10.304159942592978,
10.219875322857128,
10.133356583069176,
10.04529550291663,
9.956414641462027,
9.867467337142827,
9.779237707771554,
9.692540650535701,
9.608221841997713,
9.527157738095221,
9.450255574140579,
9.37845336482141,
9.31271990420012,
9.254054765714248,
9.203488302176307,
9.162081645773764,
9.130926708069182,
9.11114617999995,
9.103893531878668,
9.110353013392809,
9.131739653604878,
9.169299260952364,
9.224308423247752,
9.29807450767854,
9.39193566080726,
9.507260808571386,
9.645449656283475,
9.807932688630904,
9.99617116967629,
10.211657142857103,
10.455913430985788,
10.730493636249992,
11.036982140211936,
11.376994103809423,
11.75217546735484,
12.164202950535657,
12.6147840524144,
13.105657051428445,
13.63859100539057,
14.21538575148807,
14.83787190628335,
15.507910865714221,
16.227394805092896,
16.99824667910702,
17.822420221819044,
18.701899946666515,
19.63870114646196,
20.634869893392647,
21.69248303902143,
22.813648214285543,
24.000503829497603,
25.25521907434501,
26.579993917890334,
27.977059108571197,
29.44867617419985,
30.99713742196405,
32.62476593842615,
34.33391558952356,
36.12697102056889,
38.00634765624969,
39.9744917006284,
42.03388013714248,
44.187020728604494,
46.436452017202015,
48.784743324497356,
51.23449475142813,
53.78833717830679,
56.44893226482087,
59.218972450032894,
62.1011809523804,
65.09831176967576,
68.21314967910648,
71.44851023723518,
74.80723977999924,
78.29221542271131,
81.90634506005877,
85.65256736610411,
89.53385179428484,
93.5531985774135,
97.71363872767762,
102.01823403663951,
106.47007707523706,
111.07229119378232,
115.8280305219631,
120.74047996884175,
125.81285522285586,
131.04840275181775,
136.45039980291517,
142.02215440271084,
147.7670053571415,
153.68832225152022,
159.7895054505342,
166.0739860982462,
172.5452261180935,
179.20671821288897,
186.06198586481972,
193.11458333544834,
200.36809566571236,
207.82613867592434,
215.49235896577164,
223.37043391431712,
231.4640716799978,
239.77701120062642,
248.31302219339045,
257.07590515485236,
266.06949136094966,
275.29764286699515,
284.76425250767574,
294.4732438970544,
304.4285714285685
]
},
"kind": "plot",
"layers": [
{
"geom": "line",
"mapping": {
"x": "x",
"y": "y"
},
"position": "identity",
"sampling": "none",
"stat": "identity"
}
],
"mapping": {},
"scales": [
{
"aesthetic": "x",
"limits": [
null,
null
]
},
{
"aesthetic": "y",
"limits": [
null,
null
]
}
]
},
"output_type": "lets_plot_spec",
"swing_enabled": true
},
"text/html": [
" <script type=\"text/javascript\" data-lets-plot-script=\"library\" src=\"https://cdn.jsdelivr.net/gh/JetBrains/lets-plot@v3.1.0/js-package/distr/lets-plot.min.js\"></script> \n",
" <div id=\"jMWcSu\"></div>\n",
" <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
" var plotSpec={\n",
"\"mapping\":{\n",
"},\n",
"\"data\":{\n",
"\"x\":[-1.0,-0.945,-0.89,-0.835,-0.78,-0.725,-0.6699999999999999,-0.615,-0.56,-0.505,-0.44999999999999996,-0.395,-0.33999999999999997,-0.28500000000000003,-0.22999999999999998,-0.17500000000000004,-0.12,-0.06499999999999995,-0.010000000000000009,0.04499999999999993,0.10000000000000009,0.15500000000000003,0.20999999999999996,0.2649999999999999,0.32000000000000006,0.375,0.42999999999999994,0.4850000000000001,0.54,0.595,0.6499999999999999,0.7050000000000001,0.76,0.815,0.8700000000000001,0.925,0.98,1.0350000000000001,1.0899999999999999,1.145,1.2000000000000002,1.255,1.31,1.3650000000000002,1.42,1.475,1.5299999999999998,1.585,1.6400000000000001,1.6949999999999998,1.75,1.8050000000000002,1.8599999999999999,1.915,1.9700000000000002,2.025,2.08,2.135,2.19,2.245,2.3,2.355,2.41,2.465,2.52,2.575,2.63,2.685,2.74,2.795,2.85,2.905,2.96,3.0149999999999997,3.0700000000000003,3.125,3.1799999999999997,3.2350000000000003,3.29,3.3449999999999998,3.4000000000000004,3.455,3.51,3.5650000000000004,3.62,3.675,3.7300000000000004,3.785,3.84,3.8949999999999996,3.95,4.005,4.06,4.115,4.17,4.225,4.28,4.335,4.39,4.445,4.5,4.555,4.61,4.665,4.72,4.775,4.83,4.885,4.94,4.995,5.05,5.105,5.16,5.215,5.27,5.325,5.38,5.435,5.49,5.545,5.6,5.655,5.71,5.765,5.82,5.875,5.93,5.985,6.04,6.095,6.15,6.205,6.26,6.315,6.37,6.425,6.48,6.535,6.59,6.645,6.7,6.755,6.81,6.865,6.92,6.975,7.029999999999999,7.085000000000001,7.140000000000001,7.195,7.25,7.305,7.359999999999999,7.414999999999999,7.470000000000001,7.525,7.58,7.635,7.6899999999999995,7.744999999999999,7.800000000000001,7.855,7.91,7.965,8.02,8.075,8.13,8.185,8.24,8.295,8.35,8.405,8.46,8.515,8.57,8.625,8.68,8.735,8.79,8.845,8.9,8.955,9.01,9.065,9.12,9.175,9.23,9.285,9.34,9.395,9.45,9.505,9.56,9.615,9.67,9.725,9.78,9.835,9.89,9.945,10.0],\n",
"\"y\":[12.714285714285442,11.734979414914179,10.819329507678336,9.965226849140407,9.170593075237896,8.433380601283297,7.751572621964115,7.123183111342847,6.546256822857,6.018869289319067,5.539126822916549,5.105166515211945,4.715156237142759,4.367294639021489,4.059811150535635,3.790965980747698,3.5590501180951772,3.3623853303905715,3.199324164821382,3.068249947950111,2.967576785714252,2.8957495634263086,2.8512439457737866,2.83256637681918,2.8382540799999862,2.8668750581287075,2.917028093392851,2.987342747354904,3.076479360952379,3.18312905449777,3.3060137276785735,3.443886059557295,3.595529508571433,3.7597583125334904,3.935417488630959,4.121382833426348,4.316560922857152,4.519889112235874,4.730335536250009,4.946899108962064,5.168609523809534,5.39452725360492,5.623743550535721,5.8553804461644425,6.088590751428583,6.322558056640635,6.556496731488095,6.789651925033488,7.021299565714288,7.250746361343014,7.477329799107137,7.700418145569193,7.919410446666671,8.13373652771205,8.342856993392854,8.54626322777157,8.743477394285701,8.934052435747756,9.11757207434523,9.293650811640616,9.461933928571405,9.622097485450137,9.773848321964273,9.916924057176324,10.051093089523789,10.17615459681917,10.291938536249976,10.3983056443787,10.495147437142837,10.582386209854876,10.659975037202358,10.727897773247747,10.786169051428555,10.834834284557271,10.873969664821406,10.903682163783447,10.924109532380925,10.935420300926308,10.93781377910712,10.931520055985832,10.916799999999967,10.893945258962034,10.863278260059488,10.825152209854897,10.779951094285659,10.728089678664409,10.670013507678526,10.606198905390603,10.537152975238055,10.463413600033437,10.385549441964265,10.304159942592978,10.219875322857128,10.133356583069176,10.04529550291663,9.956414641462027,9.867467337142827,9.779237707771554,9.692540650535701,9.608221841997713,9.527157738095221,9.450255574140579,9.37845336482141,9.31271990420012,9.254054765714248,9.203488302176307,9.162081645773764,9.130926708069182,9.11114617999995,9.103893531878668,9.110353013392809,9.131739653604878,9.169299260952364,9.224308423247752,9.29807450767854,9.39193566080726,9.507260808571386,9.645449656283475,9.807932688630904,9.99617116967629,10.211657142857103,10.455913430985788,10.730493636249992,11.036982140211936,11.376994103809423,11.75217546735484,12.164202950535657,12.6147840524144,13.105657051428445,13.63859100539057,14.21538575148807,14.83787190628335,15.507910865714221,16.227394805092896,16.99824667910702,17.822420221819044,18.701899946666515,19.63870114646196,20.634869893392647,21.69248303902143,22.813648214285543,24.000503829497603,25.25521907434501,26.579993917890334,27.977059108571197,29.44867617419985,30.99713742196405,32.62476593842615,34.33391558952356,36.12697102056889,38.00634765624969,39.9744917006284,42.03388013714248,44.187020728604494,46.436452017202015,48.784743324497356,51.23449475142813,53.78833717830679,56.44893226482087,59.218972450032894,62.1011809523804,65.09831176967576,68.21314967910648,71.44851023723518,74.80723977999924,78.29221542271131,81.90634506005877,85.65256736610411,89.53385179428484,93.5531985774135,97.71363872767762,102.01823403663951,106.47007707523706,111.07229119378232,115.8280305219631,120.74047996884175,125.81285522285586,131.04840275181775,136.45039980291517,142.02215440271084,147.7670053571415,153.68832225152022,159.7895054505342,166.0739860982462,172.5452261180935,179.20671821288897,186.06198586481972,193.11458333544834,200.36809566571236,207.82613867592434,215.49235896577164,223.37043391431712,231.4640716799978,239.77701120062642,248.31302219339045,257.07590515485236,266.06949136094966,275.29764286699515,284.76425250767574,294.4732438970544,304.4285714285685]\n",
"},\n",
"\"kind\":\"plot\",\n",
"\"scales\":[{\n",
"\"aesthetic\":\"x\",\n",
"\"limits\":[null,null]\n",
"},{\n",
"\"aesthetic\":\"y\",\n",
"\"limits\":[null,null]\n",
"}],\n",
"\"layers\":[{\n",
"\"mapping\":{\n",
"\"x\":\"x\",\n",
"\"y\":\"y\"\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"sampling\":\"none\",\n",
"\"position\":\"identity\",\n",
"\"geom\":\"line\",\n",
"\"data\":{\n",
"}\n",
"}]\n",
"};\n",
" var plotContainer = document.getElementById(\"jMWcSu\");\n",
" LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
" </script> \n",
" <svg id=b2a23d4b-2d07-4054-9dab-30bfe41e8b1e xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" class=\"plt-container\" width=\"600.0\" height=\"400.0\">\n",
" <style type=\"text/css\">\n",
" .plt-container {\n",
" font-family: Lucida Grande, sans-serif;\n",
" user-select: none;\n",
" -webkit-user-select: none;\n",
" -moz-user-select: none;\n",
" -ms-user-select: none;\n",
"}\n",
"text {\n",
" text-rendering: optimizeLegibility;\n",
"}\n",
"#pAA8lbf .plot-title {\n",
" fill: #474747;\n",
" font-family: Lucida Grande, sans-serif;\n",
" font-size: 16.0px;\n",
" font-weight: normal;\n",
" font-style: normal; \n",
"}\n",
"#pAA8lbf .plot-subtitle {\n",
" fill: #474747;\n",
" font-family: Lucida Grande, sans-serif;\n",
" font-size: 15.0px;\n",
" font-weight: normal;\n",
" font-style: normal; \n",
"}\n",
"#pAA8lbf .plot-caption {\n",
" fill: #474747;\n",
" font-family: Lucida Grande, sans-serif;\n",
" font-size: 13.0px;\n",
" font-weight: normal;\n",
" font-style: normal; \n",
"}\n",
"#pAA8lbf .legend-title {\n",
" fill: #474747;\n",
" font-family: Lucida Grande, sans-serif;\n",
" font-size: 15.0px;\n",
" font-weight: normal;\n",
" font-style: normal; \n",
"}\n",
"#pAA8lbf .legend-item {\n",
" fill: #474747;\n",
" font-family: Lucida Grande, sans-serif;\n",
" font-size: 13.0px;\n",
" font-weight: normal;\n",
" font-style: normal; \n",
"}\n",
"#pAA8lbf .axis-title-x {\n",
" fill: #474747;\n",
" font-family: Lucida Grande, sans-serif;\n",
" font-size: 15.0px;\n",
" font-weight: normal;\n",
" font-style: normal; \n",
"}\n",
"#pAA8lbf .axis-text-x {\n",
" fill: #474747;\n",
" font-family: Lucida Grande, sans-serif;\n",
" font-size: 13.0px;\n",
" font-weight: normal;\n",
" font-style: normal; \n",
"}\n",
"#dlaccP1 .axis-tooltip-text-x {\n",
" fill: #ffffff;\n",
" font-family: Lucida Grande, sans-serif;\n",
" font-size: 13.0px;\n",
" font-weight: normal;\n",
" font-style: normal; \n",
"}\n",
"#pAA8lbf .axis-title-y {\n",
" fill: #474747;\n",
" font-family: Lucida Grande, sans-serif;\n",
" font-size: 15.0px;\n",
" font-weight: normal;\n",
" font-style: normal; \n",
"}\n",
"#pAA8lbf .axis-text-y {\n",
" fill: #474747;\n",
" font-family: Lucida Grande, sans-serif;\n",
" font-size: 13.0px;\n",
" font-weight: normal;\n",
" font-style: normal; \n",
"}\n",
"#dlaccP1 .axis-tooltip-text-y {\n",
" fill: #ffffff;\n",
" font-family: Lucida Grande, sans-serif;\n",
" font-size: 13.0px;\n",
" font-weight: normal;\n",
" font-style: normal; \n",
"}\n",
"#pAA8lbf .facet-strip-text-x {\n",
" fill: #474747;\n",
" font-family: Lucida Grande, sans-serif;\n",
" font-size: 13.0px;\n",
" font-weight: normal;\n",
" font-style: normal; \n",
"}\n",
"#pAA8lbf .facet-strip-text-y {\n",
" fill: #474747;\n",
" font-family: Lucida Grande, sans-serif;\n",
" font-size: 13.0px;\n",
" font-weight: normal;\n",
" font-style: normal; \n",
"}\n",
"#dlaccP1 .tooltip-text {\n",
" fill: #474747;\n",
" font-family: Lucida Grande, sans-serif;\n",
" font-size: 13.0px;\n",
" font-weight: normal;\n",
" font-style: normal; \n",
"}\n",
"#dlaccP1 .tooltip-title {\n",
" fill: #474747;\n",
" font-family: Lucida Grande, sans-serif;\n",
" font-size: 13.0px;\n",
" font-weight: bold;\n",
" font-style: normal; \n",
"}\n",
"#dlaccP1 .tooltip-label {\n",
" fill: #474747;\n",
" font-family: Lucida Grande, sans-serif;\n",
" font-size: 13.0px;\n",
" font-weight: bold;\n",
" font-style: normal; \n",
"}\n",
"\n",
" </style>\n",
" <g id=\"pAA8lbf\">\n",
" <rect x=\"0.0\" y=\"0.0\" height=\"400.0\" width=\"600.0\" stroke=\"rgb(71,71,71)\" stroke-opacity=\"1.0\" stroke-width=\"0.0\" fill=\"rgb(255,255,255)\" fill-opacity=\"1.0\">\n",
" </rect>\n",
" <g transform=\"translate(23.0 10.0 ) \">\n",
" <g transform=\"translate(29.941816366404606 344.0 ) \">\n",
" <line x1=\"68.79670947372502\" y1=\"-0.0\" x2=\"68.79670947372502\" y2=\"-344.0\" stroke=\"rgb(233,233,233)\" stroke-opacity=\"1.0\" stroke-width=\"1.0\">\n",
" </line>\n",
" <line x1=\"157.5666571817573\" y1=\"-0.0\" x2=\"157.5666571817573\" y2=\"-344.0\" stroke=\"rgb(233,233,233)\" stroke-opacity=\"1.0\" stroke-width=\"1.0\">\n",
" </line>\n",
" <line x1=\"246.33660488978956\" y1=\"-0.0\" x2=\"246.33660488978956\" y2=\"-344.0\" stroke=\"rgb(233,233,233)\" stroke-opacity=\"1.0\" stroke-width=\"1.0\">\n",
" </line>\n",
" <line x1=\"335.1065525978218\" y1=\"-0.0\" x2=\"335.1065525978218\" y2=\"-344.0\" stroke=\"rgb(233,233,233)\" stroke-opacity=\"1.0\" stroke-width=\"1.0\">\n",
" </line>\n",
" <line x1=\"423.8765003058541\" y1=\"-0.0\" x2=\"423.8765003058541\" y2=\"-344.0\" stroke=\"rgb(233,233,233)\" stroke-opacity=\"1.0\" stroke-width=\"1.0\">\n",
" </line>\n",
" <line x1=\"512.6464480138865\" y1=\"-0.0\" x2=\"512.6464480138865\" y2=\"-344.0\" stroke=\"rgb(233,233,233)\" stroke-opacity=\"1.0\" stroke-width=\"1.0\">\n",
" </line>\n",
" <g transform=\"translate(68.79670947372502 0.0 ) \">\n",
" <line stroke-width=\"1.0\" stroke=\"rgb(71,71,71)\" stroke-opacity=\"1.0\" x2=\"0.0\" y2=\"4.0\">\n",
" </line>\n",
" <g transform=\"translate(0.0 7.0 ) \">\n",
" <text class=\"axis-text-x\" text-anchor=\"middle\" dy=\"0.7em\">\n",
" 0\n",
" </text>\n",
" </g>\n",
" </g>\n",
" <g transform=\"translate(157.5666571817573 0.0 ) \">\n",
" <line stroke-width=\"1.0\" stroke=\"rgb(71,71,71)\" stroke-opacity=\"1.0\" x2=\"0.0\" y2=\"4.0\">\n",
" </line>\n",
" <g transform=\"translate(0.0 7.0 ) \">\n",
" <text class=\"axis-text-x\" text-anchor=\"middle\" dy=\"0.7em\">\n",
" 2\n",
" </text>\n",
" </g>\n",
" </g>\n",
" <g transform=\"translate(246.33660488978956 0.0 ) \">\n",
" <line stroke-width=\"1.0\" stroke=\"rgb(71,71,71)\" stroke-opacity=\"1.0\" x2=\"0.0\" y2=\"4.0\">\n",
" </line>\n",
" <g transform=\"translate(0.0 7.0 ) \">\n",
" <text class=\"axis-text-x\" text-anchor=\"middle\" dy=\"0.7em\">\n",
" 4\n",
" </text>\n",
" </g>\n",
" </g>\n",
" <g transform=\"translate(335.1065525978218 0.0 ) \">\n",
" <line stroke-width=\"1.0\" stroke=\"rgb(71,71,71)\" stroke-opacity=\"1.0\" x2=\"0.0\" y2=\"4.0\">\n",
" </line>\n",
" <g transform=\"translate(0.0 7.0 ) \">\n",
" <text class=\"axis-text-x\" text-anchor=\"middle\" dy=\"0.7em\">\n",
" 6\n",
" </text>\n",
" </g>\n",
" </g>\n",
" <g transform=\"translate(423.8765003058541 0.0 ) \">\n",
" <line stroke-width=\"1.0\" stroke=\"rgb(71,71,71)\" stroke-opacity=\"1.0\" x2=\"0.0\" y2=\"4.0\">\n",
" </line>\n",
" <g transform=\"translate(0.0 7.0 ) \">\n",
" <text class=\"axis-text-x\" text-anchor=\"middle\" dy=\"0.7em\">\n",
" 8\n",
" </text>\n",
" </g>\n",
" </g>\n",
" <g transform=\"translate(512.6464480138865 0.0 ) \">\n",
" <line stroke-width=\"1.0\" stroke=\"rgb(71,71,71)\" stroke-opacity=\"1.0\" x2=\"0.0\" y2=\"4.0\">\n",
" </line>\n",
" <g transform=\"translate(0.0 7.0 ) \">\n",
" <text class=\"axis-text-x\" text-anchor=\"middle\" dy=\"0.7em\">\n",
" 10\n",
" </text>\n",
" </g>\n",
" </g>\n",
" <line x1=\"0.0\" y1=\"0.0\" x2=\"537.0581836335954\" y2=\"0.0\" stroke-width=\"1.0\" stroke=\"rgb(71,71,71)\" stroke-opacity=\"1.0\">\n",
" </line>\n",
" </g>\n",
" <g transform=\"translate(29.941816366404606 0.0 ) \">\n",
" <line x1=\"0.0\" y1=\"331.3007467464136\" x2=\"537.0581836335954\" y2=\"331.3007467464136\" stroke=\"rgb(233,233,233)\" stroke-opacity=\"1.0\" stroke-width=\"1.0\">\n",
" </line>\n",
" <line x1=\"0.0\" y1=\"279.45535299300275\" x2=\"537.0581836335954\" y2=\"279.45535299300275\" stroke=\"rgb(233,233,233)\" stroke-opacity=\"1.0\" stroke-width=\"1.0\">\n",
" </line>\n",
" <line x1=\"0.0\" y1=\"227.6099592395919\" x2=\"537.0581836335954\" y2=\"227.6099592395919\" stroke=\"rgb(233,233,233)\" stroke-opacity=\"1.0\" stroke-width=\"1.0\">\n",
" </line>\n",
" <line x1=\"0.0\" y1=\"175.76456548618103\" x2=\"537.0581836335954\" y2=\"175.76456548618103\" stroke=\"rgb(233,233,233)\" stroke-opacity=\"1.0\" stroke-width=\"1.0\">\n",
" </line>\n",
" <line x1=\"0.0\" y1=\"123.91917173277017\" x2=\"537.0581836335954\" y2=\"123.91917173277017\" stroke=\"rgb(233,233,233)\" stroke-opacity=\"1.0\" stroke-width=\"1.0\">\n",
" </line>\n",
" <line x1=\"0.0\" y1=\"72.0737779793593\" x2=\"537.0581836335954\" y2=\"72.0737779793593\" stroke=\"rgb(233,233,233)\" stroke-opacity=\"1.0\" stroke-width=\"1.0\">\n",
" </line>\n",
" <line x1=\"0.0\" y1=\"20.228384225948446\" x2=\"537.0581836335954\" y2=\"20.228384225948446\" stroke=\"rgb(233,233,233)\" stroke-opacity=\"1.0\" stroke-width=\"1.0\">\n",
" </line>\n",
" <g transform=\"translate(0.0 331.3007467464136 ) \">\n",
" <g transform=\"translate(-3.0 0.0 ) \">\n",
" <text class=\"axis-text-y\" text-anchor=\"end\" dy=\"0.35em\">\n",
" 0\n",
" </text>\n",
" </g>\n",
" </g>\n",
" <g transform=\"translate(0.0 279.45535299300275 ) \">\n",
" <g transform=\"translate(-3.0 0.0 ) \">\n",
" <text class=\"axis-text-y\" text-anchor=\"end\" dy=\"0.35em\">\n",
" 50\n",
" </text>\n",
" </g>\n",
" </g>\n",
" <g transform=\"translate(0.0 227.6099592395919 ) \">\n",
" <g transform=\"translate(-3.0 0.0 ) \">\n",
" <text class=\"axis-text-y\" text-anchor=\"end\" dy=\"0.35em\">\n",
" 100\n",
" </text>\n",
" </g>\n",
" </g>\n",
" <g transform=\"translate(0.0 175.76456548618103 ) \">\n",
" <g transform=\"translate(-3.0 0.0 ) \">\n",
" <text class=\"axis-text-y\" text-anchor=\"end\" dy=\"0.35em\">\n",
" 150\n",
" </text>\n",
" </g>\n",
" </g>\n",
" <g transform=\"translate(0.0 123.91917173277017 ) \">\n",
" <g transform=\"translate(-3.0 0.0 ) \">\n",
" <text class=\"axis-text-y\" text-anchor=\"end\" dy=\"0.35em\">\n",
" 200\n",
" </text>\n",
" </g>\n",
" </g>\n",
" <g transform=\"translate(0.0 72.0737779793593 ) \">\n",
" <g transform=\"translate(-3.0 0.0 ) \">\n",
" <text class=\"axis-text-y\" text-anchor=\"end\" dy=\"0.35em\">\n",
" 250\n",
" </text>\n",
" </g>\n",
" </g>\n",
" <g transform=\"translate(0.0 20.228384225948446 ) \">\n",
" <g transform=\"translate(-3.0 0.0 ) \">\n",
" <text class=\"axis-text-y\" text-anchor=\"end\" dy=\"0.35em\">\n",
" 300\n",
" </text>\n",
" </g>\n",
" </g>\n",
" </g>\n",
" <g transform=\"translate(29.941816366404606 0.0 ) \" clip-path=\"url(#cD9EBrk)\" clip-bounds-jfx=\"[rect (0.0, 0.0), (537.0581836335954, 344.0)]\">\n",
" <defs>\n",
" <clipPath id=\"cD9EBrk\">\n",
" <rect x=\"0.0\" y=\"0.0\" width=\"537.0581836335954\" height=\"344.0\">\n",
" </rect>\n",
" </clipPath>\n",
" </defs>\n",
" <g>\n",
" <path d=\"M24.411735619708878 318.1172037634037 L24.411735619708878 318.1172037634037 L26.85290918167977 319.13265417732566 L29.294082743650655 320.082098776944 L31.73525630562154 320.9677245496987 L34.176429867592425 321.79168656765336 L36.61760342956332 322.5561079874954 L39.0587769915342 323.26308005053585 L41.49995055350509 323.9146620827093 L43.94112411547597 324.5128814945741 L46.38229767744687 325.05973378131245 L48.823471239417756 325.5571825227298 L51.26464480138864 326.0071593832558 L53.70581836335953 326.4115641119433 L56.14699192533041 326.77226454246903 L58.5881654873013 327.09109659313344 L61.02933904927219 327.3698642668606 L63.47051261124308 327.6103396511983 L65.91168617321397 327.81426291831775 L68.35285973518485 327.9833423250143 L70.79403329715574 328.1192542127065 L73.23520685912663 328.22364300743686 L75.67638042109752 328.2981212198715 L78.1175539830684 328.3442694453002 L80.55872754503929 328.3636363636364 L82.99990110701019 328.35773873941713 L85.44107466898106 328.3280614218033 L87.88224823095194 328.2760573445793 L90.32342179292284 328.2031475261534 L92.76459535489373 328.11072106955726 L95.20576891686461 328.00013516244644 L97.6469424788355 327.87271507710005 L100.0881160408064 327.729754170421 L102.52928960277728 327.57251388393576 L104.97046316474817 327.4022237437944 L107.41163672671905 327.22008136077096 L109.85281028868994 327.0272524302629 L112.29398385066082 326.8248707322913 L114.73515741263174 326.61403813150116 L117.17633097460259 326.3958245771609 L119.6175045365735 326.1712681031629 L122.05867809854439 325.9413748280229 L124.49985166051528 325.70711895488057 L126.94102522248616 325.469442771499 L129.38219878445705 325.22925665026526 L131.82337234642793 324.9874390481898 L134.26454590839882 324.74483650690695 L136.7057194703697 324.50226365267457 L139.14689303234059 324.2605031963743 L141.5880665943115 324.0203059335114 L144.02924015628236 323.7823907442148 L146.47041371825327 323.5474445932372 L148.91158728022415 323.3161225299547 L151.35276084219504 323.08904768836743 L153.79393440416592 322.866811287099 L156.2351079661368 322.6499726293966 L158.6762815281077 322.43905910313134 L161.11745509007858 322.23456618079786 L163.55862865204946 322.03695741951435 L165.99980221402035 321.84666446102295 L168.44097577599126 321.66408703168935 L170.88214933796212 321.4895929425028 L173.32332289993303 321.3235180890763 L175.76449646190392 321.1661664516466 L178.2056700238748 321.017810095074 L180.6468435858457 320.87868916884264 L183.08801714781657 320.74901190706015 L185.52919070978746 320.62895462845796 L187.97036427175834 320.51866173639104 L190.41153783372926 320.4182457188382 L192.8527113957001 320.3277871484018 L195.29388495767103 320.2473346823079 L197.73505851964188 320.1769050624062 L200.1762320816128 320.11648311517024 L202.61740564358365 320.06602175169706 L205.05857920555457 320.02544196770737 L207.49975276752542 319.9946328435457 L209.94092632949634 319.97345154418 L212.38209989146725 319.9617233192023 L214.8232734534381 319.95924150282775 L217.26444701540896 319.96576751389574 L219.70562057737988 319.98103085586894 L222.1467941393508 320.0047291168338 L224.58796770132165 320.0365279695006 L227.02914126329256 320.0760611712029 L229.47031482526342 320.12293056389854 L231.91148838723433 320.1767060741684 L234.35266194920524 320.2369257132175 L236.7938355111761 320.30309557687417 L239.23500907314695 320.37468984559075 L241.67618263511787 320.45115078444303 L244.11735619708878 320.53188874313054 L246.55852975905964 320.6162821559765 L248.9997033210305 320.70367754192773 L251.4408768830014 320.7933895045548 L253.88205044497232 320.884700732052 L256.3232240069432 320.9768619972371 L258.7643975689141 321.0690921575518 L261.20557113088495 321.1605781550612 L263.64674469285586 321.25047501645435 L266.0879182548268 321.3379058530437 L268.52909181679763 321.4219618607656 L270.9702653787685 321.5017023201799 L273.4114389407394 321.57615459647025 L275.8526125027103 321.64431413944396 L278.29378606468117 321.70514448353197 L280.7349596266521 321.7575772477888 L283.17613318862294 321.8005121358928 L285.61730675059385 321.83281693614595 L288.05848031256477 321.85332752147394 L290.4996538745356 321.860847849426 L292.9408274365065 321.85414996217514 L295.3820009984774 321.831973986518 L297.8231745604483 321.79302813387494 L300.26434812241916 321.7359887002899 L302.70552168439 321.65950006643067 L305.14669524636093 321.56217469758855 L307.58786880833185 321.4425931436785 L310.0290423703027 321.29930403923925 L312.4702159322736 321.1308241034332 L314.9113894942445 320.93563814004636 L317.3525630562154 320.71219903748846 L319.7937366181863 320.4589277687929 L322.23491018015716 320.1742133916166 L324.676083742128 319.8564130482406 L327.1172573040989 319.50385196556897 L329.55843086606984 319.11482345512985 L331.9996044280407 318.68758891307516 L334.4407779900116 318.22037782018015 L336.88195155198247 317.71138774184413 L339.3231251139534 317.15878432808955 L341.7642986759243 316.56070131356313 L344.20547223789515 315.9152405175349 L346.646645799866 315.22047184389857 L349.0878193618369 314.4744332811717 L351.52899292380783 313.67513090249537 L353.9701664857787 312.8205388656344 L356.4113400477496 311.90859941297725 L358.85251360972046 310.937222871536 L361.2936871716914 309.9042876529467 L363.73486073366223 308.80764025346855 L366.17603429563314 307.64509525398495 L368.617207857604 306.41443532000267 L371.0583814195749 305.11341120165224 L373.4995549815458 303.7397417336878 L375.9407285435167 302.2911138354871 L378.38190210548754 300.765182511052 L380.82307566745845 299.15957084900737 L383.26424922942937 297.4718700226022 L385.7054227914003 295.6996392897092 L388.14659635337114 293.84040599282446 L390.587769915342 291.8916655590678 L393.0289434773129 289.85088150018294 L395.47011703928376 287.7154854125371 L397.9112906012546 285.48287697712107 L400.3524641632256 283.1504239595494 L402.79363772519645 280.71546221006065 L405.23481128716736 278.1752956635165 L407.6759848491382 275.52719633940274 L410.1171584111091 272.7684043418285 L412.55833197307993 269.8961278595267 L414.9995055350509 266.907543165854 L417.4406790970218 263.79979461879077 L419.88185265899267 260.56999466094106 L422.3230262209635 257.2152238195323 L424.76419978293444 253.732530706416 L427.2053733449053 250.11893201806691 L429.64654690687627 246.3714125355839 L432.0877204688471 242.48692512468926 L434.528894030818 238.462390735729 L436.9700675927889 234.2946984036728 L439.41124115475975 229.98070524811396 L441.8524147167306 225.51723647326966 L444.2935882787016 220.90108536798024 L446.73476184067243 216.12901330571054 L449.17593540264335 211.19774974454825 L451.6171089646142 206.10399222720525 L454.05828252658506 200.84440638101688 L456.4994560885559 195.41562591794235 L458.94062965052683 189.81425263456416 L461.3818032124978 184.03685641208847 L463.82297677446866 178.07997521634616 L466.2641503364395 171.94011509779037 L468.7053238984104 165.6137501914989 L471.1464974603813 159.0973227171725 L473.58767102235214 152.38724297913623 L476.0288445843231 145.4798893663381 L478.47001814629397 138.37160835235073 L480.9111917082649 131.0587144953697 L483.35236527023574 123.53749043821455 L485.7935388322066 115.80418690832826 L488.23471239417745 107.85502271777784 L490.6758859561484 99.68618476325341 L493.11705951811933 91.29382802606958 L495.5582330800902 82.67407557216396 L497.99940664206105 73.82301855209806 L500.4405802040319 64.7367162010571 L502.8817537660028 55.41119583884989 L505.3229273279738 45.8424528699087 L507.76410088994464 36.02645078329033 L510.2052744519155 25.959121152674072 L512.6464480138865 15.636363636363683 \" fill=\"none\" stroke-width=\"1.0\" stroke=\"rgb(17,142,216)\" stroke-opacity=\"1.0\">\n",
" </path>\n",
" </g>\n",
" </g>\n",
" </g>\n",
" <g transform=\"translate(14.5 182.0 ) rotate(-90.0 ) \">\n",
" <text class=\"axis-title-y\" y=\"0.0\" text-anchor=\"middle\">\n",
" y\n",
" </text>\n",
" </g>\n",
" <g transform=\"translate(321.4709081832023 391.5 ) \">\n",
" <text class=\"axis-title-x\" y=\"0.0\" text-anchor=\"middle\">\n",
" x\n",
" </text>\n",
" </g>\n",
" </g>\n",
" <g id=\"dlaccP1\">\n",
" </g>\n",
"</svg>\n",
" <script>document.getElementById(\"b2a23d4b-2d07-4054-9dab-30bfe41e8b1e\").style.display = \"none\";</script>"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"val N = 200\n",
"val start = -1.0\n",
"val end = 10.0\n",
"\n",
"plot {\n",
" line {\n",
" x((0..N).map { start + it * (end - start)/N })\n",
" y((0..N).map { f(start + it * (end - start)/N) })\n",
" }\n",
" // doesn't work because of bug\n",
"// points {\n",
"// val d = data.entries.toList().sortedBy { it.key }\n",
"// x (d.map { it.key })\n",
"// y (d.map { it.value })\n",
"// }\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"data class Point(val x: Double, val y: Double)\n",
"\n",
"fun approximatePolynomial(points: List<Point>, degree: Int): (Double) -> Double {\n",
" val n = points.size\n",
" require(degree >= 0 && degree < n) { \"Degree must be between 0 and ${n - 1}\" }\n",
"\n",
" val xValues = points.map { it.x }\n",
" val yValues = points.map { it.y }\n",
"\n",
" val aMatrix = Array(degree + 1) { DoubleArray(degree + 1) }\n",
" val bVector = DoubleArray(degree + 1)\n",
"\n",
" for (i in 0..degree) {\n",
" for (j in 0..degree) {\n",
" aMatrix[i][j] = sumOfPowers(xValues, i + j)\n",
" }\n",
" bVector[i] = sumOfPowerXY(xValues, yValues, i)\n",
" }\n",
"\n",
" val coefficients = solveSystemOfEquations(aMatrix, bVector)\n",
"\n",
" return { x ->\n",
" var result = 0.0\n",
" for (i in 0..degree) {\n",
" result += coefficients[i] * Math.pow(x, i.toDouble())\n",
" }\n",
" result\n",
" }\n",
"}\n",
"\n",
"fun sumOfPowers(xValues: List<Double>, power: Int): Double {\n",
" var result = 0.0\n",
" for (x in xValues) {\n",
" result += Math.pow(x, power.toDouble())\n",
" }\n",
" return result\n",
"}\n",
"\n",
"fun sumOfPowerXY(xValues: List<Double>, yValues: List<Double>, power: Int): Double {\n",
" var result = 0.0\n",
" for (i in xValues.indices) {\n",
" result += Math.pow(xValues[i], power.toDouble()) * yValues[i]\n",
" }\n",
" return result\n",
"}\n",
"\n",
"fun solveSystemOfEquations(aMatrix: Array<DoubleArray>, bVector: DoubleArray): DoubleArray {\n",
" val n = aMatrix.size\n",
"\n",
" for (p in 0 until n) {\n",
" var maxRow = p\n",
" for (i in p + 1 until n) {\n",
" if (Math.abs(aMatrix[i][p]) > Math.abs(aMatrix[maxRow][p])) {\n",
" maxRow = i\n",
" }\n",
" }\n",
"\n",
" val tempRow = aMatrix[p]\n",
" aMatrix[p] = aMatrix[maxRow]\n",
" aMatrix[maxRow] = tempRow\n",
"\n",
" val tempB = bVector[p]\n",
" bVector[p] = bVector[maxRow]\n",
" bVector[maxRow] = tempB\n",
"\n",
" for (i in p + 1 until n) {\n",
" val factor = aMatrix[i][p] / aMatrix[p][p]\n",
" bVector[i] -= factor * bVector[p]\n",
" for (j in p until n) {\n",
" aMatrix[i][j] -= factor * aMatrix[p][j]\n",
" }\n",
" }\n",
" }\n",
"\n",
" val coefficients = DoubleArray(n)\n",
"\n",
" for (i in n - 1 downTo 0) {\n",
" var sum = 0.0\n",
" for (j in i + 1 until n) {\n",
" sum += aMatrix[i][j] * coefficients[j]\n",
" }\n",
" coefficients[i] = (bVector[i] - sum) / aMatrix[i][i]\n",
" }\n",
"\n",
" return coefficients\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"val h = approximatePolynomial(data.map {Point(it.key.toDouble(), it.value.toDouble())}, 4)"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"8.454545454546231"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"h(3.0)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"12.744588744590772"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"h(7.0)"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"application/plot+json": {
"apply_color_scheme": true,
"output": {
"data": {
"x": [
-1,
-0.945,
-0.89,
-0.835,
-0.78,
-0.725,
-0.6699999999999999,
-0.615,
-0.56,
-0.505,
-0.44999999999999996,
-0.395,
-0.33999999999999997,
-0.28500000000000003,
-0.22999999999999998,
-0.17500000000000004,
-0.12,
-0.06499999999999995,
-0.010000000000000009,
0.04499999999999993,
0.10000000000000009,
0.15500000000000003,
0.20999999999999996,
0.2649999999999999,
0.32000000000000006,
0.375,
0.42999999999999994,
0.4850000000000001,
0.54,
0.595,
0.6499999999999999,
0.7050000000000001,
0.76,
0.815,
0.8700000000000001,
0.925,
0.98,
1.0350000000000001,
1.0899999999999999,
1.145,
1.2000000000000002,
1.255,
1.31,
1.3650000000000002,
1.42,
1.475,
1.5299999999999998,
1.585,
1.6400000000000001,
1.6949999999999998,
1.75,
1.8050000000000002,
1.8599999999999999,
1.915,
1.9700000000000002,
2.025,
2.08,
2.135,
2.19,
2.245,
2.3,
2.355,
2.41,
2.465,
2.52,
2.575,
2.63,
2.685,
2.74,
2.795,
2.85,
2.905,
2.96,
3.0149999999999997,
3.0700000000000003,
3.125,
3.1799999999999997,
3.2350000000000003,
3.29,
3.3449999999999998,
3.4000000000000004,
3.455,
3.51,
3.5650000000000004,
3.62,
3.675,
3.7300000000000004,
3.785,
3.84,
3.8949999999999996,
3.95,
4.005,
4.06,
4.115,
4.17,
4.225,
4.28,
4.335,
4.39,
4.445,
4.5,
4.555,
4.61,
4.665,
4.72,
4.775,
4.83,
4.885,
4.94,
4.995,
5.05,
5.105,
5.16,
5.215,
5.27,
5.325,
5.38,
5.435,
5.49,
5.545,
5.6,
5.655,
5.71,
5.765,
5.82,
5.875,
5.93,
5.985,
6.04,
6.095,
6.15,
6.205,
6.26,
6.315,
6.37,
6.425,
6.48,
6.535,
6.59,
6.645,
6.7,
6.755,
6.81,
6.865,
6.92,
6.975,
7.029999999999999,
7.085000000000001,
7.140000000000001,
7.195,
7.25,
7.305,
7.359999999999999,
7.414999999999999,
7.470000000000001,
7.525,
7.58,
7.635,
7.6899999999999995,
7.744999999999999,
7.800000000000001,
7.855,
7.91,
7.965,
8.02,
8.075,
8.13,
8.185,
8.24,
8.295,
8.35,
8.405,
8.46,
8.515,
8.57,
8.625,
8.68,
8.735,
8.79,
8.845,
8.9,
8.955,
9.01,
9.065,
9.12,
9.175,
9.23,
9.285,
9.34,
9.395,
9.45,
9.505,
9.56,
9.615,
9.67,
9.725,
9.78,
9.835,
9.89,
9.945,
10
],
"y": [
44.285714285869396,
41.74511888232289,
39.311895245912154,
36.98337460819963,
34.75691898012285,
32.629921151994274,
30.59980469350141,
28.664023953706764,
26.82006406104781,
25.06544092333704,
23.39770122776195,
21.814422440885046,
20.3132128086438,
18.891711356350722,
17.5475878886933,
16.278542989734024,
15.082308022910391,
13.95664513103489,
12.899347236295023,
11.908238040253279,
10.981172023847144,
10.116034447389126,
9.31074135056671,
8.563239552442395,
7.871506651453668,
7.233551025413031,
6.6474118315079735,
6.11115900630099,
5.622893265729578,
5.180746105106231,
4.782879799118443,
4.427487401828706,
4.112792746674519,
3.8370504464683757,
3.5985458933977723,
3.3955952590251983,
3.2265454942881546,
3.0897743294991336,
2.9836902743456353,
2.906732617890149,
2.85737142857017,
2.8341075541981984,
2.8354726219617294,
2.8600290384232556,
2.9063699895202815,
2.973119440565285,
3.0589321362457786,
3.162493600624254,
3.2825201371382042,
3.4177588286001255,
3.5669875371975204,
3.729014904492874,
3.9026803514236965,
4.086854078302483,
4.280437064816724,
4.482361070028917,
4.691588632376558,
4.907113069672137,
5.127958479103171,
5.353179737232137,
5.581862499996541,
5.813123202708883,
6.046109060056657,
6.279998066102359,
6.513998994283499,
6.7473513974125545,
6.9793256076770325,
7.209222736639429,
7.43637467523725,
7.660144093782987,
7.879924441964137,
8.095139948843203,
8.305245622857678,
8.509727251820058,
8.70810140291784,
8.899915422713542,
9.084747437144637,
9.262206351523657,
9.43193185053807,
9.593594398250389,
9.746895238098102,
9.891566392893708,
10.027370664824716,
10.154101635453596,
10.271583665717877,
10.379671895930102,
10.4782522457777,
10.567241414323195,
10.64658688000409,
10.716266900632831,
10.776290513397022,
10.826697534859079,
10.867558560956518,
10.89897496700187,
10.92107890768262,
10.934033317061278,
10.938031908575304,
10.933299175037206,
10.920090388634563,
10.898691600929787,
10.869419642860379,
10.83262212473889,
10.788677436252804,
10.737994746464622,
10.681014003811867,
10.618205936106975,
10.55007205053748,
10.477144633665887,
10.399986751429779,
10.31919224914148,
10.235385751488565,
10.14922266253366,
10.06138916571409,
9.972602223842486,
9.883609579106292,
9.795189753068001,
9.708152046665077,
9.623336540210104,
9.541614093390635,
9.463886345269032,
9.391085714282895,
9.324175398244677,
9.26414937434177,
9.212032399136916,
9.16888000856747,
9.135778517945994,
9.113845021959861,
9.104227394671767,
9.108104289519105,
9.126685139314446,
9.161210156245204,
9.212950331873884,
9.283207437138003,
9.373314022350172,
9.484633417197841,
9.618559730743414,
9.776517851424444,
9.959963447053553,
10.170382964818032,
10.409293631280434,
10.678243452378524,
10.978811213424478,
11.31260647910608,
11.681269593485581,
12.08647168000067,
12.52991464146362,
13.013331160061966,
13.538484697358626,
14.107169494290758,
14.7212105711709,
15.382463727686684,
16.092815542900382,
16.854183375249647,
17.66851536254711,
18.537790421979878,
19.464018250110826,
20.44923932287736,
21.495524895591984,
22.60497700294229,
23.779728458990178,
25.02194285717451,
26.333814570306117,
27.717568750573946,
29.175461329539644,
30.709779018140807,
32.32283930669007,
34.016990464875335,
35.79461154175874,
37.658112365777356,
39.60993354474408,
41.65254646584674,
43.788453295647514,
46.02018698008419,
48.35031124446891,
50.781420593489315,
53.31614031120762,
55.95712646106199,
58.70706588586427,
61.568676207802355,
64.54470582843885,
67.63793392871094,
70.85117046893129,
74.18725618878716,
77.64906260734165,
81.23949202303174,
84.96147751366982,
88.81798293644408,
92.81200292791641,
96.94656290402452,
101.22471906008116,
105.64955837077332,
110.22419859016395,
114.95178825169069,
119.83550666816541,
124.87856393177594,
130.0842009140847,
135.4556892660296,
140.99633141792265,
146.70946057945184,
152.59844073967906,
158.6666666670426
]
},
"kind": "plot",
"layers": [
{
"geom": "line",
"mapping": {
"x": "x",
"y": "y"
},
"position": "identity",
"sampling": "none",
"stat": "identity"
}
],
"mapping": {},
"scales": [
{
"aesthetic": "x",
"limits": [
null,
null
]
},
{
"aesthetic": "y",
"limits": [
null,
null
]
}
]
},
"output_type": "lets_plot_spec",
"swing_enabled": true
},
"text/html": [
" <script type=\"text/javascript\" data-lets-plot-script=\"library\" src=\"https://cdn.jsdelivr.net/gh/JetBrains/lets-plot@v3.1.0/js-package/distr/lets-plot.min.js\"></script> \n",
" <div id=\"X3o8TY\"></div>\n",
" <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
" var plotSpec={\n",
"\"mapping\":{\n",
"},\n",
"\"data\":{\n",
"\"x\":[-1.0,-0.945,-0.89,-0.835,-0.78,-0.725,-0.6699999999999999,-0.615,-0.56,-0.505,-0.44999999999999996,-0.395,-0.33999999999999997,-0.28500000000000003,-0.22999999999999998,-0.17500000000000004,-0.12,-0.06499999999999995,-0.010000000000000009,0.04499999999999993,0.10000000000000009,0.15500000000000003,0.20999999999999996,0.2649999999999999,0.32000000000000006,0.375,0.42999999999999994,0.4850000000000001,0.54,0.595,0.6499999999999999,0.7050000000000001,0.76,0.815,0.8700000000000001,0.925,0.98,1.0350000000000001,1.0899999999999999,1.145,1.2000000000000002,1.255,1.31,1.3650000000000002,1.42,1.475,1.5299999999999998,1.585,1.6400000000000001,1.6949999999999998,1.75,1.8050000000000002,1.8599999999999999,1.915,1.9700000000000002,2.025,2.08,2.135,2.19,2.245,2.3,2.355,2.41,2.465,2.52,2.575,2.63,2.685,2.74,2.795,2.85,2.905,2.96,3.0149999999999997,3.0700000000000003,3.125,3.1799999999999997,3.2350000000000003,3.29,3.3449999999999998,3.4000000000000004,3.455,3.51,3.5650000000000004,3.62,3.675,3.7300000000000004,3.785,3.84,3.8949999999999996,3.95,4.005,4.06,4.115,4.17,4.225,4.28,4.335,4.39,4.445,4.5,4.555,4.61,4.665,4.72,4.775,4.83,4.885,4.94,4.995,5.05,5.105,5.16,5.215,5.27,5.325,5.38,5.435,5.49,5.545,5.6,5.655,5.71,5.765,5.82,5.875,5.93,5.985,6.04,6.095,6.15,6.205,6.26,6.315,6.37,6.425,6.48,6.535,6.59,6.645,6.7,6.755,6.81,6.865,6.92,6.975,7.029999999999999,7.085000000000001,7.140000000000001,7.195,7.25,7.305,7.359999999999999,7.414999999999999,7.470000000000001,7.525,7.58,7.635,7.6899999999999995,7.744999999999999,7.800000000000001,7.855,7.91,7.965,8.02,8.075,8.13,8.185,8.24,8.295,8.35,8.405,8.46,8.515,8.57,8.625,8.68,8.735,8.79,8.845,8.9,8.955,9.01,9.065,9.12,9.175,9.23,9.285,9.34,9.395,9.45,9.505,9.56,9.615,9.67,9.725,9.78,9.835,9.89,9.945,10.0],\n",
"\"y\":[44.285714285869396,41.74511888232289,39.311895245912154,36.98337460819963,34.75691898012285,32.629921151994274,30.59980469350141,28.664023953706764,26.82006406104781,25.06544092333704,23.39770122776195,21.814422440885046,20.3132128086438,18.891711356350722,17.5475878886933,16.278542989734024,15.082308022910391,13.95664513103489,12.899347236295023,11.908238040253279,10.981172023847144,10.116034447389126,9.31074135056671,8.563239552442395,7.871506651453668,7.233551025413031,6.6474118315079735,6.11115900630099,5.622893265729578,5.180746105106231,4.782879799118443,4.427487401828706,4.112792746674519,3.8370504464683757,3.5985458933977723,3.3955952590251983,3.2265454942881546,3.0897743294991336,2.9836902743456353,2.906732617890149,2.85737142857017,2.8341075541981984,2.8354726219617294,2.8600290384232556,2.9063699895202815,2.973119440565285,3.0589321362457786,3.162493600624254,3.2825201371382042,3.4177588286001255,3.5669875371975204,3.729014904492874,3.9026803514236965,4.086854078302483,4.280437064816724,4.482361070028917,4.691588632376558,4.907113069672137,5.127958479103171,5.353179737232137,5.581862499996541,5.813123202708883,6.046109060056657,6.279998066102359,6.513998994283499,6.7473513974125545,6.9793256076770325,7.209222736639429,7.43637467523725,7.660144093782987,7.879924441964137,8.095139948843203,8.305245622857678,8.509727251820058,8.70810140291784,8.899915422713542,9.084747437144637,9.262206351523657,9.43193185053807,9.593594398250389,9.746895238098102,9.891566392893708,10.027370664824716,10.154101635453596,10.271583665717877,10.379671895930102,10.4782522457777,10.567241414323195,10.64658688000409,10.716266900632831,10.776290513397022,10.826697534859079,10.867558560956518,10.89897496700187,10.92107890768262,10.934033317061278,10.938031908575304,10.933299175037206,10.920090388634563,10.898691600929787,10.869419642860379,10.83262212473889,10.788677436252804,10.737994746464622,10.681014003811867,10.618205936106975,10.55007205053748,10.477144633665887,10.399986751429779,10.31919224914148,10.235385751488565,10.14922266253366,10.06138916571409,9.972602223842486,9.883609579106292,9.795189753068001,9.708152046665077,9.623336540210104,9.541614093390635,9.463886345269032,9.391085714282895,9.324175398244677,9.26414937434177,9.212032399136916,9.16888000856747,9.135778517945994,9.113845021959861,9.104227394671767,9.108104289519105,9.126685139314446,9.161210156245204,9.212950331873884,9.283207437138003,9.373314022350172,9.484633417197841,9.618559730743414,9.776517851424444,9.959963447053553,10.170382964818032,10.409293631280434,10.678243452378524,10.978811213424478,11.31260647910608,11.681269593485581,12.08647168000067,12.52991464146362,13.013331160061966,13.538484697358626,14.107169494290758,14.7212105711709,15.382463727686684,16.092815542900382,16.854183375249647,17.66851536254711,18.537790421979878,19.464018250110826,20.44923932287736,21.495524895591984,22.60497700294229,23.779728458990178,25.02194285717451,26.333814570306117,27.717568750573946,29.175461329539644,30.709779018140807,32.32283930669007,34.016990464875335,35.79461154175874,37.658112365777356,39.60993354474408,41.65254646584674,43.788453295647514,46.02018698008419,48.35031124446891,50.781420593489315,53.31614031120762,55.95712646106199,58.70706588586427,61.568676207802355,64.54470582843885,67.63793392871094,70.85117046893129,74.18725618878716,77.64906260734165,81.23949202303174,84.96147751366982,88.81798293644408,92.81200292791641,96.94656290402452,101.22471906008116,105.64955837077332,110.22419859016395,114.95178825169069,119.83550666816541,124.87856393177594,130.0842009140847,135.4556892660296,140.99633141792265,146.70946057945184,152.59844073967906,158.6666666670426]\n",
"},\n",
"\"kind\":\"plot\",\n",
"\"scales\":[{\n",
"\"aesthetic\":\"x\",\n",
"\"limits\":[null,null]\n",
"},{\n",
"\"aesthetic\":\"y\",\n",
"\"limits\":[null,null]\n",
"}],\n",
"\"layers\":[{\n",
"\"mapping\":{\n",
"\"x\":\"x\",\n",
"\"y\":\"y\"\n",
"},\n",
"\"stat\":\"identity\",\n",
"\"sampling\":\"none\",\n",
"\"position\":\"identity\",\n",
"\"geom\":\"line\",\n",
"\"data\":{\n",
"}\n",
"}]\n",
"};\n",
" var plotContainer = document.getElementById(\"X3o8TY\");\n",
" LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
" </script> \n",
" <svg id=743cb5ee-031f-4b7a-be11-34148100c107 xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" class=\"plt-container\" width=\"600.0\" height=\"400.0\">\n",
" <style type=\"text/css\">\n",
" .plt-container {\n",
" font-family: Lucida Grande, sans-serif;\n",
" user-select: none;\n",
" -webkit-user-select: none;\n",
" -moz-user-select: none;\n",
" -ms-user-select: none;\n",
"}\n",
"text {\n",
" text-rendering: optimizeLegibility;\n",
"}\n",
"#pLNkDgc .plot-title {\n",
" fill: #474747;\n",
" font-family: Lucida Grande, sans-serif;\n",
" font-size: 16.0px;\n",
" font-weight: normal;\n",
" font-style: normal; \n",
"}\n",
"#pLNkDgc .plot-subtitle {\n",
" fill: #474747;\n",
" font-family: Lucida Grande, sans-serif;\n",
" font-size: 15.0px;\n",
" font-weight: normal;\n",
" font-style: normal; \n",
"}\n",
"#pLNkDgc .plot-caption {\n",
" fill: #474747;\n",
" font-family: Lucida Grande, sans-serif;\n",
" font-size: 13.0px;\n",
" font-weight: normal;\n",
" font-style: normal; \n",
"}\n",
"#pLNkDgc .legend-title {\n",
" fill: #474747;\n",
" font-family: Lucida Grande, sans-serif;\n",
" font-size: 15.0px;\n",
" font-weight: normal;\n",
" font-style: normal; \n",
"}\n",
"#pLNkDgc .legend-item {\n",
" fill: #474747;\n",
" font-family: Lucida Grande, sans-serif;\n",
" font-size: 13.0px;\n",
" font-weight: normal;\n",
" font-style: normal; \n",
"}\n",
"#pLNkDgc .axis-title-x {\n",
" fill: #474747;\n",
" font-family: Lucida Grande, sans-serif;\n",
" font-size: 15.0px;\n",
" font-weight: normal;\n",
" font-style: normal; \n",
"}\n",
"#pLNkDgc .axis-text-x {\n",
" fill: #474747;\n",
" font-family: Lucida Grande, sans-serif;\n",
" font-size: 13.0px;\n",
" font-weight: normal;\n",
" font-style: normal; \n",
"}\n",
"#dwe5M1g .axis-tooltip-text-x {\n",
" fill: #ffffff;\n",
" font-family: Lucida Grande, sans-serif;\n",
" font-size: 13.0px;\n",
" font-weight: normal;\n",
" font-style: normal; \n",
"}\n",
"#pLNkDgc .axis-title-y {\n",
" fill: #474747;\n",
" font-family: Lucida Grande, sans-serif;\n",
" font-size: 15.0px;\n",
" font-weight: normal;\n",
" font-style: normal; \n",
"}\n",
"#pLNkDgc .axis-text-y {\n",
" fill: #474747;\n",
" font-family: Lucida Grande, sans-serif;\n",
" font-size: 13.0px;\n",
" font-weight: normal;\n",
" font-style: normal; \n",
"}\n",
"#dwe5M1g .axis-tooltip-text-y {\n",
" fill: #ffffff;\n",
" font-family: Lucida Grande, sans-serif;\n",
" font-size: 13.0px;\n",
" font-weight: normal;\n",
" font-style: normal; \n",
"}\n",
"#pLNkDgc .facet-strip-text-x {\n",
" fill: #474747;\n",
" font-family: Lucida Grande, sans-serif;\n",
" font-size: 13.0px;\n",
" font-weight: normal;\n",
" font-style: normal; \n",
"}\n",
"#pLNkDgc .facet-strip-text-y {\n",
" fill: #474747;\n",
" font-family: Lucida Grande, sans-serif;\n",
" font-size: 13.0px;\n",
" font-weight: normal;\n",
" font-style: normal; \n",
"}\n",
"#dwe5M1g .tooltip-text {\n",
" fill: #474747;\n",
" font-family: Lucida Grande, sans-serif;\n",
" font-size: 13.0px;\n",
" font-weight: normal;\n",
" font-style: normal; \n",
"}\n",
"#dwe5M1g .tooltip-title {\n",
" fill: #474747;\n",
" font-family: Lucida Grande, sans-serif;\n",
" font-size: 13.0px;\n",
" font-weight: bold;\n",
" font-style: normal; \n",
"}\n",
"#dwe5M1g .tooltip-label {\n",
" fill: #474747;\n",
" font-family: Lucida Grande, sans-serif;\n",
" font-size: 13.0px;\n",
" font-weight: bold;\n",
" font-style: normal; \n",
"}\n",
"\n",
" </style>\n",
" <g id=\"pLNkDgc\">\n",
" <rect x=\"0.0\" y=\"0.0\" height=\"400.0\" width=\"600.0\" stroke=\"rgb(71,71,71)\" stroke-opacity=\"1.0\" stroke-width=\"0.0\" fill=\"rgb(255,255,255)\" fill-opacity=\"1.0\">\n",
" </rect>\n",
" <g transform=\"translate(23.0 10.0 ) \">\n",
" <g transform=\"translate(29.941816366404606 344.0 ) \">\n",
" <line x1=\"68.79670947372502\" y1=\"-0.0\" x2=\"68.79670947372502\" y2=\"-344.0\" stroke=\"rgb(233,233,233)\" stroke-opacity=\"1.0\" stroke-width=\"1.0\">\n",
" </line>\n",
" <line x1=\"157.5666571817573\" y1=\"-0.0\" x2=\"157.5666571817573\" y2=\"-344.0\" stroke=\"rgb(233,233,233)\" stroke-opacity=\"1.0\" stroke-width=\"1.0\">\n",
" </line>\n",
" <line x1=\"246.33660488978956\" y1=\"-0.0\" x2=\"246.33660488978956\" y2=\"-344.0\" stroke=\"rgb(233,233,233)\" stroke-opacity=\"1.0\" stroke-width=\"1.0\">\n",
" </line>\n",
" <line x1=\"335.1065525978218\" y1=\"-0.0\" x2=\"335.1065525978218\" y2=\"-344.0\" stroke=\"rgb(233,233,233)\" stroke-opacity=\"1.0\" stroke-width=\"1.0\">\n",
" </line>\n",
" <line x1=\"423.8765003058541\" y1=\"-0.0\" x2=\"423.8765003058541\" y2=\"-344.0\" stroke=\"rgb(233,233,233)\" stroke-opacity=\"1.0\" stroke-width=\"1.0\">\n",
" </line>\n",
" <line x1=\"512.6464480138865\" y1=\"-0.0\" x2=\"512.6464480138865\" y2=\"-344.0\" stroke=\"rgb(233,233,233)\" stroke-opacity=\"1.0\" stroke-width=\"1.0\">\n",
" </line>\n",
" <g transform=\"translate(68.79670947372502 0.0 ) \">\n",
" <line stroke-width=\"1.0\" stroke=\"rgb(71,71,71)\" stroke-opacity=\"1.0\" x2=\"0.0\" y2=\"4.0\">\n",
" </line>\n",
" <g transform=\"translate(0.0 7.0 ) \">\n",
" <text class=\"axis-text-x\" text-anchor=\"middle\" dy=\"0.7em\">\n",
" 0\n",
" </text>\n",
" </g>\n",
" </g>\n",
" <g transform=\"translate(157.5666571817573 0.0 ) \">\n",
" <line stroke-width=\"1.0\" stroke=\"rgb(71,71,71)\" stroke-opacity=\"1.0\" x2=\"0.0\" y2=\"4.0\">\n",
" </line>\n",
" <g transform=\"translate(0.0 7.0 ) \">\n",
" <text class=\"axis-text-x\" text-anchor=\"middle\" dy=\"0.7em\">\n",
" 2\n",
" </text>\n",
" </g>\n",
" </g>\n",
" <g transform=\"translate(246.33660488978956 0.0 ) \">\n",
" <line stroke-width=\"1.0\" stroke=\"rgb(71,71,71)\" stroke-opacity=\"1.0\" x2=\"0.0\" y2=\"4.0\">\n",
" </line>\n",
" <g transform=\"translate(0.0 7.0 ) \">\n",
" <text class=\"axis-text-x\" text-anchor=\"middle\" dy=\"0.7em\">\n",
" 4\n",
" </text>\n",
" </g>\n",
" </g>\n",
" <g transform=\"translate(335.1065525978218 0.0 ) \">\n",
" <line stroke-width=\"1.0\" stroke=\"rgb(71,71,71)\" stroke-opacity=\"1.0\" x2=\"0.0\" y2=\"4.0\">\n",
" </line>\n",
" <g transform=\"translate(0.0 7.0 ) \">\n",
" <text class=\"axis-text-x\" text-anchor=\"middle\" dy=\"0.7em\">\n",
" 6\n",
" </text>\n",
" </g>\n",
" </g>\n",
" <g transform=\"translate(423.8765003058541 0.0 ) \">\n",
" <line stroke-width=\"1.0\" stroke=\"rgb(71,71,71)\" stroke-opacity=\"1.0\" x2=\"0.0\" y2=\"4.0\">\n",
" </line>\n",
" <g transform=\"translate(0.0 7.0 ) \">\n",
" <text class=\"axis-text-x\" text-anchor=\"middle\" dy=\"0.7em\">\n",
" 8\n",
" </text>\n",
" </g>\n",
" </g>\n",
" <g transform=\"translate(512.6464480138865 0.0 ) \">\n",
" <line stroke-width=\"1.0\" stroke=\"rgb(71,71,71)\" stroke-opacity=\"1.0\" x2=\"0.0\" y2=\"4.0\">\n",
" </line>\n",
" <g transform=\"translate(0.0 7.0 ) \">\n",
" <text class=\"axis-text-x\" text-anchor=\"middle\" dy=\"0.7em\">\n",
" 10\n",
" </text>\n",
" </g>\n",
" </g>\n",
" <line x1=\"0.0\" y1=\"0.0\" x2=\"537.0581836335954\" y2=\"0.0\" stroke-width=\"1.0\" stroke=\"rgb(71,71,71)\" stroke-opacity=\"1.0\">\n",
" </line>\n",
" </g>\n",
" <g transform=\"translate(29.941816366404606 0.0 ) \">\n",
" <line x1=\"0.0\" y1=\"334.0511687450969\" x2=\"537.0581836335954\" y2=\"334.0511687450969\" stroke=\"rgb(233,233,233)\" stroke-opacity=\"1.0\" stroke-width=\"1.0\">\n",
" </line>\n",
" <line x1=\"0.0\" y1=\"293.9148487735029\" x2=\"537.0581836335954\" y2=\"293.9148487735029\" stroke=\"rgb(233,233,233)\" stroke-opacity=\"1.0\" stroke-width=\"1.0\">\n",
" </line>\n",
" <line x1=\"0.0\" y1=\"253.77852880190895\" x2=\"537.0581836335954\" y2=\"253.77852880190895\" stroke=\"rgb(233,233,233)\" stroke-opacity=\"1.0\" stroke-width=\"1.0\">\n",
" </line>\n",
" <line x1=\"0.0\" y1=\"213.64220883031498\" x2=\"537.0581836335954\" y2=\"213.64220883031498\" stroke=\"rgb(233,233,233)\" stroke-opacity=\"1.0\" stroke-width=\"1.0\">\n",
" </line>\n",
" <line x1=\"0.0\" y1=\"173.505888858721\" x2=\"537.0581836335954\" y2=\"173.505888858721\" stroke=\"rgb(233,233,233)\" stroke-opacity=\"1.0\" stroke-width=\"1.0\">\n",
" </line>\n",
" <line x1=\"0.0\" y1=\"133.369568887127\" x2=\"537.0581836335954\" y2=\"133.369568887127\" stroke=\"rgb(233,233,233)\" stroke-opacity=\"1.0\" stroke-width=\"1.0\">\n",
" </line>\n",
" <line x1=\"0.0\" y1=\"93.23324891553304\" x2=\"537.0581836335954\" y2=\"93.23324891553304\" stroke=\"rgb(233,233,233)\" stroke-opacity=\"1.0\" stroke-width=\"1.0\">\n",
" </line>\n",
" <line x1=\"0.0\" y1=\"53.096928943939076\" x2=\"537.0581836335954\" y2=\"53.096928943939076\" stroke=\"rgb(233,233,233)\" stroke-opacity=\"1.0\" stroke-width=\"1.0\">\n",
" </line>\n",
" <line x1=\"0.0\" y1=\"12.960608972345085\" x2=\"537.0581836335954\" y2=\"12.960608972345085\" stroke=\"rgb(233,233,233)\" stroke-opacity=\"1.0\" stroke-width=\"1.0\">\n",
" </line>\n",
" <g transform=\"translate(0.0 334.0511687450969 ) \">\n",
" <g transform=\"translate(-3.0 0.0 ) \">\n",
" <text class=\"axis-text-y\" text-anchor=\"end\" dy=\"0.35em\">\n",
" 0\n",
" </text>\n",
" </g>\n",
" </g>\n",
" <g transform=\"translate(0.0 293.9148487735029 ) \">\n",
" <g transform=\"translate(-3.0 0.0 ) \">\n",
" <text class=\"axis-text-y\" text-anchor=\"end\" dy=\"0.35em\">\n",
" 20\n",
" </text>\n",
" </g>\n",
" </g>\n",
" <g transform=\"translate(0.0 253.77852880190895 ) \">\n",
" <g transform=\"translate(-3.0 0.0 ) \">\n",
" <text class=\"axis-text-y\" text-anchor=\"end\" dy=\"0.35em\">\n",
" 40\n",
" </text>\n",
" </g>\n",
" </g>\n",
" <g transform=\"translate(0.0 213.64220883031498 ) \">\n",
" <g transform=\"translate(-3.0 0.0 ) \">\n",
" <text class=\"axis-text-y\" text-anchor=\"end\" dy=\"0.35em\">\n",
" 60\n",
" </text>\n",
" </g>\n",
" </g>\n",
" <g transform=\"translate(0.0 173.505888858721 ) \">\n",
" <g transform=\"translate(-3.0 0.0 ) \">\n",
" <text class=\"axis-text-y\" text-anchor=\"end\" dy=\"0.35em\">\n",
" 80\n",
" </text>\n",
" </g>\n",
" </g>\n",
" <g transform=\"translate(0.0 133.369568887127 ) \">\n",
" <g transform=\"translate(-3.0 0.0 ) \">\n",
" <text class=\"axis-text-y\" text-anchor=\"end\" dy=\"0.35em\">\n",
" 100\n",
" </text>\n",
" </g>\n",
" </g>\n",
" <g transform=\"translate(0.0 93.23324891553304 ) \">\n",
" <g transform=\"translate(-3.0 0.0 ) \">\n",
" <text class=\"axis-text-y\" text-anchor=\"end\" dy=\"0.35em\">\n",
" 120\n",
" </text>\n",
" </g>\n",
" </g>\n",
" <g transform=\"translate(0.0 53.096928943939076 ) \">\n",
" <g transform=\"translate(-3.0 0.0 ) \">\n",
" <text class=\"axis-text-y\" text-anchor=\"end\" dy=\"0.35em\">\n",
" 140\n",
" </text>\n",
" </g>\n",
" </g>\n",
" <g transform=\"translate(0.0 12.960608972345085 ) \">\n",
" <g transform=\"translate(-3.0 0.0 ) \">\n",
" <text class=\"axis-text-y\" text-anchor=\"end\" dy=\"0.35em\">\n",
" 160\n",
" </text>\n",
" </g>\n",
" </g>\n",
" </g>\n",
" <g transform=\"translate(29.941816366404606 0.0 ) \" clip-path=\"url(#c3cNfLg)\" clip-bounds-jfx=\"[rect (0.0, 0.0), (537.0581836335954, 344.0)]\">\n",
" <defs>\n",
" <clipPath id=\"c3cNfLg\">\n",
" <rect x=\"0.0\" y=\"0.0\" width=\"537.0581836335954\" height=\"344.0\">\n",
" </rect>\n",
" </clipPath>\n",
" </defs>\n",
" <g>\n",
" <path d=\"M24.411735619708878 245.17788880768467 L24.411735619708878 245.17788880768467 L26.85290918167977 250.27639630943986 L29.294082743650655 255.15942843111117 L31.73525630562154 259.83234089989566 L34.176429867592425 264.300427674448 L36.61760342956332 268.5689209448807 L39.0587769915342 272.6429911327641 L41.49995055350509 276.52774689112647 L43.94112411547597 280.22823510445374 L46.38229767744687 283.74944088868983 L48.823471239417756 287.0962875912364 L51.26464480138864 290.27363679095276 L53.70581836335953 293.2862882981565 L56.14699192533041 296.13898015462246 L58.5881654873013 298.83638863358385 L61.02933904927219 301.38312823973126 L63.47051261124308 303.7837517092134 L65.91168617321397 306.0427500096366 L68.35285973518485 308.1645523400652 L70.79403329715574 310.15352613102124 L73.23520685912663 312.01397704448465 L75.67638042109752 313.75014897389303 L78.1175539830684 315.3662240441421 L80.55872754503929 316.866322611585 L82.99990110701019 318.2545032640332 L85.44107466898106 319.5347628207554 L87.88224823095194 320.7110363324787 L90.32342179292284 321.78719708138766 L92.76459535489373 322.76705658112473 L95.20576891686461 323.6543645767903 L97.6469424788355 324.45280904494234 L100.0881160408064 325.166016193597 L102.52928960277728 325.79755046222795 L104.97046316474817 326.3509145217668 L107.41163672671905 326.829549274603 L109.85281028868994 327.2368338545838 L112.29398385066082 327.5760856270142 L114.73515741263174 327.8505601886572 L117.17633097460259 328.0634513677334 L119.6175045365735 328.2178912239215 L122.05867809854439 328.31695004835774 L124.49985166051528 328.3636363636364 L126.94102522248616 328.3608969238094 L129.38219878445705 328.3116167143866 L131.82337234642793 328.2186189523357 L134.26454590839882 328.08466508608217 L136.7057194703697 327.9124547955093 L139.14689303234059 327.7046259919582 L141.5880665943115 327.4637548182279 L144.02924015628236 327.19235564857513 L146.47041371825327 326.89288108871455 L148.91158728022415 326.5677219758185 L151.35276084219504 326.2192073785172 L153.79393440416592 325.8496045968988 L156.2351079661368 325.4611191625092 L158.6762815281077 325.05589483835206 L161.11745509007858 324.63601361888897 L163.55862865204946 324.2034957300393 L165.99980221402035 323.7602996291802 L168.44097577599126 323.3083220051468 L170.88214933796212 322.8493977782318 L173.32332289993303 322.3853001001859 L175.76449646190392 321.9177403542175 L178.2056700238748 321.4483681549931 L180.6468435858457 320.9787713486367 L183.08801714781657 320.5104760127303 L185.52919070978746 320.04494645631365 L187.97036427175834 319.58358521988436 L190.41153783372926 319.1277330753979 L192.8527113957001 318.6786690262674 L195.29388495767103 318.2376103073641 L197.73505851964188 317.8057123850167 L200.1762320816128 317.3840689570121 L202.61740564358365 316.9737119525947 L205.05857920555457 316.57561153246706 L207.49975276752542 316.19067608878913 L209.94092632949634 315.81975224517913 L212.38209989146725 315.4636248567127 L214.8232734534381 315.1230170099237 L217.26444701540896 314.79859002280347 L219.70562057737988 314.49094344480136 L222.1467941393508 314.2006150568245 L224.58796770132165 313.9280808712379 L227.02914126329256 313.67375513186437 L229.47031482526342 313.43799031398436 L231.91148838723433 313.2210771243363 L234.35266194920524 313.02324450111655 L236.7938355111761 312.84465961397916 L239.23500907314695 312.685427864036 L241.67618263511787 312.54559288385684 L244.11735619708878 312.42513653746914 L246.55852975905964 312.3239789203583 L248.9997033210305 312.24197835946757 L251.4408768830014 312.1789314131979 L253.88205044497232 312.1345728714081 L256.3232240069432 312.1085757554149 L258.7643975689141 312.10055131799277 L261.20557113088495 312.11004904337403 L263.64674469285586 312.13655664724865 L266.0879182548268 312.17950007676484 L268.52909181679763 312.23824351052826 L270.9702653787685 312.31208935860246 L273.4114389407394 312.40027826250895 L275.8526125027103 312.5019890952269 L278.29378606468117 312.61633896119343 L280.7349596266521 312.7423831963035 L283.17613318862294 312.8791153679098 L285.61730675059385 313.02546727482274 L288.05848031256477 313.1803089473107 L290.4996538745356 313.3424486471001 L292.9408274365065 313.51063286737497 L295.3820009984774 313.6835463327767 L297.8231745604483 313.8598119994054 L300.26434812241916 314.0379910548183 L302.70552168439 314.21658291803084 L305.14669524636093 314.3940252395161 L307.58786880833185 314.56869390120517 L310.0290423703027 314.73890301648663 L312.4702159322736 314.90290493020706 L314.9113894942445 315.0588902186711 L317.3525630562154 315.20498768964075 L319.7937366181863 315.33926438233624 L322.23491018015716 315.4597255674357 L324.676083742128 315.56431474707443 L327.1172573040989 315.65091365484614 L329.55843086606984 315.7173422558021 L331.9996044280407 315.7613587464519 L334.4407779900116 315.78065955476205 L336.88195155198247 315.7728793401576 L339.3231251139534 315.7355909935211 L341.7642986759243 315.6663056371932 L344.20547223789515 315.56247262497226 L346.646645799866 315.4214795421143 L349.0878193618369 315.24065220533316 L351.52899292380783 315.0172546628006 L353.9701664857787 314.7484891941466 L356.4113400477496 314.43149631045833 L358.85251360972046 314.0633547542808 L361.2936871716914 313.64108149961766 L363.73486073366223 313.1616317519296 L366.17603429563314 312.62189894813474 L368.617207857604 312.01871475661045 L371.0583814195749 311.34884907719044 L373.4995549815458 310.60901004116744 L375.9407285435167 309.7958440112911 L378.38190210548754 308.9059355817697 L380.82307566745845 307.93580757826885 L383.26424922942937 306.8819210579112 L385.7054227914003 305.74067530927874 L388.14659635337114 304.5084078524105 L390.587769915342 303.18139443880335 L393.0289434773129 301.7558490514124 L395.47011703928376 300.2279239046499 L397.9112906012546 298.59370944438615 L400.3524641632256 296.8492343479502 L402.79363772519645 294.9904655241273 L405.23481128716736 293.01330811316154 L407.6759848491382 290.9136054867547 L410.1171584111091 288.68713924806616 L412.55833197307993 286.3296292317144 L414.9995055350509 283.83673350377205 L417.4406790970218 281.2040483617754 L419.88185265899267 278.4271083347124 L422.3230262209635 275.5013861830334 L424.76419978293444 272.42229289864474 L427.2053733449053 269.18517770491053 L429.64654690687627 265.785328056652 L432.0877204688471 262.21796964014993 L434.528894030818 258.4782663731429 L436.9700675927889 254.56132040482578 L439.41124115475975 250.46217211585136 L441.8524147167306 246.17580011833152 L444.2935882787016 241.6971212558348 L446.73476184067243 237.02099060338878 L449.17593540264335 232.14220146747795 L451.6171089646142 227.05548538604546 L454.05828252658506 221.7555121284903 L456.4994560885559 216.236889695672 L458.94062965052683 210.49416431990585 L461.3818032124978 204.5218204649655 L463.82297677446866 198.31428082608318 L466.2641503364395 191.86590632994807 L468.7053238984104 185.17099613470805 L471.1464974603813 178.223787629967 L473.58767102235214 171.01845643678897 L476.0288445843231 163.54911640769495 L478.47001814629397 155.8098196266622 L480.9111917082649 147.79455640912838 L483.35236527023574 139.49725530198734 L485.7935388322066 130.91178308359065 L488.23471239417745 122.03194476374924 L490.6758859561484 112.85148358372999 L493.11705951811933 103.36408101625815 L495.5582330800902 93.56335676551836 L497.99940664206105 83.4428687671512 L500.4405802040319 72.99611318825583 L502.8817537660028 62.21652442738832 L505.3229273279738 51.097475114564304 L507.76410088994464 39.632276111255294 L510.2052744519155 27.814176510392826 L512.6464480138865 15.63636363636357 \" fill=\"none\" stroke-width=\"1.0\" stroke=\"rgb(17,142,216)\" stroke-opacity=\"1.0\">\n",
" </path>\n",
" </g>\n",
" </g>\n",
" </g>\n",
" <g transform=\"translate(14.5 182.0 ) rotate(-90.0 ) \">\n",
" <text class=\"axis-title-y\" y=\"0.0\" text-anchor=\"middle\">\n",
" y\n",
" </text>\n",
" </g>\n",
" <g transform=\"translate(321.4709081832023 391.5 ) \">\n",
" <text class=\"axis-title-x\" y=\"0.0\" text-anchor=\"middle\">\n",
" x\n",
" </text>\n",
" </g>\n",
" </g>\n",
" <g id=\"dwe5M1g\">\n",
" </g>\n",
"</svg>\n",
" <script>document.getElementById(\"743cb5ee-031f-4b7a-be11-34148100c107\").style.display = \"none\";</script>"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"plot {\n",
" line {\n",
" x((0..N).map { start + it * (end - start)/N })\n",
" y((0..N).map { h(start + it * (end - start)/N) })\n",
" }\n",
" // doesn't work because of bug\n",
"// points {\n",
"// val d = data.entries.toList().sortedBy { it.key }\n",
"// x (d.map { it.key })\n",
"// y (d.map { it.value })\n",
"// }\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Kotlin",
"language": "kotlin",
"name": "kotlin"
},
"language_info": {
"codemirror_mode": "text/x-kotlin",
"file_extension": ".kt",
"mimetype": "text/x-kotlin",
"name": "kotlin",
"nbconvert_exporter": "",
"pygments_lexer": "kotlin",
"version": "1.8.20"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment