3D Vector Fields of a given function
7 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I want to graphically present the vector field of a given function. Let's say that I have this function:

So, how can I plot the vector field of this function on a spherical surface?
Furthermore, how can i represent a equipotential surface lines ( sphere, as well ), of a similar function, preferably in 3D, but 2D will work as well.
This is a simulation which I obtained using Mathematica, but it is not really accurate.

Thank you!
0 commentaires
Réponses (1)
BhaTTa
le 27 Nov 2024
Modifié(e) : BhaTTa
le 27 Nov 2024
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');
0 commentaires
Voir également
Catégories
En savoir plus sur Surface and Mesh Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!