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

조회 수: 1 (최근 30일)
Amy Topaz
Amy Topaz 2022년 3월 19일
댓글: Voss 2022년 3월 20일
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
Image Analyst 2022년 3월 19일
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개)

Voss
Voss 2022년 3월 19일
%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
Amy Topaz
Amy Topaz 2022년 3월 20일
Can we not use the surface function here?
Voss
Voss 2022년 3월 20일
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);

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by