Hey @Stefan Naumoski, you can use quiver3 to plot vector fields and isosurface (or contour3 for 2D) to visualize equipotential surfaces.
Below I have provided the sample code, take it as a reference and modify the functions based on your requirement:
Code plotting the Vector Field:
% Constants
b = 1; % Example constant
a = 1; % Example constant
U = 1; % Applied voltage
% Create a grid on the sphere
theta = linspace(0, pi, 30);
phi = linspace(0, 2*pi, 30);
[Theta, Phi] = meshgrid(theta, phi);
R = 1; % Radius of the sphere
% Convert spherical to Cartesian coordinates
X = R * sin(Theta) .* cos(Phi);
Y = R * sin(Theta) .* sin(Phi);
Z = R * cos(Theta);
% Define the vector field in spherical coordinates
Vr = @(r, theta, phi) U * (b * r + a * cos(theta)); % Example function
Vtheta = @(r, theta, phi) 0; % Example: no theta component
Vphi = @(r, theta, phi) 0; % Example: no phi component
% Convert vector field to Cartesian coordinates
Vx = Vr(R, Theta, Phi) .* sin(Theta) .* cos(Phi);
Vy = Vr(R, Theta, Phi) .* sin(Theta) .* sin(Phi);
Vz = Vr(R, Theta, Phi) .* cos(Theta);
% Plot the vector field
figure;
quiver3(X, Y, Z, Vx, Vy, Vz);
axis equal;
title('Vector Field on Spherical Surface');
xlabel('X');
ylabel('Y');
zlabel('Z');
Code for plotting Equipotential Surfaces:
% Constants
b = 1; % Example constant
a = 1; % Example constant
U = 1; % Applied voltage
% Create a 3D grid
[x, y, z] = meshgrid(linspace(-2, 2, 50), linspace(-2, 2, 50), linspace(-2, 2, 50));
% Convert Cartesian to spherical coordinates
r = sqrt(x.^2 + y.^2 + z.^2);
theta = acos(z ./ r);
phi = atan2(y, x);
% Define the equipotential function
Equipotential = @(r, theta, phi) U * (b * r + a * cos(theta)); % Example function
% Compute the equipotential values over the 3D grid
V = Equipotential(r, theta, phi);
% Plot the equipotential surface
figure;
isosurface(x, y, z, V, 0.5 * max(V(:))); % Adjust the value for desired equipotential level
axis equal;
title('Equipotential Surface');
xlabel('X');
ylabel('Y');
zlabel('Z');