Plot a function with respect to another function

Dear guys,
I have two functions, each function of two variables x,y; namely z1 = f1(x,y) and z2 = f2(x,y) and want to plot z1 vs z2. The functions are below:
0 <= x,y <= 1;
z1 = -(1-x) .* ( (y./(1-x)).*(log((y./(1-x)))) + (1-((y./(1-x)))).*(log(1-((y./(1-x))))) ) /log(2);
z2 = -(1-y) .* ( (x./(1-y)).*(log((x./(1-y)))) + (1-((x./(1-y)))).*(log(1-((x./(1-y))))) ) /log(2);

 채택된 답변

Walter Roberson
Walter Roberson 2014년 3월 11일

0 개 추천

Assign values to x and y, do the calculations producing z1 and z2, then
plot(z1, z2)

댓글 수: 7

That simply does not give me the answer I want. The result plot is previously sketched in a paper and I want to reach that.
any other answers you can come up with?
Thank you
John D'Errico
John D'Errico 2014년 3월 11일
편집: John D'Errico 2014년 3월 11일
You need to define what it mean to plot z1 versus z1, if Walter's answer is not what you mean. Only you know what you mean here, and your question does not resolve that. If you have a sketch, then it would be best to show us, as your question is unclear.
Anything could be sketched in a paper. At the moment I have no reason to expect that the sketch is correct, or that you copied the equations exactly correctly. I also do not know what values you put in for x and y.
You are effectively calculating a 3D surface over x and y, and a second surface. What does it mean to plot one surface "vs" another surface? Normally when one plots p "vs" q then q becomes the control variable and p is shown for each q. In order to extend that to "z1 vs z2" with both being surfaces then you would need to create a plot that had at least 4 input dimensions and one output dimension.
if y = 1 (permitted since y <= 1), z2 doesn’t exist.
Thanks to all guys, I focused. The answer is right. My problem was that I used to put directly p1 and p2 into R12 and R21. The correct code is given below:
p1 = 0.01:0.001:0.49;
p2 = 0.01:0.001:0.49;
for i=1:1:481
for j=1:1:481
R12(i,j) = -(1-p1(i)) .* ( (p2(j)./(1-p1(i))).*(log((p2(j)./(1-p1(i))))) + (1-((p2(j)./(1-p1(i))))).*(log(1-((p2(j)./(1-p1(i)))))) ) /log(2);
R21(i,j) = -(1-p2(j)) .* ( (p1(i)./(1-p2(j))).*(log((p1(i)./(1-p2(j))))) + (1-((p1(i)./(1-p2(j))))).*(log(1-((p1(i)./(1-p2(j)))))) ) /log(2);
end
end
plot(R12,R21)
Now this is a large number of diagrams plotted simultaneously the envelope of which is the answer. I am trying to find a way to extract envelope here. If you have any idea, I appreciate having them (I am very basic in Matlab)
Also if y = 0 then you multiply 0 by log(0) which is going to give you NaN.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Line Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by