Saddle shaped 3D Plot?

조회 수: 12 (최근 30일)
Matt Amador
Matt Amador 2017년 11월 29일
댓글: Phuc Nguyen 2021년 4월 17일
Hi there. I'm trying to determine if this equation does indeed make a "saddle" shapped 3D plot in MATLAB.
Somehow, my code below says that the way the variables are inputted are invalid. Can anyone help?
clc
clear all
x = input('Give me the first number: ');
y = input('Give me the second number: ');
[Xm, Ym] = meshgrid(x,y)
Lm = x^2 - y^2
hdl = surf(Xm, Ym, Lm)

답변 (1개)

Sammit Jain
Sammit Jain 2017년 11월 29일
Here, try something like this:
x = 1:10;
y = -10:10;
[Xm, Ym] = meshgrid(x,y);
Lm = Xm.^2 - Ym.^2;
hdl = surf(Xm, Ym, Lm);
Now, let's get to why you were getting errors: 1. When you create meshgrids, you want to define an entire grid, so you need a range of values for both coordinates. 2. The variables you will use to calculate the z values (dependent on x and y) needs to use the mesh variables, and not the ones you defined earlier. 3. Remember to use element-wise operations in your Lm definition, as you want to collectively apply the operation to all elements (square in this case)
Note: Try out different values of x and y to see what you get. I got desirable results with these values.
Hope this helps. Cheers.
  댓글 수: 1
Phuc Nguyen
Phuc Nguyen 2021년 4월 17일
hi may i ask what if i want the program to ask the user to input the range of the values for both coordinates.
I wrote one but the program returned error.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Surfaces and Volumes에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by