then I change the initial point and see the second vector is not in the place it should be, needs to modify the code…

using CalculusWithJulia
using Plots
gr() # better arrows than plotly()
quiver([0],[0], quiver=([1],[2]))
unzip(vs) = Tuple(eltype(first(vs))[xyz[j] for xyz in vs] for j in eachindex(first(vs)))
u = [2, 1]
v = [-2, 1]
w = u + v
p = [1,1]
quiver(unzip([p])..., quiver=unzip([u])) # initial at (1,1) terminal at (3,2)
quiver!(unzip([u])..., quiver=unzip([v])) # initial at (2,1) terminal at (0,2)
quiver!(unzip([p])..., quiver=unzip([w])) # initial at (1,1) terminal at (1,3)

Is there any code that can work for any kind of vectors for all kind of initial points with addition operations?

Just realize and edit it, it will work if we edit the second vector with

quiver!(unzip([u+p])..., quiver=unzip([v])) # initial at (3,2) terminal at (1,3)

Feel free to share more efficient code for vectors addition

The CalculusWithJulia package has an arrow! plot recipe that makes it a bit easier to plot a single vector anchored at a point p with length v. The example therein is:

u = [1, 2]
v = [4, 2]
w = u + v
p = [0,0]
plot(legend=false)
arrow!(p, u)
arrow!(u, v) # <-- plots v anchored at point u
arrow!(p, w)

This is a convenience for plotting 1 vector at a time and for 3-d vectors, as I’m not sure all backends for Plots handle 3-d arrows for Plots. For plotting many vectors at once, the use of quiver is likely significantly more efficient. As in the above (with slight modification and skipping the seriescolor flourish):

P = [p,u,p]
V = [u,v,w]
quiver(unzip(P)...; quiver=unzip(V))

(I prefer stacking the vectors differently from @ rafael.guerra allowing the use of unzip --which is basically SplitApplyCombine.invert here – to clean up the indexing.)

Yes, as a matter of fact, today I am learning how to plot 3d vectors rightly,

Simple vector addition in 3 dimension like (1,0,0) + (0,1,0) + (0,0,1) will result in (1,1,1). Need to create the Julia code for this. I think I want to try CairoMakie because their plot is interactive and can be rotated to any angle.