MATLAB Answers

plot 3D minimum value of a function

14 views (last 30 days)
Zekun Xue
Zekun Xue on 9 Feb 2020
Commented: Star Strider on 10 Feb 2020
Hello guys,
Thanks for looking over here.
I'd like to plot a minimum value, more precisely a 'platform' of a function in the 'surf' type of figure something like the graph I attached, no idea how to do it.
I appreciate if you could give me a hand.
Here I attached part of my code about what is my x and y axis:
pn1 = 0:0.1:5;
pn2 = 0:0.1:5;
[Pn1, Pn2] = meshgrid(pn1, pn2);
and what I plot in the figure:
Energy_consumption = Dm.* Pn1 + Tn.* Pn2;
surf(Pn1, Pn2, Energy_consumption);
Thanks you again.
Have a good day.

  0 Comments

Sign in to comment.

Answers (2)

dpb
dpb on 9 Feb 2020
Edited: dpb on 9 Feb 2020
Don't think it could be any easier...look at the following from one of the surf examples:
[X,Y,Z] = peaks(25);
CO(:,:,1) = zeros(25); % red
CO(:,:,2) = ones(25).*linspace(0.5,0.6,25); % green
CO(:,:,3) = ones(25).*linspace(0,1,25); % blue
hS1=surf(X,Y,Z,CO); % first peaks() surface; save handle for later
ZMIN=min(Z(:)); % get the overall minimum Z
hold on % ready axes to add another to it
hS2=surf(X,Y,ZMIN*ones(size(Z))); % and add the plane at the ZMIN height
produces:

  1 Comment

Zekun Xue
Zekun Xue on 10 Feb 2020
Wow, this is new to me, I definitely will try. Thank you very much!
Have a good day!

Sign in to comment.


Star Strider
Star Strider on 9 Feb 2020
Try this:
Dm = 20; % Create Variable
Tn = 30; % Create Variable
pn1 = 0:0.1:5;
pn2 = 0:0.1:5;
[Pn1, Pn2] = meshgrid(pn1, pn2);
Energy_consumption = Dm.* Pn1 + Tn.* Pn2;
surf(Pn1, Pn2, Energy_consumption)
hold on
E_c_min = 40; % Apparently Minimum Is 40
mesh(Pn1, Pn2, ones(size(Pn1))*40) % Create Flat Plane At Minimum
hold off
producing:
1plot 3D minimum value of a function - 2020 02 09.png

  2 Comments

Zekun Xue
Zekun Xue on 10 Feb 2020
Thank you very much! It is very detailed, I will try this in my code.
Have a good day!

Sign in to comment.