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

32 views (last 30 days)
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 Comment
Walter Roberson
Walter Roberson on 9 May 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.

Sign in to comment.

Answers (1)

rajat aggarwal
rajat aggarwal on 18 May 2020
Edited: rajat aggarwal on 18 May 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 Comment
Walter Roberson
Walter Roberson on 18 May 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.

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!