Metadata-Version: 2.5
Name: linear-algebra01-kittithuch
Version: 0.2.3
Summary: แพ็กเกจสำหรับ linear algebra
Project-URL: Homepage, https://github.com/username/my_package
Project-URL: Documentation, https://github.com/username/my_package#readme
Project-URL: Repository, https://github.com/username/my_package.git
Project-URL: Bug Tracker, https://github.com/username/my_package/issues
Author-email: Kittithuch Chuaynoo <qmedikup@gmail.com>
License: MIT
License-File: LICENSE
Keywords: linear algebra,math
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Requires-Python: >=3.8
Requires-Dist: matplotlib
Requires-Dist: networkx
Requires-Dist: pandas
Requires-Dist: plotly
Requires-Dist: pyvista
Description-Content-Type: text/markdown


# Linear Algebra Package by Kittithuch (linear_algebra01_kittithuch)

`linear_algebra01_kittithuch` คือ Python Package ที่พัฒนาขึ้นสำหรับการคำนวณและศึกษาวิชา พีชคณิตเชิงเส้น (Linear Algebra) โดยครอบคลุมตั้งแต่การดำเนินการพื้นฐานของเวกเตอร์, Object-Oriented Programming (OOP), การประมวลผลไฟล์ (File I/O), การใช้ประโยชน์จาก Recursion & Memoization ไปจนถึงการแสดงผลเชิงทัศนสัมผัส (Data Visualization) ในรูปแบบ 2D, 3D Interactive และ Graph Theory

---

## คุณสมบัติหลัก (Features)

* **Vector Operations & Algorithms**: บวกเวกเตอร์, คูณสเกลาร์, หาขนาด (Magnitude), หาเวกเตอร์หนึ่งหน่วย (Unit Vector), ตรวจสอบเวกเตอร์ศูนย์ พร้อมการเปรียบเทียบระหว่าง Iterative และ Recursive Approaches
* **OOP & Inheritance Support**: รองรับการใช้งาน Class `Vector` และ `Vector2D` (Derived Class) สำหรับการประมวลผลเชิงวัตถุ
* **Subspace, Span & Memoization**: คำนวณผลรวมเชิงเส้น (Linear Combination), ตรวจสอบความเป็นอิสระเชิงเส้น (Linear Independence), สร้าง Standard Basis ใน $R^n$ และฟังก์ชัน Fibonacci Scalar Scaling ที่ใช้ Memoization ช่วยเพิ่มประสิทธิภาพ
* **File I/O & Exception Handling**: บันทึกและอ่านข้อมูลเวกเตอร์ผ่าน CSV (Pandas) และ JSON พร้อมระบบ Custom Exception Handling (`VectorFileError`, `VectorFormatError`)
* **Data Visualization Module**:
  * **Matplotlib**: แสดงผลเวกเตอร์ 2D และผลรวมเชิงเส้นบนระนาบฉาก
  * **Plotly**: พล็อตระนาบการ Span (Spanning Plane) ในมิติ 3D แบบ Interactive (ซูม/หมุนดูได้ผ่าน Web Browser)
  * **NetworkX**: แปลง Adjacency Matrix ให้เป็น Directed Graph แบบภาพเครือข่ายโหนด
  * **PyVista**: เรนเดอร์สนามเวกเตอร์ 3D (3D Vector Field) ความละเอียดสูง

---

## การติดตั้ง (Installation)

สามารถติดตั้งแพ็กเกจได้ง่ายๆ ผ่าน pip:

```bash
pip install linear_algebra01_kittithuch

```

*(หมายเหตุ: แนะนำให้ติดตั้งไลบรารีเสริมสำหรับการแสดงผลและการจัดการไฟล์ เช่น `pandas`, `matplotlib`, `plotly`, `networkx`, `pyvista`)*

---

## ตัวอย่างการใช้งาน (Usage Examples)

### 1. การใช้งานแบบ Procedural & OOP (Vector Classes)

```python
import linear_algebra01_kittithuch as lak

# --- แบบ Procedural ---
u = [1.0, 2.0, 3.0]
v = [4.0, 5.0, 6.0]
print("u + v =", lak.vector_add(u, v))  # Output: [5.0, 7.0, 9.0]

# --- แบบ OOP (Vector / Vector2D Class) ---
vec1 = lak.Vector2D(3, 4)
vec2 = lak.Vector2D(1, 2)

print("Magnitude of vec1:", vec1.magnitude())           # Output: 5.0
print("Angle with X-axis:", vec1.angle_with_x_axis())  # Output: 53.13 องศา
print("Cross Product 2D:", vec1.cross_product_2d(vec2)) # Output: 2.0

```

### 2. การใช้งาน File I/O และ Exception Handling

```python
import linear_algebra01_kittithuch as lak

sample_vectors = [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]]

# บันทึกและโหลดข้อมูล CSV
lak.save_vectors_to_csv(sample_vectors, "vectors.csv", labels=["v1", "v2"])
loaded_vectors = lak.load_vectors_from_csv("vectors.csv")

# Exception Handling ตัวอย่างเมื่อหาไฟล์ไม่เจอ
try:
    data = lak.load_vectors_from_csv("not_found.csv")
except lak.VectorFileError as e:
    print("Caught File Error:", e)

```

### 3. การแสดงผลกราฟิก (Visualization)

```python
import linear_algebra01_kittithuch as lak

# พล็อตเวกเตอร์ 2D
v1 = [3.0, 2.0]
v2 = [-1.0, 4.0]
v3 = [2.0, 6.0]
lak.plot_vectors_2d([v1, v2, v3], labels=["v1", "v2", "v1+v2"])

# พล็อตระนาบ Span ใน 3D ด้วย Plotly
lak.plot_spanning_plane_3d([1, 0, 2], [0, 2, 1])

# แสดง Matrix ในรูปแบบ Graph
adj_matrix = [
    [0.0, 1.5, 0.0],
    [2.0, 0.0, 3.1],
    [0.0, 0.5, 0.0]
]
lak.plot_matrix_as_graph(adj_matrix)

```

---

## โครงสร้างฟังก์ชันและคลาสในแพ็กเกจ

* **Vector Operations (`vector_operations.py`)**:
* `vector_add(u, v)` / `vector_add_recursive(u, v)` - บวกเวกเตอร์ (Iterative vs Recursion)
* `scalar_multiply(c, v)` - คูณเวกเตอร์ v ด้วยสเกลาร์ c
* `vector_magnitude(v)` / `unit_vector(v)` / `is_zero_vector(v)` - การหาขนาด เวกเตอร์หนึ่งหน่วย และตรวจสอบเวกเตอร์ศูนย์
* `vectors_to_dataframe(vectors, labels)` - แปลงลิสต์ของเวกเตอร์เป็น Pandas DataFrame
* `are_vectors_same_dimension(*vectors)` - ตรวจสอบว่าเวกเตอร์ทุกตัวมีมิติเท่ากันหรือไม่ (Variable-length Arguments)
* `Vector` / `Vector2D` - คลาสสำหรับจัดการข้อมูลเวกเตอร์แบบ OOP (พร้อม Inheritance & Operator Overloading)


* **Subspace & Span (`subspace_span.py`)**:
* `linear_combination(scalars, vectors)` - คำนวณผลรวมเชิงเส้น $c_1 v_1 + c_2 v_2 + ... + c_n v_n$
* `is_subspace_contains_zero(vectors)` - ตรวจสอบว่าชุดเวกเตอร์มีเวกเตอร์ศูนย์อยู่หรือไม่
* `is_linearly_independent_2d(u, v)` - ตรวจสอบการเป็นอิสระเชิงเส้นใน 2D
* `is_spanning_r2(v1, v2)` - ตรวจสอบว่า $v_1, v_2$ แผ่กว้างครอบคลุม $R^2$ หรือไม่
* `standard_basis_r(n)` - สร้างฐานหลักเดิม (Standard Basis) สำหรับ $R^n$
* `get_fibonacci(n)` / `fibonacci_vector_scale(n, v)` - คำนวณ Fibonacci Scalar โดยประยุกต์ใช้ Memoization


* **File I/O (`file_io.py`)**:
* `save_vectors_to_csv(vectors, filepath, labels)` / `load_vectors_from_csv(filepath)` - จัดการไฟล์ CSV
* `save_vectors_to_json(vectors_dict, filepath)` / `load_vectors_from_json(filepath)` - จัดการไฟล์ JSON
* `VectorFileError` / `VectorFormatError` - Custom Exception Classes สำหรับตรวจสอบข้อผิดพลาดในการจัดการไฟล์


* **Visualization (`visualization.py`)**:
* `plot_vectors_2d(vectors, ...)` - พล็อตเวกเตอร์ 2D ด้วย Matplotlib
* `plot_spanning_plane_3d(v1, v2)` - พล็อตระนาบ Spanning Plane 3D Interactive ด้วย Plotly
* `plot_matrix_as_graph(matrix)` - แปลง Matrix เป็น Directed Graph ด้วย NetworkX
* `plot_3d_vector_field()` - แสดงผล 3D Vector Field ด้วย PyVista



---

## ผู้พัฒนา (Author)

* **พัฒนาโดย**: Kittithuch
* **Version**: 0.2.3

```

```