3d implicit function plot with the sign function

4 views (last 30 days)
Dear all,
I need help with plotting the set of probability functions which have constant entropy:
where c is some positive real number.
I've tried to define a partial function equal to NaN whenever and then use fimplicit3 to plot this -- but failed.
Instead, I've attempted to use the sign function instead: .
So, .
When plotting this function, I obtained plots that just do not look right to me.
After failing for a long time, I finally come to believe that there's a problem with plotting the sign function. Here's my code:
syms x y z
f = @(x,y,z) (-0.1+(sign(x+y+z-1).*sign(x+y+z-1)));
interval = [0 1 0 1 0 1];
fimplicit3(f,interval)
xlabel('P(\omega_1)')
ylabel('P(\omega_2)')
zlabel('P(\omega_3)')
hold off
view([132 48])
This is an implicity plot of all such that . There shouldn't be any such numbers.
However, Matlab plots some such values.
Could someone please help. All help much appreciated.
Best,
Juergen

Answers (1)

Torsten
Torsten on 15 Feb 2023
MATLAB assumes that the function f you provide is continuous. For x+y+z =1, the function returns -0.1, for all other triples for x,y and z, it returns 0.9. Thus MATLAB assumes that "very near" to x+y+z=1, there is the surface with f(x,y,z) = 0.
  3 Comments
Torsten
Torsten on 15 Feb 2023
Edited: Torsten on 15 Feb 2023
MATLAB does not assume that the sign function is continuous, but that you prescribe a continuous function f if you apply "fimplicit3" to it.
Juergen
Juergen on 15 Feb 2023
Thanks Torsten -- again. It doesn't matter to me!, whether MATLAB assumes that the input of fimplicit3 is continuous or that the sign function is continuous.
Either way, I've found a workaround. It's not pretty; but it works -- and that counts! I'm now using fimplicit to solve a two-dimensional projection of the actual problem.
I then store the solutions to the implicit problem as a 2D-array.
I can then calculate the third probability as: 1 minus the sum of the other two probabilities. I then store these third values and then plot the 3D-array. As I said, it ain't pretty -- but it works.
For whatever reason, MATLAB displayed the solution to the final 2D-implicit problem in the figure. It took me a while to google: `set(jp, 'Visible', 'off');' -- this command vanquishes the 2D-plot.
Cheers,
Juergen
clear all
clc
interval = [0 1 0 1];
r = @(x,y) -x.*log(x)-y.*log(y)-(1-x-y).*log(1-x-y)-1.08;
rp=fimplicit(r,interval);
hp = findobj(gca,'Type', 'line');
xd = get(rp, 'XData');
yd = get(rp, 'YData');
for i = 1:length(xd)
rData(i,1)=xd(i);
rData(i,2)=yd(i);
rData(i,3)=1-xd(i)-yd(i);
end
l = @(x,y) -x.*log(x)-y.*log(y)-(1-x-y).*log(1-x-y)-1.05;
lp=fimplicit(l,interval);
hp = findobj(gca,'Type', 'line');
xd = get(lp, 'XData');
yd = get(lp, 'YData');
for i = 1:length(xd)
lData(i,1)=xd(i);
lData(i,2)=yd(i);
lData(i,3)=1-xd(i)-yd(i);
end
f = @(x,y) -x.*log(x)-y.*log(y)-(1-x-y).*log(1-x-y)-1;
fp=fimplicit(f,interval);
hp = findobj(gca,'Type', 'line');
xd = get(fp, 'XData');
yd = get(fp, 'YData');
for i = 1:length(xd)
fData(i,1)=xd(i);
fData(i,2)=yd(i);
fData(i,3)=1-xd(i)-yd(i);
end
g = @(x,y) -x.*log(x)-y.*log(y)-(1-x-y).*log(1-x-y)-0.8;
gp=fimplicit(g,interval);
hp = findobj(gca,'Type', 'line');
xd = get(gp, 'XData');
yd = get(gp, 'YData');
for i = 1:length(xd)
gData(i,1)=xd(i);
gData(i,2)=yd(i);
gData(i,3)=1-xd(i)-yd(i);
end
hh = @(x,y) -x.*log(x)-y.*log(y)-(1-x-y).*log(1-x-y)-0.6;
hhp=fimplicit(hh,interval);
hp = findobj(gca,'Type', 'line');
xd = get(hhp, 'XData');
yd = get(hhp, 'YData');
for i = 1:length(xd)
hData(i,1)=xd(i);
hData(i,2)=yd(i);
hData(i,3)=1-xd(i)-yd(i);
end
j = @(x,y) -x.*log(x)-y.*log(y)-(1-x-y).*log(1-x-y)-0.4;
jp=fimplicit(j,interval); set(jp, 'Visible', 'off');
hp = findobj(gca,'Type', 'line');
xd = get(jp, 'XData');
yd = get(jp, 'YData');
for i = 1:length(xd)
jData(i,1)=xd(i);
jData(i,2)=yd(i);
jData(i,3)=1-xd(i)-yd(i);
end
hold on
plot3(rData(:,1),rData(:,2),rData(:,3))
plot3(lData(:,1),lData(:,2),lData(:,3))
plot3(fData(:,1),fData(:,2),fData(:,3))
plot3(gData(:,1),gData(:,2),gData(:,3))
plot3(hData(:,1),hData(:,2),hData(:,3))
plot3(jData(:,1),jData(:,2),jData(:,3))
view([132 48])
xlabel('P(\omega_1)')
ylabel('P(\omega_2)')
zlabel('P(\omega_3)')
hold off

Sign in to comment.

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!