Clear Filters
Clear Filters

How to plot a given vector field A(x y,z)=(-y)x hat + ( x) y hat + (0) z hat in x y plane .I tried this code but getting an error

6 views (last 30 days)
% Define the vector field A(x, y, z) = (-y)x_hat + (x)y_hat + (0)z_hat
syms x y z
A = [-y*x, x*y, 0];
% Define the x and y coordinates for the plot x = linspace(-2, 2, 20); y = linspace(-2, 2, 20); [X, Y] = meshgrid(x, y);
% Evaluate the vector field at each point on the grid U = subs(A(1), {x, y}, {X, Y}); V = subs(A(2), {x, y}, {X, Y});
% Plot the vector field quiver(X, Y, U, V); xlabel('x'); ylabel('y'); title('Vector Field Plot in the x-y Plane');

Answers (1)

VBBV
VBBV on 28 Jan 2024
% Define the vector field A(x, y, z) = (-y)x_hat + (x)y_hat + (0)z_hat
syms x y z
A = [-y*x, x*y, 0];
xx = linspace(-2, 2, 20);
yy = linspace(-2, 2, 20);
[X, Y] = meshgrid(xx, yy);
U = subs(A(1), {x, y}, {X, Y});
V = subs(A(2), {x, y}, {X, Y});
quiver(X, Y, U, V); xlabel('x'); ylabel('y');
title('Vector Field Plot in the x-y Plane');

Categories

Find more on Robust Control Toolbox in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!