Skip to content

Commit

Permalink
P
Browse files Browse the repository at this point in the history
  • Loading branch information
taroyabuki committed Mar 13, 2024
1 parent 31b68e3 commit ed12464
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 23 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Wolfram|Alpha,Python,R,Mathematicaをフル活用して,大学教養レ
環境(言語)|サンプルコード|備考
--|--|--
[Wolfram\|Alpha](https://www.wolframalpha.com/)|[クエリと結果](code/wolframalpha)|無料
Google Colab (Python)|[![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/taroyabuki/comath/blob/master/code/python.ipynb)|無料(要登録)
Google Colab (Python)|[![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/taroyabuki/comath/blob/master/code/python/python.ipynb)|無料(要登録)
Google Colab (R)|[![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/taroyabuki/comath/blob/master/code/r/r.ipynb)|無料(要登録)
[Wolfram Cloud](https://www.wolframcloud.com)|動的生成[^1]|無料(要登録)
Mathematica|[mathematica.nb](code/mathematica/mathematica.nb) あるいは動的生成[^2]|[ラズベリーパイ版](https://www.wolfram.com/raspberry-pi/)は無料
Expand Down
24 changes: 2 additions & 22 deletions code/python/python.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ output:
[矢吹太朗『コンピュータでとく数学』(オーム社,\ 2024)](https://github.com/taroyabuki/comath)

```{r setup, include=FALSE}
system("pip install matplotlib pandas seaborn see scikit-learn statsmodels sympy")
system("pip install matplotlib IPython pandas seaborn see scikit-learn statsmodels sympy")
```

```{python}
Expand All @@ -19,9 +19,8 @@ from IPython.display import display

# 1 実行環境


```{python}
!python -m pip install see
#!python -m pip install see
```

```{python}
Expand Down Expand Up @@ -66,7 +65,6 @@ see(model)

# 2 数と変数


```{python}
2 * (-3)
```
Expand Down Expand Up @@ -269,7 +267,6 @@ refine(sqrt((x - 1)**2), Q.nonnegative(x - 1))

# 3 データ構造


```{python}
v = [2, 3, 5]; len(v)
```
Expand Down Expand Up @@ -404,7 +401,6 @@ english, math = m.T; english, math

# 4 可視化と方程式


```{python}
var('x')
plot(x**2 + 2 * x - 4, (x, -5, 3));
Expand Down Expand Up @@ -483,10 +479,8 @@ solve(Lt(x**2 + 2 * x - 4, 0), x)

# 5 論理式


# 6 1次元のデータ


```{python}
a = pd.Series([36, 43, 53, 55, 56, 56, 57, 60, 61, 73])
b = pd.Series([34, 39, 39, 49, 50, 52, 52, 55, 83, 97])
Expand Down Expand Up @@ -550,7 +544,6 @@ a.std(ddof=1) * z + a.mean()

# 7 2次元のデータ


```{python}
x = pd.Series([35, 45, 55, 65, 75])
y = pd.Series([114, 124, 143, 158, 166])
Expand Down Expand Up @@ -618,7 +611,6 @@ sns.regplot(x=data.x, y=data.y, ci=None);

# 8 確率変数と確率分布


```{python}
X = DiscreteUniform('X', range(1, 7)) # X = Die('X', 6)でもよい.
density(X)(2)
Expand Down Expand Up @@ -999,7 +991,6 @@ quad(lambda x: (x - rv.mean())**2 * rv.pdf(x), -1, 1)

# 9 多次元の確率分布


```{python}
X1 = DiscreteUniform('X1', range(1, 7))
X2 = DiscreteUniform('X2', range(1, 7))
Expand Down Expand Up @@ -1120,7 +1111,6 @@ plt.contourf(Y1, Y2, z, cmap='viridis'); plt.xlabel('Y1'); plt.ylabel('Y2');

# 10 推測統計


```{python}
mu = 2; sigma = 3; rv = stats.norm(mu, sigma)
data1 = [rv.rvs(5).mean() for _ in range(10000)]
Expand Down Expand Up @@ -1235,7 +1225,6 @@ stats.f.ppf((alpha / 2, 1 - alpha / 2), m - 1, n - 1)

# 11 線形回帰分析


```{python}
data = pd.DataFrame({
'x1': [1, 1, 2, 3], 'x2': [2, 3, 5, 7], 'y': [3, 6, 3, 6]})
Expand Down Expand Up @@ -1364,7 +1353,6 @@ sns.regplot(x=data.x1, y=data.y, ci=95);

# 12 関数の極限と連続性


```{python}
f = lambda x: 2 * x - 3; var('x')
limit(f(x), x, 1)
Expand Down Expand Up @@ -1393,7 +1381,6 @@ limit(abs(x) / x, x, 0, dir='+'), limit(abs(x) / x, x, 0, dir='-')

# 13 \kintou{3zw


```{python}
f = lambda x: x**3; var('h'); a = 1
limit((f(a + h) - f(a)) / h, h, 0)
Expand Down Expand Up @@ -1452,7 +1439,6 @@ series(f(x), x0=sol[0], n=3)

# 14 \kintou{3zw


```{python}
var('x')
integrate(-x**2 + 4 * x + 1, (x, 1, 4))
Expand Down Expand Up @@ -1524,7 +1510,6 @@ var('x'); integrate(exp(-x**2), (x, -oo, oo))

# 15 多変数関数の微分積分


```{python}
f = lambda x, y: x**2 * y / (x**4 + y**2); var('x y r theta')
(limit(limit(f(x, y), x, 0), y, 0), # ①
Expand Down Expand Up @@ -1601,7 +1586,6 @@ simplify(J.det())

# 16 ベクトル


```{python}
a = Matrix([2, 3, 5]); len(a)
```
Expand Down Expand Up @@ -1673,7 +1657,6 @@ np.arccos(a @ b / (linalg.norm(a) * linalg.norm(b)))

# 17 \kintou{3zw


```{python}
A = Matrix([[1, 2, 0], [0, 3, 4]]); A
```
Expand Down Expand Up @@ -1837,7 +1820,6 @@ np.linalg.matrix_rank(A)

# 18 ベクトル空間


```{python}
a1 = Matrix([3, 1]); a2 = Matrix([2, 2]); var('c1 c2')
solve(c1 * a1 + c2 * a2, (c1, c2))
Expand Down Expand Up @@ -1948,7 +1930,6 @@ Q, np.allclose(Q.T @ Q, np.eye(3))

# 19 固有値と固有ベクトル


```{python}
A = Matrix([[5, 6, 3], [0, 9, 2], [0, 6, 8]])
eigs = A.eigenvects()
Expand Down Expand Up @@ -2104,7 +2085,6 @@ print(np.cumsum(s2) / sum(s2)) # 累積寄与率(後述)

# 20 特異値分解と擬似逆行列


```{python}
A = Matrix([[1, 0], [1, 1], [0, 1]])
Ur, Sr, Vr = A.singular_value_decomposition()
Expand Down

0 comments on commit ed12464

Please sign in to comment.