2020年6月28日日曜日

学習環境

新装版 数学読本3 (松坂 和夫(著)、岩波書店)の第12章(放物線・だ円・双曲線 - 2次関数)、12.1(放物線・だ円・双曲線)、放物線の問1の解答を求めてみる。



    1. y=14·2x2=18x2

    2. y=14·(-18)x2=-2x2

    3. y2=4·1xy2=4x

    4. y2=4·(-12)xy2=-2x

コード

#!/usr/bin/env python3
from sympy import sqrt, plot, Rational
from sympy.abc import x

print('1.')

ts = [(x ** 2 / 8, -2),
      (-2 * x ** 2, Rational(1, 8))] + \
    [[s * y for s in [-1, 1]]
     for y in [sqrt(4 * x), sqrt(-2 * x)]]
for i, t in enumerate(ts, 1):
    print(f'({i})')
    p = plot(*t,
             (x, -5, 5),
             ylim=(-5, 5),
             legend=True,
             show=False)
    colors = ['red', 'green', 'blue', 'brown', 'orange',
              'purple', 'pink', 'gray', 'skyblue', 'yellow']
    for o, color in zip(p, colors):
        o.line_color = color
    p.save(f'sample1_{i}.png')
p.show()

入出力結果(Zsh、PowerShell、Terminal、Jupyter(IPython))

% ./sample1.py
1.
(1)
(2)
(3)
(4)
%

0 コメント:

コメントを投稿