{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "919acae4", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%useLatestDescriptors\n", "%use lets-plot" ] }, { "cell_type": "code", "execution_count": 2, "id": "a04be5ce", "metadata": {}, "outputs": [], "source": [ "fun linspace(start: Double, stop: Double, num: Int): List {\n", " return List(num) { i -> start + i * ((stop - start) / (num - 1)) }\n", "}" ] }, { "cell_type": "code", "execution_count": 3, "id": "679e2247", "metadata": {}, "outputs": [], "source": [ "fun F(x: Double, y: Double, a: Double = 0.0, b: Double = 0.0): Double {\n", " return y.pow(2) - x.pow(3) - a * x - b\n", "}\n", "\n", "fun level(z: Double, c: Double = 1.0): Double {\n", " return exp(-c * abs(z))\n", "}" ] }, { "cell_type": "code", "execution_count": 4, "id": "6824d0ac", "metadata": {}, "outputs": [], "source": [ "val n = 300\n", "val a = -1.0\n", "val b = 0.0\n", "val xRange = linspace(-3.0, 3.0, n + 1)\n", "val yRange = linspace(-3.0, 3.0, n + 1)\n", "val zippedData = xRange.map { x ->\n", " yRange.map { y -> Triple(x, y, level(F(x, y, a = a, b = b), c = 10.0)) }\n", "}.flatten()\n", "val data = mapOf(\n", " \"x\" to zippedData.map { it.first },\n", " \"y\" to zippedData.map { it.second },\n", " \"z\" to zippedData.map { it.third },\n", ")" ] }, { "cell_type": "code", "execution_count": 5, "id": "f73cead8", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "letsPlot(data) +\n", " geomRaster(showLegend = false) { x=\"x\"; y=\"y\"; fill=\"z\" } +\n", " scaleFillGradient(low=\"#253494\", high=\"#ffffcc\") +\n", " ggtitle(\"Elliptic curve with a = $a, b = $b\",\n", " \"Simple way to draw an algebraic curve - with geomRaster()\") +\n", " ggsize(800, 600) +\n", " themeClassic() + theme(axis = \"blank\")" ] } ], "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": 5 }