Skip to content

Instantly share code, notes, and snippets.

@ohno

ohno/hello.ipynb Secret

Last active October 27, 2022 11:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ohno/1291f2b167e665ec4c04886e4cf0e8fd to your computer and use it in GitHub Desktop.
Save ohno/1291f2b167e665ec4c04886e4cf0e8fd to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "750b96e8",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Hello World!\n"
]
}
],
"source": [
"println(\"Hello World!\")"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "dfa83b41",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"2"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"x = 1\n",
"y = 2\n",
"x = y"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "fe3c867c",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"3"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"x = 1\n",
"y = 2\n",
"z = x + y"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "1d6ec4c5",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"3"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"z"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "69861ec0",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"3\n"
]
}
],
"source": [
"println(z)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "46de657f",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1.0"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sin(π/2)"
]
},
{
"cell_type": "markdown",
"id": "5913c47f",
"metadata": {},
"source": [
"# マークダウンの例\n",
"\n",
"例えば加法定理は以下のように書く.\n",
"\n",
"$$\n",
" \\sin(\\alpha+\\beta) = \\sin\\alpha \\cdot \\cos\\beta + \\cos\\alpha \\cdot \\sin\\beta\n",
"$$"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "a6dffe92",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0.1411200080598672\n",
"0.1411200080598673\n"
]
}
],
"source": [
"α = 1\n",
"β = 2\n",
"println( sin(α+β) )\n",
"println( sin(α)*cos(β)+cos(α)*sin(β) )"
]
},
{
"cell_type": "markdown",
"id": "d908ab57",
"metadata": {},
"source": [
"# グラフを描写する\n",
"\n",
"Juliaでは, Plots.jlというパッケージを用いて関数や配列をプロットすることができる. CSVファイルなどをプロットしたい場合は, CSV.jlなどを用いて, データを配列に格納する必要がある."
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "09c3e8f3",
"metadata": {},
"outputs": [],
"source": [
"# using Pkg\n",
"# Pkg.add(\"Plots\")\n",
"using Plots"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "5a265ecf",
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n",
"<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"600\" height=\"400\" viewBox=\"0 0 2400 1600\">\n",
"<defs>\n",
" <clipPath id=\"clip910\">\n",
" <rect x=\"0\" y=\"0\" width=\"2400\" height=\"1600\"/>\n",
" </clipPath>\n",
"</defs>\n",
"<path clip-path=\"url(#clip910)\" d=\"\n",
"M0 1600 L2400 1600 L2400 0 L0 0 Z\n",
" \" fill=\"#ffffff\" fill-rule=\"evenodd\" fill-opacity=\"1\"/>\n",
"<defs>\n",
" <clipPath id=\"clip911\">\n",
" <rect x=\"480\" y=\"0\" width=\"1681\" height=\"1600\"/>\n",
" </clipPath>\n",
"</defs>\n",
"<path clip-path=\"url(#clip910)\" d=\"\n",
"M193.936 1486.45 L2352.76 1486.45 L2352.76 47.2441 L193.936 47.2441 Z\n",
" \" fill=\"#ffffff\" fill-rule=\"evenodd\" fill-opacity=\"1\"/>\n",
"<defs>\n",
" <clipPath id=\"clip912\">\n",
" <rect x=\"193\" y=\"47\" width=\"2160\" height=\"1440\"/>\n",
" </clipPath>\n",
"</defs>\n",
"<polyline clip-path=\"url(#clip912)\" style=\"stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 458.697,1486.45 458.697,47.2441 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip912)\" style=\"stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 866.021,1486.45 866.021,47.2441 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip912)\" style=\"stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 1273.35,1486.45 1273.35,47.2441 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip912)\" style=\"stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 1680.67,1486.45 1680.67,47.2441 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip912)\" style=\"stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 2087.99,1486.45 2087.99,47.2441 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip910)\" style=\"stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 193.936,1486.45 2352.76,1486.45 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip910)\" style=\"stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 458.697,1486.45 458.697,1467.55 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip910)\" style=\"stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 866.021,1486.45 866.021,1467.55 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip910)\" style=\"stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 1273.35,1486.45 1273.35,1467.55 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip910)\" style=\"stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 1680.67,1486.45 1680.67,1467.55 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip910)\" style=\"stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 2087.99,1486.45 2087.99,1467.55 \n",
" \"/>\n",
"<path clip-path=\"url(#clip910)\" d=\"M427.598 1532.02 L457.273 1532.02 L457.273 1535.95 L427.598 1535.95 L427.598 1532.02 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip910)\" d=\"M480.213 1518.36 L468.408 1536.81 L480.213 1536.81 L480.213 1518.36 M478.986 1514.29 L484.866 1514.29 L484.866 1536.81 L489.796 1536.81 L489.796 1540.7 L484.866 1540.7 L484.866 1548.85 L480.213 1548.85 L480.213 1540.7 L464.611 1540.7 L464.611 1536.19 L478.986 1514.29 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip910)\" d=\"M835.964 1532.02 L865.639 1532.02 L865.639 1535.95 L835.964 1535.95 L835.964 1532.02 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip910)\" d=\"M879.76 1544.91 L896.079 1544.91 L896.079 1548.85 L874.135 1548.85 L874.135 1544.91 Q876.797 1542.16 881.38 1537.53 Q885.987 1532.88 887.167 1531.53 Q889.413 1529.01 890.292 1527.27 Q891.195 1525.51 891.195 1523.82 Q891.195 1521.07 889.25 1519.33 Q887.329 1517.6 884.227 1517.6 Q882.028 1517.6 879.575 1518.36 Q877.144 1519.13 874.366 1520.68 L874.366 1515.95 Q877.19 1514.82 879.644 1514.24 Q882.098 1513.66 884.135 1513.66 Q889.505 1513.66 892.7 1516.35 Q895.894 1519.03 895.894 1523.52 Q895.894 1525.65 895.084 1527.57 Q894.297 1529.47 892.19 1532.07 Q891.612 1532.74 888.51 1535.95 Q885.408 1539.15 879.76 1544.91 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip910)\" d=\"M1273.35 1517.37 Q1269.73 1517.37 1267.91 1520.93 Q1266.1 1524.47 1266.1 1531.6 Q1266.1 1538.71 1267.91 1542.27 Q1269.73 1545.82 1273.35 1545.82 Q1276.98 1545.82 1278.79 1542.27 Q1280.61 1538.71 1280.61 1531.6 Q1280.61 1524.47 1278.79 1520.93 Q1276.98 1517.37 1273.35 1517.37 M1273.35 1513.66 Q1279.16 1513.66 1282.21 1518.27 Q1285.29 1522.85 1285.29 1531.6 Q1285.29 1540.33 1282.21 1544.94 Q1279.16 1549.52 1273.35 1549.52 Q1267.54 1549.52 1264.46 1544.94 Q1261.4 1540.33 1261.4 1531.6 Q1261.4 1522.85 1264.46 1518.27 Q1267.54 1513.66 1273.35 1513.66 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip910)\" d=\"M1675.32 1544.91 L1691.64 1544.91 L1691.64 1548.85 L1669.7 1548.85 L1669.7 1544.91 Q1672.36 1542.16 1676.94 1537.53 Q1681.55 1532.88 1682.73 1531.53 Q1684.98 1529.01 1685.86 1527.27 Q1686.76 1525.51 1686.76 1523.82 Q1686.76 1521.07 1684.81 1519.33 Q1682.89 1517.6 1679.79 1517.6 Q1677.59 1517.6 1675.14 1518.36 Q1672.71 1519.13 1669.93 1520.68 L1669.93 1515.95 Q1672.75 1514.82 1675.21 1514.24 Q1677.66 1513.66 1679.7 1513.66 Q1685.07 1513.66 1688.26 1516.35 Q1691.46 1519.03 1691.46 1523.52 Q1691.46 1525.65 1690.65 1527.57 Q1689.86 1529.47 1687.75 1532.07 Q1687.18 1532.74 1684.07 1535.95 Q1680.97 1539.15 1675.32 1544.91 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip910)\" d=\"M2091 1518.36 L2079.2 1536.81 L2091 1536.81 L2091 1518.36 M2089.78 1514.29 L2095.66 1514.29 L2095.66 1536.81 L2100.59 1536.81 L2100.59 1540.7 L2095.66 1540.7 L2095.66 1548.85 L2091 1548.85 L2091 1540.7 L2075.4 1540.7 L2075.4 1536.19 L2089.78 1514.29 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><polyline clip-path=\"url(#clip912)\" style=\"stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 193.936,1445.74 2352.76,1445.74 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip912)\" style=\"stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 193.936,1106.3 2352.76,1106.3 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip912)\" style=\"stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 193.936,766.858 2352.76,766.858 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip912)\" style=\"stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 193.936,427.415 2352.76,427.415 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip912)\" style=\"stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:2; stroke-opacity:0.1; fill:none\" points=\"\n",
" 193.936,87.9727 2352.76,87.9727 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip910)\" style=\"stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 193.936,1486.45 193.936,47.2441 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip910)\" style=\"stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 193.936,1445.74 212.834,1445.74 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip910)\" style=\"stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 193.936,1106.3 212.834,1106.3 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip910)\" style=\"stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 193.936,766.858 212.834,766.858 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip910)\" style=\"stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 193.936,427.415 212.834,427.415 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip910)\" style=\"stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 193.936,87.9727 212.834,87.9727 \n",
" \"/>\n",
"<path clip-path=\"url(#clip910)\" d=\"M50.9921 1446.19 L80.6679 1446.19 L80.6679 1450.13 L50.9921 1450.13 L50.9921 1446.19 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip910)\" d=\"M91.5706 1459.09 L99.2095 1459.09 L99.2095 1432.72 L90.8993 1434.39 L90.8993 1430.13 L99.1632 1428.46 L103.839 1428.46 L103.839 1459.09 L111.478 1459.09 L111.478 1463.02 L91.5706 1463.02 L91.5706 1459.09 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip910)\" d=\"M120.922 1457.14 L125.807 1457.14 L125.807 1463.02 L120.922 1463.02 L120.922 1457.14 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip910)\" d=\"M145.992 1431.54 Q142.381 1431.54 140.552 1435.11 Q138.746 1438.65 138.746 1445.78 Q138.746 1452.88 140.552 1456.45 Q142.381 1459.99 145.992 1459.99 Q149.626 1459.99 151.431 1456.45 Q153.26 1452.88 153.26 1445.78 Q153.26 1438.65 151.431 1435.11 Q149.626 1431.54 145.992 1431.54 M145.992 1427.84 Q151.802 1427.84 154.857 1432.44 Q157.936 1437.03 157.936 1445.78 Q157.936 1454.5 154.857 1459.11 Q151.802 1463.69 145.992 1463.69 Q140.181 1463.69 137.103 1459.11 Q134.047 1454.5 134.047 1445.78 Q134.047 1437.03 137.103 1432.44 Q140.181 1427.84 145.992 1427.84 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip910)\" d=\"M51.9875 1106.75 L81.6633 1106.75 L81.6633 1110.69 L51.9875 1110.69 L51.9875 1106.75 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip910)\" d=\"M101.756 1092.1 Q98.1447 1092.1 96.316 1095.66 Q94.5104 1099.21 94.5104 1106.33 Q94.5104 1113.44 96.316 1117.01 Q98.1447 1120.55 101.756 1120.55 Q105.39 1120.55 107.196 1117.01 Q109.024 1113.44 109.024 1106.33 Q109.024 1099.21 107.196 1095.66 Q105.39 1092.1 101.756 1092.1 M101.756 1088.4 Q107.566 1088.4 110.621 1093 Q113.7 1097.58 113.7 1106.33 Q113.7 1115.06 110.621 1119.67 Q107.566 1124.25 101.756 1124.25 Q95.9456 1124.25 92.8669 1119.67 Q89.8114 1115.06 89.8114 1106.33 Q89.8114 1097.58 92.8669 1093 Q95.9456 1088.4 101.756 1088.4 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip910)\" d=\"M121.918 1117.7 L126.802 1117.7 L126.802 1123.58 L121.918 1123.58 L121.918 1117.7 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip910)\" d=\"M137.033 1089.02 L155.39 1089.02 L155.39 1092.96 L141.316 1092.96 L141.316 1101.43 Q142.334 1101.08 143.353 1100.92 Q144.371 1100.73 145.39 1100.73 Q151.177 1100.73 154.556 1103.9 Q157.936 1107.08 157.936 1112.49 Q157.936 1118.07 154.464 1121.17 Q150.992 1124.25 144.672 1124.25 Q142.496 1124.25 140.228 1123.88 Q137.982 1123.51 135.575 1122.77 L135.575 1118.07 Q137.658 1119.21 139.881 1119.76 Q142.103 1120.32 144.58 1120.32 Q148.584 1120.32 150.922 1118.21 Q153.26 1116.1 153.26 1112.49 Q153.26 1108.88 150.922 1106.77 Q148.584 1104.67 144.58 1104.67 Q142.705 1104.67 140.83 1105.08 Q138.978 1105.5 137.033 1106.38 L137.033 1089.02 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip910)\" d=\"M100.76 752.656 Q97.1493 752.656 95.3206 756.221 Q93.515 759.763 93.515 766.892 Q93.515 773.999 95.3206 777.564 Q97.1493 781.105 100.76 781.105 Q104.395 781.105 106.2 777.564 Q108.029 773.999 108.029 766.892 Q108.029 759.763 106.2 756.221 Q104.395 752.656 100.76 752.656 M100.76 748.953 Q106.571 748.953 109.626 753.559 Q112.705 758.142 112.705 766.892 Q112.705 775.619 109.626 780.226 Q106.571 784.809 100.76 784.809 Q94.9502 784.809 91.8715 780.226 Q88.816 775.619 88.816 766.892 Q88.816 758.142 91.8715 753.559 Q94.9502 748.953 100.76 748.953 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip910)\" d=\"M120.922 778.258 L125.807 778.258 L125.807 784.138 L120.922 784.138 L120.922 778.258 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip910)\" d=\"M145.992 752.656 Q142.381 752.656 140.552 756.221 Q138.746 759.763 138.746 766.892 Q138.746 773.999 140.552 777.564 Q142.381 781.105 145.992 781.105 Q149.626 781.105 151.431 777.564 Q153.26 773.999 153.26 766.892 Q153.26 759.763 151.431 756.221 Q149.626 752.656 145.992 752.656 M145.992 748.953 Q151.802 748.953 154.857 753.559 Q157.936 758.142 157.936 766.892 Q157.936 775.619 154.857 780.226 Q151.802 784.809 145.992 784.809 Q140.181 784.809 137.103 780.226 Q134.047 775.619 134.047 766.892 Q134.047 758.142 137.103 753.559 Q140.181 748.953 145.992 748.953 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip910)\" d=\"M101.756 413.214 Q98.1447 413.214 96.316 416.779 Q94.5104 420.32 94.5104 427.45 Q94.5104 434.556 96.316 438.121 Q98.1447 441.663 101.756 441.663 Q105.39 441.663 107.196 438.121 Q109.024 434.556 109.024 427.45 Q109.024 420.32 107.196 416.779 Q105.39 413.214 101.756 413.214 M101.756 409.51 Q107.566 409.51 110.621 414.117 Q113.7 418.7 113.7 427.45 Q113.7 436.177 110.621 440.783 Q107.566 445.366 101.756 445.366 Q95.9456 445.366 92.8669 440.783 Q89.8114 436.177 89.8114 427.45 Q89.8114 418.7 92.8669 414.117 Q95.9456 409.51 101.756 409.51 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip910)\" d=\"M121.918 438.816 L126.802 438.816 L126.802 444.695 L121.918 444.695 L121.918 438.816 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip910)\" d=\"M137.033 410.135 L155.39 410.135 L155.39 414.07 L141.316 414.07 L141.316 422.543 Q142.334 422.195 143.353 422.033 Q144.371 421.848 145.39 421.848 Q151.177 421.848 154.556 425.019 Q157.936 428.191 157.936 433.607 Q157.936 439.186 154.464 442.288 Q150.992 445.366 144.672 445.366 Q142.496 445.366 140.228 444.996 Q137.982 444.626 135.575 443.885 L135.575 439.186 Q137.658 440.32 139.881 440.876 Q142.103 441.431 144.58 441.431 Q148.584 441.431 150.922 439.325 Q153.26 437.218 153.26 433.607 Q153.26 429.996 150.922 427.89 Q148.584 425.783 144.58 425.783 Q142.705 425.783 140.83 426.2 Q138.978 426.617 137.033 427.496 L137.033 410.135 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip910)\" d=\"M91.5706 101.318 L99.2095 101.318 L99.2095 74.9519 L90.8993 76.6186 L90.8993 72.3594 L99.1632 70.6927 L103.839 70.6927 L103.839 101.318 L111.478 101.318 L111.478 105.253 L91.5706 105.253 L91.5706 101.318 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip910)\" d=\"M120.922 99.3731 L125.807 99.3731 L125.807 105.253 L120.922 105.253 L120.922 99.3731 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip910)\" d=\"M145.992 73.7714 Q142.381 73.7714 140.552 77.3362 Q138.746 80.8778 138.746 88.0074 Q138.746 95.1139 140.552 98.6787 Q142.381 102.22 145.992 102.22 Q149.626 102.22 151.431 98.6787 Q153.26 95.1139 153.26 88.0074 Q153.26 80.8778 151.431 77.3362 Q149.626 73.7714 145.992 73.7714 M145.992 70.0677 Q151.802 70.0677 154.857 74.6742 Q157.936 79.2575 157.936 88.0074 Q157.936 96.7342 154.857 101.341 Q151.802 105.924 145.992 105.924 Q140.181 105.924 137.103 101.341 Q134.047 96.7342 134.047 88.0074 Q134.047 79.2575 137.103 74.6742 Q140.181 70.0677 145.992 70.0677 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><polyline clip-path=\"url(#clip912)\" style=\"stroke:#009af9; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 255.035,115.858 258.35,112.81 261.664,109.936 264.979,107.235 268.294,104.709 283.62,95.32 298.945,89.732 306.608,88.3739 314.27,87.9763 321.933,88.5395 \n",
" 329.596,90.0629 337.259,92.5443 344.921,95.98 352.584,100.365 360.247,105.694 375.572,119.15 390.898,136.272 400.108,148.286 409.318,161.564 418.527,176.08 \n",
" 427.737,191.804 436.947,208.704 446.157,226.745 455.367,245.89 464.577,266.1 480.151,302.583 495.725,341.778 511.299,383.458 526.872,427.379 543.79,477.329 \n",
" 560.707,529.276 577.625,582.861 594.542,637.715 625.735,740.907 656.928,844.707 673.649,899.753 690.37,953.903 707.091,1006.79 723.812,1058.07 743.185,1115 \n",
" 762.558,1168.78 772.245,1194.34 781.931,1218.93 791.617,1242.5 801.304,1264.99 809.912,1284.03 818.52,1302.15 827.129,1319.32 835.737,1335.5 844.345,1350.66 \n",
" 852.953,1364.78 861.561,1377.83 870.17,1389.79 885.267,1408.07 900.364,1422.82 915.461,1433.98 930.558,1441.46 938.788,1443.99 947.018,1445.41 955.248,1445.72 \n",
" 963.478,1444.92 971.708,1443.01 979.938,1440 988.168,1435.89 996.398,1430.69 1004.68,1424.37 1012.96,1416.95 1021.24,1408.47 1029.51,1398.92 1046.07,1376.72 \n",
" 1062.63,1350.48 1071.78,1334.31 1080.94,1316.99 1090.09,1298.56 1099.24,1279.06 1108.4,1258.53 1117.55,1237 1126.7,1214.52 1135.86,1191.13 1153.28,1144.31 \n",
" 1170.69,1094.73 1188.11,1042.75 1205.53,988.757 1241.75,871.746 1277.98,751.426 1308.47,650.364 1338.96,551.908 1357.57,494.034 1376.19,438.437 1394.8,385.581 \n",
" 1413.41,335.908 1421.94,314.333 1430.46,293.551 1438.99,273.598 1447.51,254.51 1464.57,219.058 1481.62,187.444 1489.49,174.202 1497.36,161.846 1505.24,150.394 \n",
" 1513.11,139.864 1520.99,130.271 1528.86,121.629 1536.73,113.952 1544.61,107.25 1552.58,101.467 1560.56,96.7035 1568.54,92.9682 1576.51,90.2663 1584.49,88.602 \n",
" 1592.46,87.9779 1600.44,88.3948 1608.42,89.8523 1617.36,92.7193 1626.29,96.8847 1635.23,102.341 1644.17,109.076 1653.11,117.079 1662.05,126.334 1670.99,136.822 \n",
" 1679.93,148.523 1696.13,172.748 1712.33,200.731 1720.43,216.076 1728.53,232.293 1736.63,249.355 1744.73,267.236 1754,288.677 1763.28,311.109 1772.55,334.486 \n",
" 1781.83,358.76 1800.37,409.793 1818.92,463.785 1836.1,516.028 1853.27,570.053 1870.44,625.476 1887.62,681.905 1921.48,794.552 1955.34,906.436 1971.78,959.55 \n",
" 1988.22,1011.41 2004.66,1061.68 2021.1,1110.02 2037.95,1157.26 2054.8,1201.83 2071.66,1243.43 2088.51,1281.76 2097.74,1301.28 2106.97,1319.7 2116.2,1336.99 \n",
" 2125.44,1353.1 2134.67,1368.01 2143.9,1381.69 2153.13,1394.1 2162.36,1405.22 2175.77,1419.04 2189.18,1430.03 2202.59,1438.15 2216,1443.36 2229.42,1445.63 \n",
" 2242.83,1444.97 2256.24,1441.36 2269.65,1434.83 2275.15,1431.31 2280.65,1427.31 2286.15,1422.82 2291.66,1417.86 \n",
" \"/>\n",
"<path clip-path=\"url(#clip910)\" d=\"\n",
"M1988.5 198.898 L2280.8 198.898 L2280.8 95.2176 L1988.5 95.2176 Z\n",
" \" fill=\"#ffffff\" fill-rule=\"evenodd\" fill-opacity=\"1\"/>\n",
"<polyline clip-path=\"url(#clip910)\" style=\"stroke:#000000; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 1988.5,198.898 2280.8,198.898 2280.8,95.2176 1988.5,95.2176 1988.5,198.898 \n",
" \"/>\n",
"<polyline clip-path=\"url(#clip910)\" style=\"stroke:#009af9; stroke-linecap:round; stroke-linejoin:round; stroke-width:4; stroke-opacity:1; fill:none\" points=\"\n",
" 2012.48,147.058 2156.4,147.058 \n",
" \"/>\n",
"<path clip-path=\"url(#clip910)\" d=\"M2194.23 166.745 Q2192.43 171.375 2190.72 172.787 Q2189 174.199 2186.13 174.199 L2182.73 174.199 L2182.73 170.634 L2185.23 170.634 Q2186.99 170.634 2187.96 169.8 Q2188.93 168.967 2190.11 165.865 L2190.88 163.921 L2180.39 138.412 L2184.91 138.412 L2193.01 158.689 L2201.11 138.412 L2205.62 138.412 L2194.23 166.745 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /><path clip-path=\"url(#clip910)\" d=\"M2212.91 160.402 L2220.55 160.402 L2220.55 134.037 L2212.24 135.703 L2212.24 131.444 L2220.51 129.778 L2225.18 129.778 L2225.18 160.402 L2232.82 160.402 L2232.82 164.338 L2212.91 164.338 L2212.91 160.402 Z\" fill=\"#000000\" fill-rule=\"evenodd\" fill-opacity=\"1\" /></svg>\n"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"plot(sin)"
]
},
{
"cell_type": "markdown",
"id": "fed84385",
"metadata": {},
"source": [
"https://zenn.dev/ohno/articles/3101433fbe9231"
]
},
{
"cell_type": "markdown",
"id": "37b0d982",
"metadata": {},
"source": [
"# 最適化問題を解く\n",
"\n",
"Optim.jlでは様々な方法で最適化問題を解くことができる. 最急降下法を用いて $f(x) = (x+2)^2 + 1$ の最小値・最小点を求める."
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "2ea4ffb3",
"metadata": {},
"outputs": [],
"source": [
"# using Pkg\n",
"# Pkg.add(\"Optim\")\n",
"using Optim"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "60b8b7bf",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
" * Status: success\n",
"\n",
" * Candidate solution\n",
" Final objective value: 1.000000e+00\n",
"\n",
" * Found with\n",
" Algorithm: Gradient Descent\n",
"\n",
" * Convergence measures\n",
" |x - x'| = 7.00e+00 ≰ 0.0e+00\n",
" |x - x'|/|x'| = 3.50e+00 ≰ 0.0e+00\n",
" |f(x) - f(x')| = 4.90e+01 ≰ 0.0e+00\n",
" |f(x) - f(x')|/|f(x')| = 4.90e+01 ≰ 0.0e+00\n",
" |g(x)| = 9.17e-11 ≤ 1.0e-08\n",
"\n",
" * Work counters\n",
" Seconds run: 0 (vs limit Inf)\n",
" Iterations: 1\n",
" f(x) calls: 3\n",
" ∇f(x) calls: 3\n"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"f(x) = (x[1] + 2.0)^2 + 1\n",
"x0 = [5.0]\n",
"optimize(f, x0, method=GradientDescent())"
]
},
{
"cell_type": "markdown",
"id": "548e9250",
"metadata": {},
"source": [
"https://zenn.dev/ohno/articles/2a1dc7d609e5bc"
]
},
{
"cell_type": "markdown",
"id": "2c672c48",
"metadata": {},
"source": [
"# 固有値問題を解く\n",
"\n",
"LinearAlgebra.jlを使えば簡単に行列の固有値や固有ベクトルを求めることができる. LAPACKが裏で動いているので, 安心感がある. LinearAlgebra.jlは最初からインストールされている."
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "5c1a46f6",
"metadata": {},
"outputs": [],
"source": [
"using LinearAlgebra"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "c1a12724",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"3×3 Matrix{Int64}:\n",
" -4 0 6\n",
" -3 2 3\n",
" -3 0 5"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"A = [-4 0 6;\n",
" -3 2 3;\n",
" -3 0 5]"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "65dc8544",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Eigen{Float64, Float64, Matrix{Float64}, Vector{Float64}}\n",
"values:\n",
"3-element Vector{Float64}:\n",
" -1.0\n",
" 2.0\n",
" 2.0\n",
"vectors:\n",
"3×3 Matrix{Float64}:\n",
" -0.816497 0.0 -0.6742\n",
" -0.408248 1.0 0.301511\n",
" -0.408248 0.0 -0.6742"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"eigen(A)"
]
},
{
"cell_type": "markdown",
"id": "eb79df72",
"metadata": {},
"source": [
"https://zenn.dev/ohno/articles/cb10dc5b3f5bbc"
]
},
{
"cell_type": "markdown",
"id": "a1287075",
"metadata": {},
"source": [
"# 特殊関数を使う\n",
"\n",
"Juliaには様々な特殊関数を利用するためのパッケージが用意されている."
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "8c84d1f2",
"metadata": {},
"outputs": [],
"source": [
"# using Pkg\n",
"# Pkg.add(\"SpecialFunctions\")\n",
"using SpecialFunctions"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "f5348e14",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"3.1415926535897936"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"gamma(1/2)^2"
]
},
{
"cell_type": "markdown",
"id": "b4bc757b",
"metadata": {},
"source": [
"https://zenn.dev/ohno/articles/f352f354e5cf96"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "97e477fb",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Julia 1.8.2",
"language": "julia",
"name": "julia-1.8"
},
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.8.2"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment