Matlab 3D Plot

I want to plot two functions on the same 3D plot. X axis is Pa, Y axis is Pb, and Z axis is the value of each functions (Profit1 an Profit 3). I want to see dots (preferably different color) for each function's values based on different Pa and Pb combinations. So, it will be easy to navigate how these functions approach (or drift apart) based on Pa and Pb.
I attached the matlab file. My functions are Profit1 and Profit3.
Profit1 = (Pb*p-c)*Hb+Pa*(1-Pb)*wu*Ha;
Profit3 = Pa/(1-Pa)*(wu-w+Pb*(p-wu))*((1-Pa)*Ha+(1-Pb)*Hb)+w*(Pa*Ha+Pb*Hb)-c*(Ha+Hb);
Pa and Pb are probability values ranging 0 to 1, with 0.01 increment. I have the condition that Pa<Pb, always.
So,
Pb = 0:0.01:1
Pa = 0:0.01:(Pb - 0.01)
The constant values are:
c = 0;
p = 1;
wu = 0.8;
w = 0.5;
Ha = 100;
Hb = 200;
I tried to plot it but I want to know what 3D plot is the best in terms of easy navigation. I also wonder that if it is possible to plot this scenario on 2D.
Thank you in advance

Answers (2)

Geoff Hayes
Geoff Hayes on 12 Sep 2015
Sd - try adding the following lines of code to the end your script (which runs just fine)
close all;
figure;
hold on;
Pa = 0:0.01:(Pb-0.01);
Pb = 0:0.01:0.50;
plot3(table(:,1),table(:,2),table(:,3),'Color','g');
plot3(table(:,1),table(:,2),table(:,4));
view(45,45);
Since Pa and Pb are in the first and second columns respectively of the table then we use these as the first two inputs to the plot3 function. The third parameter is just the Profit1 or Profit3.

2 Comments

Hamoon
Hamoon on 12 Sep 2015
Actually there was no file there when I commented that, or maybe there was and I didn't see that. My comment was based on the question. So, Thank you Geoff.
Yellow Canary
Yellow Canary on 12 Sep 2015
Hello. Thank you. Do you know other graphs which are easier to see the difference between these two functions? I want to add this to my research paper. Maybe a bar graph might work better.

Sign in to comment.

Pb = 0:0.01:1
Pa = 0:0.01:(Pb - 0.01)
is going to give you a warning that the elements must be scalar. There is no way in MATLAB code arrays that have different numbers of columns depending on the row. You will need to loop over Pb and produce an output for each entry, or you will need to create a rectangular output and then arrange that the graphics is not produced for the places you do not want to see.
For example,
c = 0;
p = 1;
wu = 0.8;
w = 0.5;
Ha = 100;
Hb = 200;
Pb = 0 : 0.01 : 1;
Pa = 0 : 0.01 : 0.99;
[PB, PA] = ndgrid(Pb, Pa);
Profit1 = (PB*p-c)*Hb + PA.*(1-PB)*wu*Ha;
Profit3 = PA./(1-PA) .*(wu-w+PB*(p-wu)) .* ((1-PA)*Ha+(1-PB)*Hb) + w*(PA*Ha +PB*Hb) - c*(Ha+Hb);
unwanted = PA > PB;
subplot(1,3,1)
Results1 = Profit1;
Results1(unwanted) = NaN;
surf(PB, PA, Results1, 'EdgeColor', 'none');
title('Profit1')
subplot(1,3,2)
Results2 = Profit3;
Results2(unwanted) = NaN;
surf(PB, PA, Results2, 'EdgeColor', 'none');
title('Profit3')
subplot(1,3,3)
scatter3(PB(:), PA(:), Results2(:), 15, Results2(:)-Results1(:))
colorbar
title('Profit3 colored by difference to Profit1')

2 Comments

Yellow Canary
Yellow Canary on 13 Sep 2015
Hello. Thank you for the answer. I run the code and I am trying to understand the plots. What you mean by loop over Pb and produce an output for each entry? For each Pb, there are many Pa values. For example if Pb=0.10, Pa's will be from zero to 0.09. If Pb=0.11 , Pa's will be 0 to 0.10. So, for the two Pb values, most Pa values are doubled. Do yo mean I need to get rid of that to plot the data?
An example of looping:
c = 0;
p = 1;
wu = 0.8;
w = 0.5;
Ha = 100;
Hb = 200;
ax1 = subplot(1,2,1);
ax2 = subplot(1,2,2);
for Pb = 0 : 0.01 : 1;
Pa = 0 : 0.01 : Pb - 0.01;
Profit1 = (Pb*p-c)*Hb + Pa.*(1-Pb)*wu*Ha;
Profit3 = Pa./(1-Pa) .*(wu-w+Pb*(p-wu)) .* ((1-Pa)*Ha+(1-Pb)*Hb) + w*(Pa*Ha +Pb*Hb);
%
plot3(ax1, Pa, repmat(Pb,length(Pa),1), Profit1);
hold(ax1,'on');
plot3(ax2, Pa, repmat(Pb,length(Pa),1),Profit3);
hold(ax2,'on');
end
view(ax1,[169 18])
view(ax2,[169 18])

Sign in to comment.

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Asked:

on 11 Sep 2015

Edited:

on 14 Sep 2015

Community Treasure Hunt

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

Start Hunting!