Vmls - sum of vectors, displacement

Hello, good afternoon.

I’m reading the VMLS book introduction about algebra linear and trying to draw the vector displacement in a plot. When sum two vectors a and b, the a+b vector dont need to connect to the end of b as shown in the book?

In my experiments the a+b vector crosses the b vector

function sumsdisp2(a::Vector, b::Vector)
    if (length(a) != 2) || (length(b) != 2)
        error("This function only works with 2d vectors");
    end
    ab = a + b;
    plot([0, a[1]], [0, a[2]], arrow=true, label="a");
    plot!([a[1], b[1]], [a[2], b[2]], arrow=true, label="b");
    plot!([0, ab[1]], [0, ab[2]], arrow=true, label="a+b");
end

image
What Im doing wrong?

I recommend working through a single case by hand
starting with a, b, and calculating a+b. Either of the
cases in the image you show would work.

Then determine what the plot command would be
to display each vector. It doesn’t look like any of the
vectors are being plotted correctly.

Can you reproduce the top left example specifically?

I’m not sure how you produced your example plot (I can’t get your output from various input vectors), but here’s how to do it with quiver, which is the Plots function for plotting vector fields:

julia> a = [1, 2]; b = [1, 0];

julia> a + b
2-element Vector{Int64}:
 2
 2

julia> quiver([0], [0], quiver = ([a[1]], [a[2]]))

julia> quiver!([a[1]], [a[2]], quiver = ([b[1]], [b[2]]))

julia> quiver!([0], [0], quiver = ([a[1] + b[1]], [a[2] + b[2]]))

It looks like in your example you added the result of a + b to a, rather than adding b (you get to [3, 4] which is [1, 2] + [2, 2] instead of [1, 2] + [1, 0] which I think is what you were trying to do)

1 Like

The book doesn’t give the vectors values, only the values. Then I’m trying to reproduce ploting, but have another thing that im not seeing in the process.

It worked. I’ll read more about quiver function in documentation. But what I notice is quiver maintains the vector magnitude when ploting above the origin (0, 0). Thank you.

image

From the graph: a = (5,1), b = (-1,3), and a+b = (4,4)