Plotting a 3d curve between a given equation and x and y axis

1 vue (au cours des 30 derniers jours)
Amy Topaz
Amy Topaz le 19 Mar 2022
Commenté : Voss le 20 Mar 2022
Need to plot a 3d curve between Hx/Hg vs x and y
Hx = (1/pi)*(arctan(((g/2 + x)/y) + arctan((g/2 - x)/y)));
%x varies from -4 to 4
%y varies from -4 to 4
%g is constant

Réponse acceptée

Image Analyst
Image Analyst le 19 Mar 2022
Did you try something like this? Adapt as needed:
numElements = 400;
% x varies from -4 to 4
x = linspace(-4, 4, numElements)
x = 1×400
-4.0000 -3.9799 -3.9599 -3.9398 -3.9198 -3.8997 -3.8797 -3.8596 -3.8396 -3.8195 -3.7995 -3.7794 -3.7594 -3.7393 -3.7193 -3.6992 -3.6792 -3.6591 -3.6391 -3.6190 -3.5990 -3.5789 -3.5589 -3.5388 -3.5188 -3.4987 -3.4787 -3.4586 -3.4386 -3.4185
% y varies from -4 to 4
y = linspace(-4, 4, numElements)
y = 1×400
-4.0000 -3.9799 -3.9599 -3.9398 -3.9198 -3.8997 -3.8797 -3.8596 -3.8396 -3.8195 -3.7995 -3.7794 -3.7594 -3.7393 -3.7193 -3.6992 -3.6792 -3.6591 -3.6391 -3.6190 -3.5990 -3.5789 -3.5589 -3.5388 -3.5188 -3.4987 -3.4787 -3.4586 -3.4386 -3.4185
% g is constant
g = 0.50
g = 0.5000
Hx = (1/pi)*(atan(((g/2 + x) ./ y) + atan((g/2 - x) ./ y)));
plot3(x, y, Hx, 'b.-', 'LineWidth', 2)
grid on
xlabel('x');
ylabel('y');
zlabel('Hx')
uiwait(helpdlg('Grab the graph and spin it around.'))
  1 commentaire
Amy Topaz
Amy Topaz le 20 Mar 2022
Thank you, could we use the surf or surface function here?

Connectez-vous pour commenter.

Plus de réponses (1)

Voss
Voss le 19 Mar 2022
%x varies from -4 to 4
x = -4:0.1:4;
%y varies from -4 to 4
y = -4:0.1:4;
%g is constant
g = 1;
% Hx = (1/pi)*(arctan(((g/2 + x)/y) + arctan((g/2 - x)/y)));
Hx = (1/pi)*(atan(((g/2 + x)./y) + atan((g/2 - x)./y)));
plot3(x,y,Hx);
grid on
xlabel('x');
ylabel('y');
zlabel('Hx');
  3 commentaires
Amy Topaz
Amy Topaz le 20 Mar 2022
Can we not use the surface function here?
Voss
Voss le 20 Mar 2022
No, we can.
%x varies from -4 to 4
x = -4:0.1:4;
%y varies from -4 to 4
y = -4:0.1:4;
%g is constant
g = 1;
[X,Y] = meshgrid(x,y);
% Hx = (1/pi)*(arctan(((g/2 + x)/y) + arctan((g/2 - x)/y)));
Hx = (1/pi)*(atan(((g/2 + X)./Y) + atan((g/2 - X)./Y)));
% surf(X,Y,Hx); surf() is another option
surface(X,Y,Hx);
view(3);

Connectez-vous pour commenter.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by