Files
Book4_Power-of-Matrix/Book4_Ch04_Python_Codes/Bk4_Ch04_15.ipynb
Iris Series: Visualize Math -- From Arithmetic Basics to Machine Learning 79be5dda7d Add files via upload
2025-02-01 17:06:45 +08:00

134 lines
2.8 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
{
"cells": [
{
"cell_type": "markdown",
"id": "73bd968b-d970-4a05-94ef-4e7abf990827",
"metadata": {},
"source": [
"Chapter 04\n",
"\n",
"# 行列式\n",
"Book_4《矩阵力量》 | 鸢尾花书:从加减乘除到机器学习 (第二版)"
]
},
{
"cell_type": "markdown",
"id": "167f6933-14ac-44fb-83e3-24d28b21a894",
"metadata": {},
"source": [
"该代码定义了一个 $2 \\times 2$ 矩阵 $A$,并计算其行列式。矩阵 $A$ 的定义为:\n",
"\n",
"$$\n",
"A = \\begin{bmatrix} 4 & 2 \\\\ 1 & 3 \\end{bmatrix}\n",
"$$\n",
"\n",
"行列式计算公式为:\n",
"\n",
"$$\n",
"\\det(A) = A_{11} A_{22} - A_{12} A_{21}\n",
"$$\n",
"\n",
"具体计算得:\n",
"\n",
"$$\n",
"\\det(A) = 4 \\cdot 3 - 2 \\cdot 1 = 12 - 2 = 10\n",
"$$\n",
"\n",
"该代码使用 `np.linalg.det` 函数来计算行列式的值。"
]
},
{
"cell_type": "markdown",
"id": "38e823dc-d626-4fba-8ac6-3fc7d73e9486",
"metadata": {},
"source": [
"## 导入所需库"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "1c1d325e-6981-4885-a9c1-d59bdbe0a194",
"metadata": {},
"outputs": [],
"source": [
"import numpy as np # 导入NumPy库用于数值计算"
]
},
{
"cell_type": "markdown",
"id": "cd7164de-4737-4076-89d3-3f7b8e5b988b",
"metadata": {},
"source": [
"## 定义矩阵A"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "194dc241-67d8-4ca1-a752-e6c7d2237c94",
"metadata": {},
"outputs": [],
"source": [
"A = np.array([[4, 2], # 定义矩阵A\n",
" [1, 3]])"
]
},
{
"cell_type": "markdown",
"id": "8bf849ff-6000-4d22-8e57-8d15debbb248",
"metadata": {},
"source": [
"## 计算矩阵A的行列式"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "d910437e-4d72-4c09-8618-a809968077a9",
"metadata": {},
"outputs": [],
"source": [
"det_A = np.linalg.det(A) # 计算矩阵A的行列式"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "85a80909-2aac-49ed-bb7a-f8cc6b80ee7d",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "ecd322f4-f919-4be2-adc3-69d28ef25e69",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.7"
}
},
"nbformat": 4,
"nbformat_minor": 5
}