I'm using MATLAB R2013a.
%I have two IVs and one DV: x1,x2 (IV) and x3 (1-x1-x2, DV)
m=[]; for x1 = .1:.01:.8 for x2 = .1:.01:.8 x3 = 1-x1-x2; %disp([i j k]);
m(end+1,:,:) = [x1;x2;x3]; end end condition_sum = m(:,3)<.099; m(condition_sum,:) = []; x1 = m(:,1); x2 = m(:,2); x3 = m(:,3); %These x values are then used to determine gamma values as follows
A12 = -.59; A13 = .72; A23 = 1.35; A21 = A12; A31 = A13; A32 = A23; g1 = exp(2*A12*x1.*x2.^2 + 2*A13*x1.*x3.^2 - 3*A12*x1.^2.*x2.^2 - 3*A23*x2.^2.*x3.^2 - 3*A13*x1.^2.*x3.^2); g2 = exp(2*A23*x2.*x3.^2 + 2*A21*x2.*x1.^2 - 3*A23*x2.^2.*x3.^2 - 3*A31*x3.^2.*x1.^2 - 3*A21*x2.^2.*x1.^2); g3 = exp(2*A31*x3.*x1.^2 + 2*A32*x3.*x2.^2 - 3*A31*x3.^2.*x1.^2 - 3*A12*x1.^2.*x2.^2 - 3*A32*x3.^2.*x2.^2); %Then, total pressure is calculated
P1sat = .193; P2sat = .085; P3sat = .061; p = x1.*g1*P1sat + x2.*g2*P2sat + x3.*g3*P3sat; %Unacceptable values are removed
m = [x1,x2,x3,p]; condition_pressure = m(:,4)>0.1500; m(condition_pressure,:)= []; %re-define x1,x2,x3,p
x1 = m(:,1); x2 = m(:,2); x3 = m(:,3); p = m(:,4);
At this point, I wish to create a graphical representation of my two IVs and total pressure(p): (x1,x2,p) I used plot3(x1,x2,p) but that doesn't really show what I was picturing. I was picturing a type of meshgrid (I couldn't figure it out from their webpage: http://www.mathworks.com/help/matlab/ref/meshgrid.html). What is the best method to use?
Secondly, there is a cost function associated with x1, x2 and x3. It is as follows:
%cost function
c1x1 + c2x2 + c3x3 + penalty = costc1 = 0.04c2 = 0.11c3 = 0.17penalty = 2.5p^2 %where p is p from before
I wished to overlap a cost function in the form of a color gradient. In other words, I wanted the previous meshgrid to have a shade of red to indicate high cost and a shade of blue to indicate low cost. What sort of function should I use to do this?
Any tips, suggestions, or useful resources would be much appreciated!
Thank you,
Matt
P.S.
Sorry for the obnoxious formatting…
Best Answer