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

조회 수: 42 (최근 30일)
Maryam Abdelhamid
Maryam Abdelhamid 2020년 5월 9일
댓글: Walter Roberson 2020년 5월 18일
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
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
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
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 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