# How do i format my vector function correct for ploting with quiver?

**URL:** <https://discourse.julialang.org/t/how-do-i-format-my-vector-function-correct-for-ploting-with-quiver/121019>\
**Category:** Visualization\
**Tags:** plots\
**Created:** [October 7, 2024, 4:58pm UTC](https://discourse.julialang.org/t/how-do-i-format-my-vector-function-correct-for-ploting-with-quiver/121019 "2024-10-07T16:58:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Knud\_Sorensen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/knud_sorensen/32/52401_2.png) [@Knud\_Sorensen](https://discourse.julialang.org/u/Knud_Sorensen)\
**Post date:** [October 7, 2024, 4:58pm UTC](https://discourse.julialang.org/t/how-do-i-format-my-vector-function-correct-for-ploting-with-quiver/121019/1 "2024-10-07T16:58:43Z")

</div>

Hi. I have the following function I what to make a vector plot of:  
I have:

```julia
using Plots
using LinearAlgebra
L=0.1

s=[0 -L/2]
e=[0 L/2]
l=e-s

function GDA(x,y)
	if 0==x && 0==y
	   return 0.0
	end
	ra=[x y]-s
	rb=[x y]-e
	da=sqrt(dot(ra,ra))
 	db=sqrt(dot(rb,rb))
	res=-l*(1.0/da+1.0/db)
	res+=rb*dot(l,rb)/db^3
	res+=ra*dot(l,ra)/da^3
	t=ra/da+rb/db
	res+=t
	res+=t*dot(l,t)*(1.0/(da+db+L)+1.0/(da+db-L))
	res*=2.0/((da+db)*(da+db)-L*L)
	return res
end

xs = -2:0.2:2
ys = -2:0.2:2

xxs = [x for x in xs for y in ys]
yys = [y for x in xs for y in ys]

field = [GDA(x,y) for x in xs for y in ys]
quiver(xxs, yys, quiver=(field[1,:],field[2,:]))

```

Quiver don’t like the format, but how do I generate a format quiver like ?

---

<div class="post-metadata">

**Author:** ![rsenne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rsenne/32/212973_2.png) [@rsenne](https://discourse.julialang.org/u/rsenne)\
**Post date:** [October 7, 2024, 5:54pm UTC](https://discourse.julialang.org/t/how-do-i-format-my-vector-function-correct-for-ploting-with-quiver/121019/2 "2024-10-07T17:54:31Z")

</div>

This seemed to work:

```julia
using Plots
using LinearAlgebra

L = 0.1

s = [0, -L/2]
e = [0, L/2]
l = e - s

function GDA(x, y)
    if x == 0 && y == 0
        return [0.0, 0.0]
    end
    ra = [x, y] - s
    rb = [x, y] - e
    da = sqrt(dot(ra, ra))
    db = sqrt(dot(rb, rb))
    res = -l * (1.0/da + 1.0/db)
    res += rb * dot(l, rb) / db^3
    res += ra * dot(l, ra) / da^3
    t = ra/da + rb/db
    res += t
    res += t * dot(l, t) * (1.0/(da+db+L) + 1.0/(da+db-L))
    res *= 2.0 / ((da+db)^2 - L^2)
    return res
end

xs = -0.5:0.05:0.5
ys = -0.5:0.05:0.5

u = [GDA(x, y)[1] for y in ys, x in xs]
v = [GDA(x, y)[2] for y in ys, x in xs]

quiver(xs, ys, quiver=(u, v), aspect_ratio=:equal, 
       xlabel="X", ylabel="Y", title="Vector Field Plot")

```

And produced this:

![image](https://global.discourse-cdn.com/julialang/original/3X/d/6/d6ec3346d9905929c40f70da76a0a61f44d4f8a8.png)
