(* 18/10/2018, K. Byczuk,  materialy pomocnicze do wykladu Elektrodynamika IN *)

(* Wykresy pola wektorowego i linii pola w d=2*)
VectorPlot[{x,-y},{x,-3,3},{y,-3,3}]
StreamPlot[{x,-y},{x,-3,3},{y,-3,3}]

(* Rozne pola, zrodla, wirowosc*)
VectorPlot[{x/Sqrt[x^2+y^2],y/Sqrt[x^2+y^2]},{x,-3,3},{y,-3,3}]
VectorPlot[{x/Sqrt[x^2+y^2],-y/Sqrt[x^2+y^2]},{x,-3,3},{y,-3,3}]

VectorPlot[{y/Sqrt[x^2+y^2],x/Sqrt[x^2+y^2]},{x,-3,3},{y,-3,3}]
VectorPlot[{y/Sqrt[x^2+y^2],-x/Sqrt[x^2+y^2]},{x,-3,3},{y,-3,3}]

(*Pole Coulomba 1/r^2 w d=3*)
r[x_,y_,z_]=Sqrt[x^2+y^2+z^2];
(*Pole od ladunku dodatniego*)
VectorPlot3D[{x/r[x,y,z]^3,y/r[x,y,z]^3,z/r[x,y,z]^3},{x,-3,3},{y,-3,3},{z,-3,3}]
(*Pole od ladunku ujemnego*)
VectorPlot3D[{-x/r[x,y,z]^3,-y/r[x,y,z]^3,-z/r[x,y,z]^3},{x,-3,3},{y,-3,3},{z,-3,3}]

(*Pole Coulomba 1/r^2 w d=3 od dwoch zrodel*)
(* (a,b,c) polozenie zrodla*)
g[x_,y_,z_,a_,b_,c_]=Sqrt[(x-a)^2+(y-b)^2+(z-c)^2];
VectorPlot3D[{(x+1)/g[x,y,z,-1,-1,-1]^3+(x-1)/g[x,y,z,1,1,1]^3,(y+1)/g[x,y,z,-1,-1,-1]^3+(y-1)/g[x,y,z,1,1,1]^3,(z+1)/g[x,y,z,-1,-1,-1]^3 +(z-1)/g[x,y,z,1,1,1]^3 },{x,-3,3},{y,-3,3},{z,-3,3}]
VectorPlot3D[{(x+1)/g[x,y,z,-1,-1,-1]^3-2(x-1)/g[x,y,z,1,1,1]^3,(y+1)/g[x,y,z,-1,-1,-1]^3-2 (y-1)/g[x,y,z,1,1,1]^3,(z+1)/g[x,y,z,-1,-1,-1]^3 -2 (z-1)/g[x,y,z,1,1,1]^3 },{x,-3,3},{y,-3,3},{z,-3,3}]

(* Linie sil w plaszczyznie z=0 od dwoch zrodel w plaszczyznie z=0*)
StreamPlot[{(x+1)/g[x,y,0,-1,-1,0]^3-(x-1)/g[x,y,0,1,1,0]^3,(y+1)/g[x,y,0,-1,-1,0]^3-(y-1)/g[x,y,0,1,1,0]^3},{x,-3,3},{y,-3,3}]

(*Linie sil od czterech ladunkow, zadanie z tw. Earnshawa*)
StreamPlot[{(x+1)/g[x,y,0,-1,-1,0]^3+(x-1)/g[x,y,0,1,1,0]^3+(x+1)/g[x,y,0,-1,1,0]^3+(x-1)/g[x,y,0,1,-1,0]^3,(y+1)/g[x,y,0,-1,-1,0]^3+(y-1)/g[x,y,0,1,1,0]^3 +(y-1)/g[x,y,0,-1,1,0]^3+(y+1)/g[x,y,0,1,-1,0]^3},{x,-3,3},{y,-3,3}]