Question

I have this function:

function f=cost(x)
f=1.10471*x(1)^2*x(2)+0.04811*x(3)*x(4)*(14.0+x(2));

subject to

g(1)=tau-tau_max;
g(2)=sigma-sigma_max;
g(3)=x(1)-x(4);
g(4)=0.10471*x(1)^2+0.04811*x(3)*x(4)*(14+x(2))-5.0;
g(5)=0.125-x(1);
g(6)=delta-delta_max;
g(7)=P-PcX;

all g[1..7] should be <= 0

I have to keep any two of them as a constant and plot the f(x) The upper and lower bounds are respectively (x1..x4)

LowerBound=[0.125  0.1   0.1  0.125];
UpperBound=[5.0   10.0  10.0    5.0];    

thanks in advance...

edit: so far what i have done:

function [x1,x2,x3,x4]=objFuncPlot
[x2, x3] = meshgrid(0.1:.1:10, 0.1:.1:10);
//x1 and x4 is constant
x1=0.1996;
x4=0.2107;
//calculating constraints
[g1,g2,g3,g4,g5,g6,g7]=constraints(x1,x2,x3,x4); 
G1=[g1,g2,g4,g6,g7];
G2=[g3,g5];
infeasible=~all(G1(:)<=0) | ~all(G2(:)<=0);
//objective function
f=1.10471.*x1^2.*x2+0.04811.*x3.*x4.*(14.0+x2);
f(infeasible)=nan;
//plotting surf
surf(x2,x3,f,'LineStyle','none');
view(68,20)
hold on
xlabel('x');ylabel('y');zlabel('z');
hold off

//Constraints & Constants & Equations
function [g1,g2,g3,g4,g5,g6,g7]=constraints(x1,x2,x3,x4)
P=6000;
L=14;
E=30.*10^6;
G=12.*10^6;
tau_max=13600;
sigma_max=30000;
delta_max=0.25;
M=P*(14+x2./2);
R=sqrt(x2^2./4+(x1+x3)^2./4);
J=2.*(x1.*x2.*sqrt(2).*(x2^2/12+(x1+x3)^2/4));
tau_one=P./(sqrt(2).*x1.*x2);
tau_two=(M.*R)./J;
tau=sqrt(tau_one^2+2.*tau_one.*tau_two.*x2./(2.*R)+tau_two^2);
sigma=(6.*P.*L)./(x4.*x3^2);
delta=(4.*P.*L^3)./(30.*10^6.*x4.*x3^3);
PcX=4.013.*E./L^2.*sqrt(x3^2.*x4^6./36).*(1-x3.*sqrt(E./(4.*G))./(2.*L));
g1=tau-tau_max;
g2=sigma-sigma_max;
g3=x1-x4;
g4=0.10471.*x1^2+0.04811.*x3.*x4.*(14+x2)-5.0;
g5=0.125-x1;
g6=delta-delta_max;
g7=P-PcX;
Was it helpful?

Solution

A simple approach would be to define a new function which returns 1 when its argument is less than or equal to zero and returns NaN for +ve arguemnt

function H = mod_neg_step(argument)
         H = zeros(size(argument));
         H(argument<= 0) = 1;
         H(argument> 0) = NaN;
end

Then redefine your function f as

f=1.10471*x(1)^2*x(2)+0.04811*x(3)*x(4)*(14.0+x(2));
f=f*mod_neg_step(g(1))*mod_neg_step(g(2))*mod_neg_step(g(3))*mod_neg_step(g(4))...
  *mod_neg_step(g(5))*mod_neg_step(g(6))*mod_neg_step(g(7));

This will ensure that when g(1)...g(7) are positive your function f returns value NaN.Only when all of g(1)...g(7) are 0 or negative, function f will return

f=1.10471*x(1)^2*x(2)+0.04811*x(3)*x(4)*(14.0+x(2));

OTHER TIPS

You have a function of FOUR independent variables, so essentially a FIVE dimensional thing. What do you want to plot????????? You have a monitor, or a piece of paper. These things have two dimensions, not five.

The constraints here are not that important because you cannot plot this relationship anyway.

Just wanting to do something is not enough for it to happen. If wishes were horses, beggars would ride.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top