I want to make a function that plots 3D quadratic surface
20 次查看(过去 30 天)
显示 更早的评论
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 个评论
Walter Roberson
2020-5-9
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.
回答(1 个)
rajat aggarwal
2020-5-18
编辑:rajat aggarwal
2020-5-18
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 个评论
Walter Roberson
2020-5-18
Note that ezplot() is not recommended anymore. It uses older technology to create the plot. fplot() is a better choice in most cases now.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surface and Mesh Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!