How to find the (x,y) combinations that make z=0?

조회 수: 14 (최근 30일)
Franziska
Franziska 2019년 9월 16일
편집: Kevin Phung 2019년 9월 18일
Hi Everyone
I have a matrix Z(i,j) that is a function of X and Y. Surface and contour plot look fine, but are difficult to interpret.
Is there a way to plot a function of X and Y , such that Z is equal to zero (or as close to zero as possible, since non of the elements in the Z matrix is actually zero)? What I'd like to find out is for which combinations of X and Y the Z-value is above and below zero.
My code is very long, but I did something like this to get matrix Z:
X=linspace(a,b)
Y=linspace(c,d)
for i = 1:numel(X)
Z(:,i) = functionZ(X(i))
%Functionhandle functionZ:
Z(j) = %functionZ(X)
Y=linspace(c,d)
for j = 1:numel(Y)
Z(j)= %function with parameter X
end
end
thanks in advance for any tips!
  댓글 수: 2
Matt J
Matt J 2019년 9월 16일
Is there a way to plot a function of X and Y , such that Z is equal to zero
But you say you've looked at contour plots. Shouldn't this already be given to you by the zero isocontour?
Franziska
Franziska 2019년 9월 17일
편집: Franziska 2019년 9월 17일
It does, but it does not give me the 'exact' zero-isocontour, and the contour plot is difficult to interpret, since there is one extreme peak. what I am looking for is a good way to report the result, that is the XY values for which Z is above / below zero.
Edit: Found a way:
to find the iso-countourline for Z=0
v=[0,0]
contour(X, Y, Z, v)
Thanks so much for giving me the crucial hint!

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

채택된 답변

Kevin Phung
Kevin Phung 2019년 9월 16일
편집: Kevin Phung 2019년 9월 18일
Correct me if I am misinterpreting your goal:
You have a function z(x,y).
You are trying to find the values of x and y that give you some particular values of Z, in this case very close to 0. You can try something like this:
% define some condition for Z values, in this case I want to look for all Z values in my
% Z matrix that are between 0 and 0.001.
% find() those values, and use ind2sub in order to grab the [row,col] pairs.
[x_ind,y_ind] = ind2sub(size(Z),find(and(Z=<0.001,Z>0 )));
xy_pairs = [X(x_ind) Y(y_ind)] % this will give you the x and y pairs
edit: you have already accepted my answer, but I forgot to include an '=' sign

추가 답변 (1개)

Matt J
Matt J 2019년 9월 16일

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by