### Linear Equations

An equation is an statement that equates to expressions. In mathematics, a linear equation is an equation that may be put in the form of $ax + by + c = z$. In this form the values a is called the *coefficients*, that are often real numbers.*x,y,z* are called the variables. The *c* is often used for constants. 

If the equation has only one undefined variabe then we call the it Linear equation in one variabe.These equations take the form $a x + b = 0$.

Similarly, equations with two undefined variabes are called Linear equation in two variabe. These equations take generally take the form $a x + by + c = 0$. 

We can also have equations with multiple variable called polynomials. What is a polynomial? the word "polynomial" just means many terms. And a polynomial is an algebraic expression, that contains constants, variables with coefficients, and exponentials with a positive exponent.

#### Slope-Intercept Form

A line can be defined by its *m* slope, and its y-intercept y0 (the y coordinate where is intersects the y-axis). 
The most common form is the slope-intercept equation of a straight line: 

\begin{align}
y & = mx+b \\
\end{align}




Lets look at the video to get more understanding of linear equations.



```python
from IPython.display import YouTubeVideo
YouTubeVideo('CWByMDHyTos', width=860, height=460)
```










#### Plotting slope intercept form


```python
import numpy as np
import matplotlib.pyplot as plt

fig = plt.figure()
ax = fig.add_subplot(111)

# https://numpy.org/doc/stable/reference/generated/numpy.linspace.html
x = np.linspace(-10, 10, 1000)

# https://matplotlib.org/3.1.1/api/spines_api.html
ax.spines['left'].set_position('center')
ax.spines['bottom'].set_position('center')
ax.spines['right'].set_position('center')
ax.spines['top'].set_position('center')

plt.plot(x, 2*x+1, '-r', label = 'y = 2x+1')
plt.plot(x, 2*x-3, '-b', label = 'y = 2x+1')

plt.legend(loc = 'upper left')
plt.show()
```

### Functions

Sometimes a equation is written as a function, with f(x) instead of y. The above slope intecept equation can be written as $f(x) = mx + b$. We see functions everywhere in our lives, anything that has a input, process and output is a function. There are other functions like $x2$ is a squaring function, $y3+1$ is also a function and in geometry, Sine, Cosine and Tangent are functions.
Lets understand functions more clearly using the video below.


```python
from IPython.display import YouTubeVideo
YouTubeVideo('P3LsdcjqS8s', width=860, height=460)
```










One important thing to keep in mind is that function is single valued. one value will have only one output value. This can be tested by [verticle line test](https://en.wikipedia.org/wiki/Vertical_line_test), meaning no vertical line ever crosses more than one value


```python
def function(x, y):
    return (x**2+y)

print(function(5,3))
```

#### Plotting Functions


```python
import matplotlib.pyplot as plt
import numpy as np

# create 1000 equally spaced points between -10 and 10
# https://numpy.org/doc/stable/reference/generated/numpy.linspace.html
x = np.linspace(-100, 100, 1000)

# calculate the y value for each element of the x vector
y = x**2 - x + 2  

fig, ax = plt.subplots()

#https://matplotlib.org/api/_as_gen/matplotlib.axes.Axes.plot.html
ax.plot(x, y)
```

### Vectors

Any object that has length and direction is called a vector. We can use vectors to define the movement of objects from one point to another. Two vectors can be same if they have same magnitude and direction. Some exmaples of vectors can be Velocity, Acceleration, Force and increase/decrease in anything. Vectors are built from ordinary numbers, which form the components
of the vector. As described in the figure below, a vector has a head, a tail direction and magnitude.



Vector algebra is very useful in solving problems in Digital Technologies like Machine Learning, computer graphics, computer vision and data science.

#### Plotting a vectors in 2D




```python
import numpy as np
import matplotlib.pyplot as plt

v = np.array([2,4])

fig, ax = plt.subplots()

ax.plot([0, v[0]], [0, v[1]])

```


#### Plotting a vectors in 3D




```python
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

v = np.array([2,4,6])

fig = plt.figure()

ax = Axes3D(fig)

# x,y,z

ax.plot([0,0], [0,0], [-10, 10], 'k--')
ax.plot([0,0], [-10, 10], [0,0], 'k--')
ax.plot( [-10, 10], [0,0], [0,0],  'k--')


ax.plot([0, v[0]],[0,v[1]],[0,v[2]])

```

#### Vector Addition


```python
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

v = np.array([2,4,6])

u = np.array([-5, -3, -2])

z = np.add(v,u)

fig = plt.figure()

ax = Axes3D(fig)

# x,y,z

ax.plot([0,0], [0,0], [-10, 10], 'k--')
ax.plot([0,0], [-10, 10], [0,0], 'k--')
ax.plot( [-10, 10], [0,0], [0,0],  'k--')

print (z)
ax.plot([0, v[0]],[0,v[1]],[0,v[2]])
ax.plot([0, u[0]],[0,u[1]],[0,u[2]])
ax.plot([0, z[0]],[0,z[1]],[0,z[2]])
```

#### Vector Multiplication

Vector Multiplication is of three types "Scalar product", “Cross product” and “Dot product.”

In an scalar product we multiply the number directly by a scalar quantity and our vector scales by that much value.

A dot product can be thought as direction growth on a vector when multiplied with another vector, the result gives us the effect on the original vector(positive, negative, or zero). Dot product is a scalar quantity. We calculate the dot product using this formula $a · b = |a| × |b| × cos(θ)$

Cross Product is defined as a vector that is at right angles to the other two vectors . We calculate cross product using this formula $a × b = |a| |b| sin(θ) n$. We leverage the "Right Hand Rule" to better understand the cross product.

#### Try it out

If you point your index finger along vector a, and point your middle finger along vector b: the cross product goes in the direction of your thumb. , 


```python
u = np.array([1,2,3])
v = np.array([5,2,4])

# Dot product

dotp = np.dot(u,v)

# Cross Product

crossp = np.cross(u,v)

print("Dot Product is : {}".format(dotp))

print("Cross Product is : {}".format(crossp))
```

    Dot Product is : 21
    Cross Product is : [ 2 11 -8]


### Exercices

#### Pen and Paper

1. Find a vector that is orthogonal to the 3D vectors,  P = ( 3 , 2 , 1 ) , Q = ( 4 , − 1 , 1 )

2. Solve the given systems of linear equations:-
$x + 2y = 10$, $2x + y = 6$

####  Code

3. Using the above cross product approach, plot two 3D vectors and their cross product


```python
# Plot 3D vectors and their cross product in 3D Space.

def plot_cross_product(vector_a, vector_b):
    pass

plot_cross_product(u,v)
```

80104d2b9212601b3177a0e5166af0407902b585
ipynb
Jupyter Notebook
Equations_Functions_Vectors/.ipynb_checkpoints/Equations_Functions_Vectors-checkpoint.ipynb
yogeshmpandey/M4DT
efc1f22f6eaca92c4291a583d81d2d8a0717be95
Apache-2.0
2020-06-15T13:37:34.000Z
2020-06-15T13:37:34.000Z
Equations_Functions_Vectors/.ipynb_checkpoints/Equations_Functions_Vectors-checkpoint.ipynb
yogeshmpandey/M4DT
efc1f22f6eaca92c4291a583d81d2d8a0717be95
Apache-2.0
Equations_Functions_Vectors/.ipynb_checkpoints/Equations_Functions_Vectors-checkpoint.ipynb
yogeshmpandey/M4DT
efc1f22f6eaca92c4291a583d81d2d8a0717be95
Apache-2.0
Qwen/Qwen-72B
1. YES
2. YES