Hello everyone, I want to plot a 3d plot of the function z=2*X.^2-3*(X.*Y)+4*Y.^2 My code is the following: [X,Y]=meshgrid(-2:0.1:2); z=2*X.^2-3*(X.*Y)+4*Y.^2 surf(X,Y,z)
However when the plot appears the z axis is going up to 35 which shouldn't be correct since maximum value of z whould be for X=-2 and Y=2 which gives Z=12. What am I doing wrong?

 채택된 답변

Star Strider
Star Strider 2017년 10월 20일

0 개 추천

If you add this max call to your code (after you calculate ‘z’), you arrive at a different result:
max_z = max(z(:))
max_z =
36
So there is nothing wrong with your plot.
You can find the indices of the maximum with:
[r,c] = find(z == max_z)
that returns [41,1] and [1,41] for the two maxima.

댓글 수: 2

sotomayor
sotomayor 2017년 10월 20일
Nice!! Thanks for the help!!
Star Strider
Star Strider 2017년 10월 20일
As always, my pleasure!

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

추가 답변 (0개)

카테고리

제품

질문:

2017년 10월 20일

댓글:

2017년 10월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by