How to create a quiver with given code?

2 views (last 30 days)
Below is the current code I have so far.
clear all
clc
x=0:5:20;
y=0:10:40;
z=0:20:80;
[X,Y,Z]=meshgrid(x,y,z);
v=[];
for i=1:5
for j=1:5
for k=1:5
v(i,j,k,1)=X(i,j,k)^2+Y(i,j,k)^2+Z(i,j,k)^2;
v(i,j,k,2)=2*X(i,j,k)*Y(i,j,k)*Z(i,j,k);
v(i,j,k,3)=X(i,j,k)+Y(i,j,k)+2*Z(i,j,k);
end
end
end
disp('v is');
disp(v)
From this I need to create a figure presenting the vector field (quiver3
function), name all axes, change the fonts of all labels to 12, reverse the direction of Z-axis
and add the title. Finally, calculate the divergence (divergence function) and curl (curl
function) of the vector field v.
I have never used the quiver comment or the divergence and curl functions. Any help would be appriciated.

Accepted Answer

Walter Roberson
Walter Roberson on 2 Sep 2022
x=0:5:20;
y=0:10:40;
z=0:20:80;
[X,Y,Z]=meshgrid(x,y,z);
v=[];
for i=1:5
for j=1:5
for k=1:5
v(i,j,k,1)=X(i,j,k)^2+Y(i,j,k)^2+Z(i,j,k)^2;
v(i,j,k,2)=2*X(i,j,k)*Y(i,j,k)*Z(i,j,k);
v(i,j,k,3)=X(i,j,k)+Y(i,j,k)+2*Z(i,j,k);
end
end
end
quiver3(X, Y, Z, v(:,:,:,1), v(:,:,:,2), v(:,:,:,3))

More Answers (0)

Categories

Find more on Vector Fields in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!