Can someone help me graph this function

8 Ansichten (letzte 30 Tage)
Dante Truong
Dante Truong am 24 Nov. 2016
Kommentiert: Dante Truong am 24 Nov. 2016
It's an Hyperboloid of 2 sheets ( -x^2/a^2 - y^2/b^2 + z^2/c^2 =1) Also if the equation =0 instead of 1 how would you change it? Thank you.

Akzeptierte Antwort

Image Analyst
Image Analyst am 24 Nov. 2016
Try using meshgrid() to get all possible combinations of x and y in a range you specify:
% Declare some constants.
fontSize = 20;
a=1;
b=2;
c=3;
numElements = 30;
constant = 1; % or 0, whichever you want.
% Define range of x and y axes.
x = linspace(-2*a, 2*a, numElements);
y = linspace(-2*b, 2*b, numElements);
% Get every possible combination of x and y.
[X, Y] = meshgrid(x, y);
% Construct function.
Z1 = c * sqrt(constant + X.^2 / a^2 + Y.^2 / b^2);
Z1 = reshape(Z1, [], length(y));
surf(Z1);
Z2 = -c * sqrt(constant + X.^2 / a^2 + Y.^2 / b^2);
Z2 = reshape(Z2, [], length(y));
hold on;
surf(Z2);
% Fancy up the plot
grid on;
xlabel('X', 'FontSize', fontSize);
ylabel('Y', 'FontSize', fontSize);
zlabel('Z', 'FontSize', fontSize);
% Set up figure properties:
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Get rid of tool bar and pulldown menus that are along top of figure.
% set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')

Weitere Antworten (1)

Roger Stafford
Roger Stafford am 24 Nov. 2016
Bearbeitet: Roger Stafford am 24 Nov. 2016
X = -2*a:.001*a:2*a;
Y = -2*b:.001*b:2*b;
Z1 = c*sqrt(1+X.^2/a^2+Y.^2/b^2);
Z2 = -c*sqrt(1+X.^2/a^2+Y.^2/b^2);
surf(X,Y,Z1)
hold on
surf(X,Y,Z2)
If a 0 is used instead of a 1, then make that substitution in the expressions for Z1 and Z2.
  2 Kommentare
Dante Truong
Dante Truong am 24 Nov. 2016
Your code it said "Undefined function or variable 'a'."
Roger Stafford
Roger Stafford am 24 Nov. 2016
You have to specifically define all three quantities, a, b, and c in order to get a graph. You can't leave them as merely symbolic variables.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Discrete Data Plots finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by