サクサク読めて、アプリ限定の機能も多数!
トップへ戻る
おみそ汁
my-notes.hatenablog.com
Python3 コード triangle1.py #!/usr/bin/env python3 """(docstring) """ def print_math_problem(): """(docstring) """ print("""三角形が描けるかどうかを判定する。 以下の 3 つの線分を辺にもつような三角形は描けるか、描けないか。 (1). 6cm, 7cm, 12cm (2). 15cm, 8cm, 7cm (3). 5cm, 16cm, 9cm """) def triangle1(n_list): """(docstring) """ # 定理: # 三角形の 2 辺の和は他の 1 辺 より長い。 # 最大値 max_of_n_list = max(n_list) # 2 辺の和 (n_list の全合計から 最大値を引いている) sum_of_other_two_sid
Python3 コード complex_coefficient1.py #!/usr/bin/env python3 """(docstring) """ import sympy as sym class MathProblem: """(docstring) """ @staticmethod def print_math_problem(): """(docstring) """ print('複素係数の 2 次方程式を解け。\n') class ComplexCoefficient1: """(dostring) """ def __init__(self, expr): """(docstring) """ self.__expr = expr def complex_coefficient_func1(self): """(docstring) """ x = sym.Symb
使用する数式 上の数式は以下で作成 (SymPy: latex()) >>> import sympy as sym >>> k, n = sym.symbols('k n') >>> print(sym.latex(sym.Sum(4, (k, 1, 5)))) \sum_{k=1}^{5} 4 >>> print(sym.latex(sym.Sum(2*k**2 + 5*k + 3, (k, 1, 4)))) \sum_{k=1}^{4} \left(2 k^{2} + 5 k + 3\right) >>> print(sym.latex(sym.Sum(k**2 - 3*k, (k, 1, 5)))) \sum_{k=1}^{5} \left(k^{2} - 3 k\right) >>> print(sym.latex(sym.Sum(6*k**2 + 2, (k, 1, n))))
Python3 コード probability1.py #!/usr/bin/env python3 """(docstring) """ import numpy as np import sympy as sym def print_math_problem(): """(docstring) """ print("""1 個のサイコロを 1 回投げるという施行において、 以下の事象が起こる確率を求めよ。 (1). 偶数の目または 3 の倍数の目が出る。 (2). 偶数の目または 5 の目が出る。 """) def probability1(): """(docstring) """ # 確率: # 数式: # 確率 = ある事象の場合の数 / 全事象の場合の数 # 全体集合 (1 ~ 6) を U として作成しておく。 U = list(range(1, 7)) # (1). # U
Python3 コード combinations5.py #!/usr/bin/env python3 """(docstring) """ from sympy.functions.combinatorial.numbers import nC def print_math_problem(): """(docstring) """ print("""男 6 人、女 4 人の計 10 人から 4 人の代表を選ぶとき、 以下のそれぞれのような選び方の場合の数を求めよ。 (1). 4 人とも男となる。 (2). 男 2 人、女 2 人となる。 (3). 少なくとも 1 人は女である。 (4). 特定の男女を 1 人ずつ含む。 """) def combinations5(): """(docstring) """ # リストの順に: # # (1). nCr = nCn - r # (2).
Python3 コード sets_cap_cup_complement4.py #!/usr/bin/env python3 """(docstring) """ import functools import numpy as np def print_math_problem(): """(docstring) """ print("""1 から 600 までの整数の中で、2 の倍数の集合を A, 3 の倍数の集合を B, 5 の倍数の集合を C とする。 このとき、以下のものを求めよ。 (1). 集合 A の要素の個数 n(A) (2). 集合 B の要素の個数 n(B) (3). 集合 C の要素の個数 n(C) (4). 集合 A cap B の要素の個数 n(A cap B) (5). 集合 B cap C の要素の個数 n(B cap C) (6). 集合 C cap A の
Python3 コード limit4.py #!/usr/bin/env python3 """(docstring) """ import sympy as sym class MathProblem: """(docstring) """ @staticmethod def print_math_problem(): """(docstring) """ print('関数の極限を求めよ。') print('') class Limit4: """(docstring) """ def __init__(self, expr, num): """(docstring) """ self.__expr = expr self.__num = num def limit_func4(self): """(docstring) """ x = sym.Symbol('x') f = expr
Python3 コード limit4.py #!/usr/bin/env python3 """(docstring) """ import sympy as sym class MathProblem: """(docstring) """ @staticmethod def print_math_problem(): """(docstring) """ print('関数の極限を求めよ。') print('') class Limit4: "…
Python3 コード num_elems1.py #!/usr/bin/env python3 """(docstring) """ import numpy as np def print_math_problem(): """(docstring) """ print("""1 から 500 までの整数の中で、2 の倍数の集合を A, 5 の倍数の集合を B とする。このとき、以下を求めよ。 (1). 集合 A の要素の個数 n(A) (2). 集合 B の要素の個数 n(B) (3). 集合 A ∩ B の要素の個数 n(A ∩ B) """) def num_elems1(): """(docstring) """ # 全体集合 U U = np.array([i_1 for i_1 in np.arange(1, 501)]) # print(U.size) # or # pr
Python3コード binary_search.py #!/usr/bin/env python3 """(docstring) """ import random def binary_search(data, num): """(docstring) """ head = 0 tail = len(data) - 1 while head <= tail: center = (head + tail) // 2 if data[center] == num: print('{0}{1} {2}{3}'.format(center, '番目の要素が一致しました。', '数値: ', num)) break elif data[center] < num: head = center + 1 else: tail = center - 1 else: print('見つかりませんでした。
このページを最初にブックマークしてみませんか?
『統計学, 数学, R (R言語), Python 3』の新着エントリーを見る
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く