Skip to content

Commit

Permalink
Merge pull request #65 from bovem/drafts
Browse files Browse the repository at this point in the history
Article #38: Tensors, Vectors, and Matrices
  • Loading branch information
bovem committed Jul 3, 2024
2 parents 311b1f6 + f73e6dc commit 3765ae7
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ For a glimpse into my journey and the projects I've been involved in, feel free
- <a target=_blank href="https://www.avni.sh/posts/go/file-handling-in-go/">File Handling in Go</a>
- <a target=_blank href="https://www.avni.sh/posts/go/concurrency-in-go/">Concurrency in Go</a>
- <a target=_blank href="https://www.avni.sh/posts/go/rest-api-requests-in-go/">REST API Requests in Go</a>
- <a target=_blank href="https://www.avni.sh/posts/linear-algebra/">Linear Algebra</a>
- <a target=_blank href="https://www.avni.sh/posts/linear-algebra/tensors/">Tensors</a>
- <a target=_blank href="https://www.avni.sh/posts/dsa/">Data Structures and Algorithms</a>
- <a target=_blank href="https://www.avni.sh/posts/dsa/time-complexity/">Time Complexity</a>
- <a target=_blank href="https://www.avni.sh/posts/dsa/arrays-strings-hashmaps/">Arrays, Strings, and HashMaps</a>
Expand Down
2 changes: 2 additions & 0 deletions content/contents.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ summary: "Index of all content"
- <a target=_blank href="/posts/go/file-handling-in-go/">File Handling in Go</a>
- <a target=_blank href="/posts/go/concurrency-in-go/">Concurrency in Go</a>
- <a target=_blank href="/posts/go/rest-api-requests-in-go/">REST API Requests in Go</a>
- <a target=_blank href="/posts/linear-algebra/">Linear Algebra</a>
- <a target=_blank href="/posts/linear-algebra/tensors/">Tensors</a>
- <a target=_blank href="/posts/dsa/">Data Structures and Algorithms</a>
- <a target=_blank href="/posts/dsa/time-complexity/">Time Complexity</a>
- <a target=_blank href="/posts/dsa/arrays-strings-hashmaps/">Arrays, Strings, and HashMaps</a>
Expand Down
5 changes: 5 additions & 0 deletions content/posts/linear-algebra/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: Linear Algebra
summary: Contains posts related to `Linear Algebra`
description: Contains posts related to Linear Algebra
---
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
115 changes: 115 additions & 0 deletions content/posts/linear-algebra/tensors/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
---
author: "Avnish"
title: "Tensors"
date: "2024-07-03"
description: "A tensor is an array of data expanding in multiple independent dimensions."
tags: ["math", "linear-algebra", "tensors", "vectors", "matrices"]
categories: ["Math", "Linear Algebra"]
series: ["Linear Algebra"]
aliases: ["tensors"]
cover:
image: "tensors-cover.png"
linkFullImages: true
alt: "A tensor is an array of data expanding in multiple independent dimensions."
caption: ""
relative: false
responsiveImages: false
ShowToc: true
TocOpen: false
comments: false
math: true
---

In linear algebra, a **tensor** is an array of data expanding in multiple (or zero) independent dimensions. It is used to represent quantities/equations/functions with multiple components, for example, the equation $3x+2y=0$ could be represented with the tensor $[3\ 2\ 0]$ where each value in the tensor represents the different components of the equation.

The number of independent dimensions of a tensor is called its **rank**.

Vectors and matrices could be generalized with the term tensor. The following Venn diagram visualizes the connection between them.

<p align="center"><img src="tensors-matrices-vectors-venn-diagram.png" alt="Venn Diagram of Tensors, Matrices and Vectors"></p>

# Scalar (Rank 0 Tensor)
A rank 0 tensor does not expand in any dimension, it is used to represent quantities that could be expressed by just one component i.e. its magnitude or scale. For example, the distance of $8\ cm$ between two points could be represented by the tensor $[ 8 ]$.

Since the value of a rank 0 tensor signifies only its *scale* or *magnitude* it could be called a **scalar** value. A scalar value could represent the mass of an object, the temperature of a room, the speed of a car, etc.

# Vector (Rank 1 Tensor)
A rank 1 tensor (or a **vector**) expands in one dimension i.e. it represents values with more than one component.

<p align="center"><img src="vectors.png" alt="Vectors (Rank 1) Tensor"></p>

Vectors are used to represent the magnitude and direction of different components of quantities such as displacement of an object, velocity of a car, electric field generated by a particle, etc. For example, displacement of $5\ m$ in the east direction and $10\ m$ in the north direction for an object could be represented with the vector $[5\ 10]$ where each component represents displacement in the east and north direction respectively.

In equations, vectors are denoted as bold letters ($\textbf{E}$) or letters with an arrow on top ($\vec{E}$).

## Magnitude of a Vector
To obtain the magnitude/scalar value of a vector we have to square all of its components and take the square root of their sum. For example, the magnitude of the displacement vector in the example above i.e. the distance between the start and the end will be $$|\ [ 0\ 5 \ 0 \ 10]\ | = \sqrt{0^2 + 5^2 + 0^2 + 10^2} = 25+100 = 125\ m$$
The magnitude of a vector is denoted by enclosing it within $|\ \ |$, for example, $|\vec{E}|$.

# Matrix (Rank 2 Tensor)
A rank 2 tensor (or a **matrix**) expands in two independent dimensions.
<p align="center"><img src="matrices.png" alt="Matrices (Rank 2) Tensor"></p>

A *system of linear equations*
$$x - 2y = 6$$
$$ x - y = 4 $$
$$ x + y = 0 $$
could be represented using a matrix as

$$ \begin{bmatrix} 1 & -2 & 6 \\\ 1 & -1 & 4 \\\ 1 & 1 & 0 \end{bmatrix}$$

This matrix has three rows and three columns. Thus, its **order** will be $3 \times 3$.
A matrix with one row or one column could be called a matrix or vector interchangeably.

# Tensors (Rank >=3)
The following diagram visualizes a rank 3 tensor in a 3-dimensional plane.
<p align="center"><img src="3d-tensor.png" alt="Rank 3 Tensor"></p>

Tensors with the rank greater than 3 are difficult to visualize but they could be represented as nested arrays in any programming language.
```python
# The following array has four levels of nesting
rank_4_tensor = [
[
[
[
6, 7, 8
],
[
8, 58, 26
]
],
[
[
5, 28, 19
],
[
10, 11, 12
]
]
],
[
[
[
13, 14, 15
],
[
16, 17, 18
]
],
[
[
19, 20, 21
],
[
22, 23, 24
]
]
]
]
```

# Resources
<a href="https://www.youtube.com/watch?v=f5liqUk0ZTw" target="_blank">What's a Tensor?</a>
<a href="https://mathworld.wolfram.com/TensorRank.html" target="_blank">Tensor Rank</a>
<a href="https://medium.com/linear-algebra/part-1-linear-equation-of-two-variables-and-matrices-d8de21eb8d51" target="_blank">Part 1 : Linear equation of two variables and Matrices</a>
<a href="https://medium.com/linear-algebra/part-4b-tensors-scalars-and-vectors-68cf6c1f2be" target="_blank">Part 4B : Tensors, Scalars, Vectors, and Matrices</a>
Binary file added content/posts/linear-algebra/tensors/matrices.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added content/posts/linear-algebra/tensors/vectors.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 3765ae7

Please sign in to comment.