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

1 view (last 30 days)
Amy Topaz on 19 Mar 2022
Commented: Voss on 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

Image Analyst on 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 CommentShow NoneHide None
Amy Topaz on 20 Mar 2022
Thank you, could we use the surf or surface function here?

### More Answers (1)

Voss on 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');
Voss on 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);