How to calculate flux through a plane parallel to the XZ plane? Given a 3d vector field.

1 Ansicht (letzte 30 Tage)
Say we have a 3D vector field, let's say the field and grid are already defined
n = 100;
rmax = 10000;
x = linspace(-rmax,rmax,n)
y = linspace(-rmax,rmax,n)
z = linspace(-rmax,rmax,n)
% Say FX,FY, and FZ are the components of the vector field and we want to calculate the flux through the plane y = 9800
Fy9800 = (FY(Y==y(n-2)))'; %Picks out the Y- component of the vector field in the y = 9800 plane
Fy9800R = reshape(Fy9800,[n,n]);
[X2,Z2] = meshgrid(x,z)
surf(X2,Z2,Fy9800R) %Graphs the flux through the y=9800 plane
xlabel('X-Axis')
ylabel('Z-Axis')
zlabel('Flux')
Would this work? Thanks in advanced for the help.

Antworten (1)

Rahul
Rahul am 16 Jul. 2025
Hi Omar,
I understand that you are working with a 3D vector field defined on a grid and would like to extract and visualize the Y-component of the field on a specific plane, where one dimension (in this case, y) has a fixed value. The given approach involves trying to plot this as a surface to get a visual representation of the flux through that plane.
Here a few modifications that you can consider adopting in the given MATLAB script:
Fy9800 = (FY(Y == y(n-2)))';
  1. Floating-point comparison: Using 'Y == y(n-2)' may not behave as intended because of floating-point precision. Even if 'y(n-2)' is exactly 9800 in the vector, comparing it directly like this might not return 'true' due to small numerical differences.
  2. Indexing structure: This approach treats 'FY' and 'Y' as flat arrays, but if 'FY' is a 3D matrix (n x n x n), this kind of logical indexing can flatten and disrupt the spatial layout. A better and more structured way could be to directly use the known index for 'y = 9800'.
Since the given script utilizes 'linspace(-rmax, rmax, n)' to define the y vector, and since 'y(n-2)' is 9800, we can safely use the following indexing method:
iy = n - 2; % Index where y ≈ 9800
The relevant slice of 'FY' can then be extracted using regular 3D indexing, as shown below:
Fy9800 = squeeze(FY(:, iy, :)); % Slice of FY at y = 9800 (X-Z plane)
The 'squeeze' function has been used here to remove the singleton Y-dimension and get a 2D matrix of size (n x n) that corresponds to X and Z. Here is how you can align it properly with the plotting grid:
[X2, Z2] = meshgrid(x, z);
Fy9800R = Fy9800';
% Transpose to match dimensions of X2 and Z2
The transpose of the 'meshgrid(x, z)' creates matrices where rows correspond to Z and columns to X, and we want 'Fy9800R(i, j)' to correspond to 'Z(i)' and 'X(j)'.
This approach should allow you to create a clear surface plot of the Y-component of your vector field on the specified plane.
For more information regarding various functions used in the above mentioned code snippet, you can refer to the following documentation links:

Kategorien

Mehr zu Networks finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by