Notebook 3 – Math 2121, Fall 2021
In today's notebook we'll try to get some feeling for vectors in
xxxxxxxxxx
md"# Notebook 3 -- Math 2121, Fall 2021
In today's notebook we'll try to get some feeling for vectors in $\mathbb{R}^2$ and $\mathbb{R}^3$ and their linear combinations. We'll also think about what a solution to a vector equation means. The code here involves a lot of new plotting functions in Julia."
Running this notebook (optional)
If you have Pluto up and running, you can access the notebook we are currently viewing by entering this link (right click -> Copy Link) in the Open from file menu in Pluto.
xxxxxxxxxx
md"## Running *this* notebook (optional)
If you have Pluto up and running, you can access the notebook we are currently viewing by entering [this link](http://www.math.ust.hk/~emarberg/teaching/2021/Math2121/julia/03_Math2121_Fall2021.jl) (right click -> Copy Link) in the *Open from file* menu in Pluto.
"
xxxxxxxxxx
begin
using PlutoUI
using Plots
end
Vectors in
Let's start out by drawing some vectors in
xxxxxxxxxx
md"## Vectors in $\mathbb{R}^2$
​
Let's start out by drawing some vectors in $\mathbb{R}^2$."
Create some vectors in
u1
= v1
= w1
=
u2
= v2
= w2
=
xxxxxxxxxx
begin
u1_slider = u1 Slider(-10:0.1:10, default=4, show_value=false)
u2_slider = u2 Slider(-10:0.1:10, default=8, show_value=false)
​
v1_slider = v1 Slider(-10:0.1:10, default=-10, show_value=false)
v2_slider = v2 Slider(-10:0.1:10, default=6, show_value=false)
​
w1_slider = w1 Slider(-10:0.1:10, default=2, show_value=false)
w2_slider = w2 Slider(-10:0.1:10, default=-9, show_value=false)
md"""**Create some vectors in $$\mathbb{R}^2$$**
`u1` = $(u1_slider) `v1` = $(v1_slider) `w1` = $(w1_slider)
`u2` = $(u2_slider) `v2` = $(v2_slider) `w2` = $(w2_slider)
"""
end
The vectors we created:
xxxxxxxxxx
md"The vectors we created:"
u = [ 4] v = [ -10] w = [ 2]
[ 8] [ 6] [ -9]
xxxxxxxxxx
begin
s = [string(u1), string(v1), string(w1), string(u2), string(v2), string(w2)]
pad = maximum([4, maximum(map(length,s))])
for i=1:length(s)
s[i] = " "^(pad - length(s[i])) * s[i]
end
top = join(["u = [$(s[1])]", "v = [$(s[2])]", "w = [$(s[3])]"], " ")
bot = join([" [$(s[4])]", " [$(s[5])]", " [$(s[6])]"], " ")
Text(join([top, bot], "\n"))
end
Display: u
v
w
xxxxxxxxxx
md"""**Display**:
`u` $(@bind uon html"<input type=checkbox >") `v` $(@bind von html"<input type=checkbox >") `w` $(@bind won html"<input type=checkbox >")
"""
xxxxxxxxxx
begin
lims = (
-(maximum([1, uon + von + won])) * 10,
maximum([1, uon + von + won]) * 10
)
p1 = scatter([0], [0], xlims = lims, ylims = lims,
legend = false, label = "origin", aspect_ratio=:equal,
title = "Vectors u, v, w")
if uon
quiver!(quiver = ([u1],[u2]), [0], [0], color = [:blue],)
end
if von
quiver!(quiver = ([v1],[v2]), [0], [0], color = [:orange],)
end
if won
quiver!(quiver = ([w1],[w2]), [0], [0], color = [:green],)
end
p2 = scatter([0], [0], xlims = lims, ylims = lims,
legend = false, label = "origin", aspect_ratio=:equal,
title = "Sum of vectors")
quiver!(
quiver = ([uon*u1 + von*v1 + won*w1],[uon*u2 + von*v2 + won*w2]),
[0], [0], color = [:black],
)
quiver!(
quiver = ([uon*u1],[uon*u2]),
[0], [0],
color = [:blue],
linestyle = :dashdot,
)
quiver!(
quiver = ([von*v1],[von*v2]),
[uon*u1], [uon*u2],
color = [:orange],
linestyle = :dashdot,
)
quiver!(
quiver = ([won*w1],[won*w2]),
[uon*u1 + von*v1], [uon*u2 + von*v2],
color = [:green],
linestyle = :dashdot,
)
plot(p1, p2, layout=2)
end
The vector
The right hand graph shows the sum of the displayed vectors on the left as the solid arrow. The dotted arrows are just copies of u, v, and w moved around.
xxxxxxxxxx
md"The vector $u$ is shown in blue, $v$ in orange, and $w$ in green.
​
The right hand graph shows the sum of the displayed vectors on the left as the solid arrow. The dotted arrows are just copies of u, v, and w moved around."
Linear combinations
Now that we have chosen some vectors
xxxxxxxxxx
md"## Linear combinations
​
Now that we have chosen some vectors $u$, $v$, $w$, let's think about the meaning of the linear combination $au + bv + cw$ where $a,b,c \in \mathbb{R}$ are scalars."
Choose some scalars in
a
= b
= c
=
xxxxxxxxxx
begin
a_slider = a Slider(-10:0.1:10, default=1*uon, show_value=false)
b_slider = b Slider(-10:0.1:10, default=1*von, show_value=false)
c_slider = c Slider(-10:0.1:10, default=1*won, show_value=false)
md"""**Choose some scalars in $$\mathbb{R}$$**
`a` = $(a_slider) `b` = $(b_slider) `c` = $(c_slider)
"""
end
The scalars we chose:
xxxxxxxxxx
md"The scalars we chose:"
a = 1 b = -1.4 c = 0
xxxxxxxxxx
Text(join([string("a = ", a), string("b = ", b), string("c = ", c)], " "))
xxxxxxxxxx
begin
p3 = scatter([0], [0], xlims = lims, ylims = lims,
legend = false, label = "origin", aspect_ratio=:equal,
title = "a•u, b•v, and c•w")
if uon
quiver!(quiver = ([a*u1],[a*u2]), [0], [0], color = [:blue],)
end
if von
quiver!(quiver = ([b*v1],[b*v2]), [0], [0], color = [:orange],)
end
if won
quiver!(quiver = ([c*w1],[c*w2]), [0], [0], color = [:green],)
end
p4 = scatter([0], [0], xlims = lims, ylims = lims,
legend = false, label = "origin", aspect_ratio=:equal,
title = "a•u + b•v + c•w")
quiver!(
quiver = (
[a*uon*u1 + b*von*v1 + c*won*w1],
[a*uon*u2 + b*von*v2 + c*won*w2]
),
[0], [0], color = [:black],
)
quiver!(
quiver = ([a*uon*u1],[a*uon*u2]),
[0], [0],
color = [:blue],
linestyle = :dashdot,
)
quiver!(
quiver = ([b*von*v1],[b*von*v2]),
[a*uon*u1], [a*uon*u2],
color = [:orange],
linestyle = :dashdot,
)
quiver!(
quiver = ([c*won*w1],[c*won*w2]),
[a*uon*u1 + b*von*v1], [a*uon*u2 + b*von*v2],
color = [:green],
linestyle = :dashdot,
)
plot(p3, p4, layout=2)
end
Varying
If
The same thing happens to the arrows representing
xxxxxxxxxx
md"Varying $a$ among positive values scales the length of the arrow that represents the vector $u$.
​
If $a$ is negative then this scalaing reverses the direction of $u$.
​
The same thing happens to the arrows representing $v$ and $w$ when we change $b$ and $c$."
Vector equations
Let's now think of
Choose a target vector
What does a solution to the equation
The solutions
xxxxxxxxxx
md"## Vector equations
​
Let's now think of $a,b,c$ as the variables $x_1=a$ and $x_2=b$ and $x_3=c$.
​
Choose a target vector $t =\left[\begin{array}{l} t_1 \\ t_2\end{array}\right] \in \mathbb{R}^2$.
​
What does a solution to the equation $x_1 u + x_2 v + x_3 w = t$ mean?
​
The solutions $x = \left[\begin{array}{l} x_1 \\ x_2 \\ x_3\end{array}\right]$ to this equation are the same as the solutions to the linear system whose augmented matrix is
$$A = \left[\begin{array}{ccc|c} u_1 & v_1 & w_1 & t_1 \\ u_2 & v_2 & w_2 & t_2 \end{array}\right]$$."
Let's create a random target vector
xxxxxxxxxx
md"Let's create a random target vector $t$."
2×1 Matrix{Float64}:
-19.6
11.3
xxxxxxxxxx
target = rand(-20:0.1:20, 2, 1)
Here's our coefficient matrix.
xxxxxxxxxx
md"Here's our coefficient matrix."
2×3 Matrix{Int64}:
4 -10 2
8 6 -9
xxxxxxxxxx
coefficient_matrix = [u1 v1 w1; u2 v2 w2]