I want to make a function that plots 3D quadratic surface

30 visualizzazioni (ultimi 30 giorni)
I want to creat a function that returns a graph of hyperbolic paraboloid just by entring the coefficient of x^2,y^2 and z
function hyperbolicparaboloid(A,B,C)
A=input('enter coeffecient of x^2');
B=input('enter coeffecient of y^2');
C=input('enter coeffecient of z');
%y^2/b^2-x^2/a^2=z/c
%where B=1/b^2, A=1/a^2, C=1/c
X=linspace(-10,10,100);
Y=linspace(-10,10,100);
Z=linspace(-10,10,100);
[X,Y]=meshgrid(X,Y);
Z=((Y.^2*B)-(X.^2*A))./C;
mesh(X,Y,Z);
view([130,30])
end
Althoug the code is working the function cannot be created
so what is the problem with this function?
  1 Commento
Walter Roberson
Walter Roberson il 9 Mag 2020
What is the point of accepting three input parameters and then promptly ignoring them? You should either have your function not accept any parameters or else you should have your function use the A, B, C values passed in.
Z=linspace(-10,10,100);
That statement is not productive: you overwrite the Z you create there.

Accedi per commentare.

Risposte (1)

rajat aggarwal
rajat aggarwal il 18 Mag 2020
Modificato: rajat aggarwal il 18 Mag 2020
You can use ezplot to draw hyperbolic paraboloid
following links can also help
clc;
clear all;
[X,Y,Z] = meshgrid(-10:0.5:10,-10:0.5:10,-10:0.5:10);
a=1;
b=1;
c=1;
V = X.^2/a^2 + Y.^2/b^2 - Z.^2/c^2;
p=patch(isosurface(X,Y,Z,V,1)); % This is the key step. It involves getting the part of the volume corresponding to the surface defined by the equation
set(p,'FaceColor','red','EdgeColor','none');
daspect([1 1 1])
view(3);
camlight
  1 Commento
Walter Roberson
Walter Roberson il 18 Mag 2020
Note that ezplot() is not recommended anymore. It uses older technology to create the plot. fplot() is a better choice in most cases now.

Accedi per commentare.

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by