-
-
Save takatakamanbou/e861035358637b7e45ef3988af03d997 to your computer and use it in GitHub Desktop.
PIP2020-06-note2.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"nbformat": 4, | |
"nbformat_minor": 0, | |
"metadata": { | |
"colab": { | |
"name": "PIP2020-06-note2.ipynb", | |
"provenance": [], | |
"collapsed_sections": [], | |
"include_colab_link": true | |
}, | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3" | |
} | |
}, | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "view-in-github", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"<a href=\"https://colab.research.google.com/gist/takatakamanbou/e861035358637b7e45ef3988af03d997/pip2020-06-note2.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "NI3mY1FGZWgV", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"# 2020年度パターン情報処理第6回講義資料その2\n", | |
"\n", | |
"\n", | |
"この科目のウェブサイトへ https://www-tlab.math.ryukoku.ac.jp/wiki/?PIP/2020\n", | |
"\n", | |
"![hoge](https://www-tlab.math.ryukoku.ac.jp/~takataka/course/PIP/PIP-logo-96x96.png)\n" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "ffaGVK2o5VWe", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"## はじめに\n", | |
"\n", | |
"これは Google Colab の Notebook です.どうやって閲覧・実行したらいいかわからないひとは,以下を参照してください. \n", | |
"https://www-tlab.math.ryukoku.ac.jp/wiki/?PIP/2020/ex06" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "QRNjWashW4pr", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"### Notebook の動かし方に関する注意\n", | |
"\n", | |
"この Notebook では,上の方のセルで作った変数や関数を後のセルで使うことがあります.そのため,上の方のセルを実行せずに下の方を実行すると,エラーになることがあります.上から順に実行していきましょう.\n", | |
"\n", | |
"また,メニューの「ランタイム」から,「すべてのセルを実行」したりすることも可能です.セルの実行が終わらなくなったりした場合は,「ランライム」 > 「実行を中断」. " | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "1jfSXIY6VNxP", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"### 準備\n", | |
"\n", | |
"以下のプログラムを実行するための準備です.このセルを実行してから,先へ進みましょう." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "IFYQk7ONZENz", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"# 科学技術計算のライブラリ NumPy のモジュールを np という名前で使えるようにする\n", | |
"import numpy as np\n", | |
"# グラフを描くためのライブラリ matplotlib の pyplot を plt という名前でインポート\n", | |
"import matplotlib.pyplot as plt\n", | |
"# コンピュータビジョン・画像処理のライブラリ OpenCV のモジュールをインポート\n", | |
"#import cv2 # 今回使ってない" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "bUpNOXqZZnPU", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"## ★ 6.2 周期信号を三角関数の和で表す" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "ueWvaKQGv04A", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"<参考: 第6回講義資料>\n", | |
"\n", | |
"前回までに,$N$ 本の $N$ 次元実ベクトルから成る正規直交基底 $\\{\n", | |
"\\mathbf{u}_1, \\mathbf{u}_2,\\dots , \\mathbf{u}_N \\}$ を用いると,任意の $N$ 次元実ベ\n", | |
"クトル $\\mathbf{x}$ を $\\mathbf{x} = c_1\\mathbf{u}_1 + c_2\\mathbf{u}_2 + \\dots +\n", | |
"c_N\\mathbf{u}_N$ と直交展開でき,「成分」$\\mathbf{u}_k$に対する係\n", | |
"数$c_k$は $c_k = \\mathbf{x}\\cdot\\mathbf{u}_{k}$ となることを学んだ.\n" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "PhZnUiUq27sQ", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"\n", | |
"実は,同じ考え方で,アナログ周期信号を展開することができる.例えば,周期$2\\pi$の周期信号 $f(t)$ は,$\\sin{t}, \\sin{2t},\\dots ,\\cos{t}, \\cos{2t},\\dots$ といった正弦波を成分として,次のように展開できる.\n", | |
"\n", | |
"\\begin{align}\n", | |
" f(t) &= \\frac{a_{0}}{2} + \\sum_{k=1}^{\\infty}\\left( a_{k}\\cos{kt} + b_{k}\\sin{kt} \\right) \\\\\n", | |
" &=\\frac{a_{0}}{2} + a_{1}\\cos{t} + b_{1}\\sin{t} + a_{2}\\cos{2t} + b_{2}\\sin{2t} + \\cdots\n", | |
"\\end{align}\n", | |
"\n", | |
"$a_0, a_1, a_2, \\dots, b_1, b_2, \\dots$ が展開係数である.このような展開を,$f(t)$の **フーリエ級数展開** という.詳しくは次回説明する." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "83EVKc3UZR8f", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"# 上記の左辺の値を計算する関数\n", | |
"#\n", | |
"def expand(t, ak, bk):\n", | |
"\n", | |
" N = ak.shape[0]\n", | |
" assert N == bk.shape[0]\n", | |
" f = np.empty((N, t.shape[0]))\n", | |
"\n", | |
" f[0, :] = ak[0]/2\n", | |
" for k in range(1, N):\n", | |
" f[k, :] = f[k-1, :]\n", | |
" f[k, :] += ak[k] * np.cos(k*t) + bk[k] * np.sin(k*t)\n", | |
"\n", | |
" return f" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "wEcEOq8NF64x", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"----\n", | |
"### 成分となる正弦波はどんなん?\n", | |
"\n", | |
"$ k = 1, 2, 3, \\dots$ のときの $\\cos{kt}, \\sin{kt}$ のグラフ" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "QxBPtsJdF3-T", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"# 適当な区間で t の値をつくる\n", | |
"t = np.linspace(-3*np.pi, 3*np.pi, num=1000)\n", | |
"\n", | |
"# グラフを描く\n", | |
"fig, ax = plt.subplots(6, facecolor=\"white\", figsize=(8, 12))\n", | |
"ax[0].plot(t, np.cos(t), \"-\", label = \"$\\cos{t}$\")\n", | |
"ax[1].plot(t, np.cos(2*t), \"-\", label = \"$\\cos{2t}$\")\n", | |
"ax[2].plot(t, np.cos(3*t), \"-\", label = \"$\\cos{3t}$\")\n", | |
"ax[3].plot(t, np.sin(t), \"-\", label = \"$\\sin{t}$\", color=\"tab:orange\")\n", | |
"ax[4].plot(t, np.sin(2*t), \"-\", label = \"$\\sin{2t}$\", color=\"tab:orange\")\n", | |
"ax[5].plot(t, np.sin(3*t), \"-\", label = \"$\\sin{3t}$\", color=\"tab:orange\")\n", | |
"for i in range(6):\n", | |
" ax[i].set_xlim(np.min(t), np.max(t))\n", | |
" ax[i].set_ylim(-2, 2)\n", | |
" ax[i].legend()\n", | |
"plt.show()" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "jkZmnJEl7yhi", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"----\n", | |
"### 例その1: 周期 $2\\pi$ ののこぎり波\n", | |
"\n", | |
"$$\n", | |
"f(t) = t \\qquad (-\\pi < t < \\pi)\n", | |
"$$\n", | |
"を周期関数に拡張したもの." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "TneMB-fBBQgm", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"# 適当な区間で t の値をつくる\n", | |
"t = np.linspace(-3*np.pi, 3*np.pi, num=1000)\n", | |
"\n", | |
"# 上記ののこぎり波をつくる\n", | |
"f = 2*np.pi*((t+np.pi)/(2*np.pi) - np.floor((t+np.pi)/(2*np.pi)) - 1/2)\n", | |
"\n", | |
"# グラフを描く\n", | |
"fig, ax = plt.subplots(facecolor=\"white\", figsize=(8, 6))\n", | |
"ax.plot(t, f, \"-\", label = \"$f(t)$\")\n", | |
"ax.set_xlim(np.min(t), np.max(t))\n", | |
"ax.legend()\n", | |
"plt.show()" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "Xu3oiV6I5Iir", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"このとき,展開係数は\n", | |
"$$\n", | |
"\\left\\{\n", | |
"\\begin{aligned}\n", | |
"a_k &= 0 \\quad (k = 0, 1, 2, \\dots )\\\\\n", | |
"b_k &= (-1)^{k+1}\\frac{2}{k} \\quad (k = 1, 2, \\dots )\\\\\n", | |
"\\end{aligned}\n", | |
"\\right.\n", | |
"$$\n", | |
"となる(どこからこれが出てくるかは,次回授業で).\n", | |
"$$\n", | |
"b_1 = 2,\\ b_2 = -1,\\ b_3 = \\frac{2}{3},\\ b_4 = -\\frac{1}{4},\\ \\dots\n", | |
"$$" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "lAoDuCfacbXd", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"# ak, bk の値を作る\n", | |
"Nmax = 100\n", | |
"ak = np.empty(Nmax+1)\n", | |
"bk = np.empty(Nmax+1)\n", | |
"\n", | |
"ak[0] = 0.0\n", | |
"bk[0] = 0.0 # bk[0] is not used\n", | |
"\n", | |
"for k in range(1, Nmax):\n", | |
" ak[k] = 0.0\n", | |
" bk[k] = 2/(k)\n", | |
" if k % 2 == 0:\n", | |
" bk[k] *= -1\n", | |
"\n", | |
"print(ak[:10]) # a_0 から a_9 まで\n", | |
"print(bk[1:10]) # b_1 から b_9 まで" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "XkaQ8ciYI3IP", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"$a_k\\cos{kt}$ および $b_k\\sin{kt}$ $(k=1, 2, 3)$ のグラフを描いてみる." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "rtFRXMbAI0-3", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"# 適当な区間で t の値をつくる\n", | |
"t = np.linspace(-3*np.pi, 3*np.pi, num=1000)\n", | |
"\n", | |
"# グラフを描く\n", | |
"fig, ax = plt.subplots(6, facecolor=\"white\", figsize=(8, 12))\n", | |
"ax[0].plot(t, ak[1]*np.cos(t), \"-\", label = \"$a_1\\cos{t}$\")\n", | |
"ax[1].plot(t, ak[2]*np.cos(2*t), \"-\", label = \"$a_2\\cos{2t}$\")\n", | |
"ax[2].plot(t, ak[3]*np.cos(3*t), \"-\", label = \"$a_3\\cos{3t}$\")\n", | |
"ax[3].plot(t, bk[1]*np.sin(t), \"-\", label = \"$b_1\\sin{t}$\", color=\"tab:orange\")\n", | |
"ax[4].plot(t, bk[2]*np.sin(2*t), \"-\", label = \"$b_2\\sin{2t}$\", color=\"tab:orange\")\n", | |
"ax[5].plot(t, bk[3]*np.sin(3*t), \"-\", label = \"$b_3\\sin{3t}$\", color=\"tab:orange\")\n", | |
"for i in range(6):\n", | |
" ax[i].set_xlim(np.min(t), np.max(t))\n", | |
" ax[i].set_ylim(-2, 2)\n", | |
" ax[i].legend()\n", | |
"plt.show()" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "zKwI3f-5684J", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"# 展開した式の値を求める\n", | |
"ft = expand(t, ak, bk)" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "Cb13jyO0SK06", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"以下では,$f(t)$ のフーリエ級数展開\n", | |
"\\begin{align}\n", | |
" f(t) &= \\frac{a_{0}}{2} + \\sum_{k=1}^{\\infty}\\left( a_{k}\\cos{kt} + b_{k}\\sin{kt} \\right) \\\\\n", | |
" &=\\frac{a_{0}}{2} + a_{1}\\cos{t} + b_{1}\\sin{t} + a_{2}\\cos{2t} + b_{2}\\sin{2t} + \\cdots\n", | |
"\\end{align}\n", | |
"の右辺の和を $\\infty$ までではなく,$K$番目までで打ち切ったものつまり\n", | |
"\\begin{align}\n", | |
" f_K(t) = \\frac{a_{0}}{2} + \\sum_{k=1}^{K}\\left( a_{k}\\cos{kt} + b_{k}\\sin{kt} \\right) \\\\\n", | |
"\\end{align}\n", | |
"を計算します.$f_K(t)$ はどんなグラフになるでしょう?" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "fdekgOyrcqjz", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"#@title スライダを動かすと K の値つまり何番目の展開係数まで使うかを変えられます.いじってみよう { run: \"auto\" }\n", | |
"K = 0 #@param {type:\"slider\", min:0, max:10, step:1}\n", | |
"hoge = ft[K]\n", | |
"fig, ax = plt.subplots(facecolor=\"white\", figsize=(8, 6))\n", | |
"ax.plot(t, f, \"-\", label=\"$f(t)$\", color=\"black\")\n", | |
"ax.plot(t, hoge, \"-\", label = \"k={}\".format(K), color=\"red\")\n", | |
"ax.legend()\n", | |
"ax.set_xlim(np.min(t), np.max(t))\n", | |
"ax.set_ylim(-4, 4)\n", | |
"plt.show()" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "-qskYlBgEuEH", | |
"colab_type": "code", | |
"colab": {} | |
}, | |
"source": [ | |
"#@title もっと K を大きくしてみよう { run: \"auto\" }\n", | |
"K = 10 #@param {type:\"slider\", min:10, max:100, step:10}\n", | |
"hoge = ft[K]\n", | |
"fig, ax = plt.subplots(facecolor=\"white\", figsize=(8, 6))\n", | |
"ax.plot(t, f, \"-\", label=\"$f(t)$\", color=\"black\")\n", | |
"ax.plot(t, hoge, \"-\", label = \"k={}\".format(K), color=\"red\")\n", | |
"ax.legend()\n", | |
"ax.set_xlim(np.min(t), np.max(t))\n", | |
"ax.set_ylim(-4, 4)\n", | |
"plt.show()" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "RbtkxPlrMA92", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"----\n", | |
"### 例その2: 周期 $2\\pi$ の方形波\n", | |
"\n", | |
"\n", | |
"$$\n", | |
"f(t) = \\left\\{ \\begin{array}{ll}\n", | |
"\\pi & \\displaystyle \\left(-\\frac{\\pi}{2} \\le t < \\frac{\\pi}{2}\\right) \\\\\n", | |
"0 & \\left(-\\pi \\le t < -\\frac{\\pi}{2} \\quad\\mbox{または}\\quad \\frac{\\pi}{2} \\le t < \\pi\\right)\n", | |
"\\end{array} \\right.\n", | |
"$$\n", | |
"を周期関数に拡張したもの." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab_type": "code", | |
"id": "mlX6l6RvM3r1", | |
"colab": {} | |
}, | |
"source": [ | |
"# 適当な区間で t の値をつくる\n", | |
"t = np.linspace(-3*np.pi, 3*np.pi, num=1000)\n", | |
"\n", | |
"# 上記の方形波をつくる\n", | |
"ti = np.floor((t + 3*np.pi)*2/np.pi) % 4\n", | |
"f = np.zeros_like(t)\n", | |
"f[ti == 1] = np.pi\n", | |
"f[ti == 2] = np.pi\n", | |
"\n", | |
"# グラフを描く\n", | |
"fig, ax = plt.subplots(facecolor=\"white\", figsize=(8, 6))\n", | |
"ax.plot(t, f, \"-\", label = \"$f(t)$\")\n", | |
"ax.set_xlim(np.min(t), np.max(t))\n", | |
"ax.set_ylim(-0.5, 4)\n", | |
"ax.legend()\n", | |
"plt.show()" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"colab_type": "text", | |
"id": "sefKTEzTNpls" | |
}, | |
"source": [ | |
"このとき,展開係数は\n", | |
"$$\n", | |
"\\left\\{\n", | |
"\\begin{aligned}\n", | |
"a_0 &= \\pi \\\\\n", | |
"a_k &= \\frac{2}{k}\\sin{\\frac{\\pi}{2}k} \\quad (k = 1, 2, \\dots )\\\\\n", | |
"b_k &= 0 \\quad (k = 1, 2, \\dots )\\\\\n", | |
"\\end{aligned}\n", | |
"\\right.\n", | |
"$$\n", | |
"となる(どこからこれが出てくるかは,次回授業で).\n", | |
"$$\n", | |
"a_1 = 2,\\quad a_2 = 0,\\quad a_3 = -\\frac{2}{3}\\quad, a_4 = 0,\\quad a_5 = \\frac{2}{5},\\dots\n", | |
"$$" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab_type": "code", | |
"id": "xdxSQ_B7N150", | |
"colab": {} | |
}, | |
"source": [ | |
"# ak, bk の値を作る\n", | |
"Nmax = 100\n", | |
"ak = np.empty(Nmax+1)\n", | |
"bk = np.empty(Nmax+1)\n", | |
"\n", | |
"ak[0] = np.pi\n", | |
"bk[0] = 0.0 # bk[0] is not used\n", | |
"\n", | |
"for k in range(1, Nmax):\n", | |
" ak[k] = 2*np.sin(np.pi*k/2)/(k)\n", | |
" bk[k] = 0.0\n", | |
"\n", | |
"print(ak[:10]) # a_0 から a_9 まで\n", | |
"print(bk[1:10]) # b_1 から b_9 まで" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"colab_type": "text", | |
"id": "G4ct6JECORkx" | |
}, | |
"source": [ | |
"$a_k\\cos{kt}$ および $b_k\\sin{kt}$ $(k=1, 2, 3)$ のグラフを描いてみる." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab_type": "code", | |
"id": "MxjLwaRRORky", | |
"colab": {} | |
}, | |
"source": [ | |
"# グラフを描く\n", | |
"fig, ax = plt.subplots(6, facecolor=\"white\", figsize=(8, 12))\n", | |
"ax[0].plot(t, ak[1]*np.cos(t), \"-\", label = \"$a_1\\cos{t}$\")\n", | |
"ax[1].plot(t, ak[2]*np.cos(2*t), \"-\", label = \"$a_2\\cos{2t}$\")\n", | |
"ax[2].plot(t, ak[3]*np.cos(3*t), \"-\", label = \"$a_3\\cos{3t}$\")\n", | |
"ax[3].plot(t, bk[1]*np.sin(t), \"-\", label = \"$b_1\\sin{t}$\", color=\"tab:orange\")\n", | |
"ax[4].plot(t, bk[2]*np.sin(2*t), \"-\", label = \"$b_2\\sin{2t}$\", color=\"tab:orange\")\n", | |
"ax[5].plot(t, bk[3]*np.sin(3*t), \"-\", label = \"$b_3\\sin{3t}$\", color=\"tab:orange\")\n", | |
"for i in range(6):\n", | |
" ax[i].set_xlim(np.min(t), np.max(t))\n", | |
" ax[i].set_ylim(-2, 2)\n", | |
" ax[i].legend()\n", | |
"plt.show()" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab_type": "code", | |
"id": "fj2N-J8WOe4V", | |
"colab": {} | |
}, | |
"source": [ | |
"# 展開した式の値を求める\n", | |
"ft = expand(t, ak, bk)" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab_type": "code", | |
"id": "tbafNLBaOe4X", | |
"colab": {} | |
}, | |
"source": [ | |
"#@title スライダを動かすと K の値つまり何番目の展開係数まで使うかを変えられます.いじってみよう { run: \"auto\" }\n", | |
"K = 0 #@param {type:\"slider\", min:0, max:10, step:1}\n", | |
"hoge = ft[K]\n", | |
"fig, ax = plt.subplots(facecolor=\"white\", figsize=(8, 6))\n", | |
"ax.plot(t, f, \"-\", label=\"$f(t)$\", color=\"black\")\n", | |
"ax.plot(t, hoge, \"-\", label = \"k={}\".format(K), color=\"red\")\n", | |
"ax.legend()\n", | |
"ax.set_xlim(np.min(t), np.max(t))\n", | |
"ax.set_ylim(-0.5, 4)\n", | |
"plt.show()" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab_type": "code", | |
"id": "vlf7MYBpOe4a", | |
"colab": {} | |
}, | |
"source": [ | |
"#@title もっと K を大きくしてみよう { run: \"auto\" }\n", | |
"K = 10 #@param {type:\"slider\", min:10, max:100, step:10}\n", | |
"hoge = ft[K]\n", | |
"fig, ax = plt.subplots(facecolor=\"white\", figsize=(8, 6))\n", | |
"ax.plot(t, f, \"-\", label=\"$f(t)$\", color=\"black\")\n", | |
"ax.plot(t, hoge, \"-\", label = \"k={}\".format(K), color=\"red\")\n", | |
"ax.legend()\n", | |
"ax.set_xlim(np.min(t), np.max(t))\n", | |
"ax.set_ylim(-0.5, 4)\n", | |
"plt.show()" | |
], | |
"execution_count": 0, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "edzGqC-eAu32", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"## おまけ" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "B1_RMhi5BJL1", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"### Colab Notebook を自分の Google Drive 上に保存する\n", | |
"\n", | |
"いじった Colab Notebook を残しておきたい場合,次のようにすると,自分の Google Drive 上へ保存できます.\n", | |
"\n", | |
"1. 自分の Google アカウント(学籍番号@mail.ryukoku.ac.jpのでもよいし,個人のでもよい)でログインした状態で,この Notebook を開く\n", | |
"1. 「ファイル」 > 「ドライブにコピーを保存」とすると,ブラウザの画面が切り替わり,「hoge.ipynb のコピー」のような名前の Colab Notebook が開いた状態になる.\n", | |
"1. その画面で「ファイル」 > 「ドライブで探す」とすると,コピーしたファイルが,GoogleDriveの\n", | |
"```\n", | |
"「マイドライブ」 > 「Colab Notebooks」\n", | |
"```\n", | |
"にあることがわかる.\n", | |
"1. ファイル名に「のコピー」がついたままなのは気持ちわるいので,適当に変更.拡張子は .ipynb で.\n", | |
"1. 好きにいじる.\n", | |
"1. 適宜「ファイル」 > 「保存」 する.\n" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "iy0aW4e5DswI", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"### Colab について知りたい\n", | |
"\n", | |
"Google Colab について知りたいひとは,Google の Colab 紹介ページへどうぞ: https://colab.research.google.com/?hl=ja これ自身が Colab のページです.\n", | |
"\n", | |
"Google Colab は,Jupyter Notebook をもとに作られています.**Jupyter Notebook** は,自分のPC上でPythonなどのプログラムを対話的に実行できる「ノートブック」を,ブラウザからアクセスできる仕組みです.最近は,Python 以外の様々な言語に対応しています.\n", | |
"\n", | |
"いろいろググって調べてみるとよいでしょう.\n", | |
"\n", | |
"そのうちどこかに,自分のPCにPythonとかJupyter関係とかインストール方法を説明する資料を作りたい...." | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "eAZAVIn0F5KD", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"### 猫出したい?コーギー出したい?" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "Ew4xCbvZGJNu", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"「ツール」 > 「設定」 > 「その他」" | |
] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment