Put In The For Command...
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
How Can I Simplify This Code Using For Command ...
tic
syms x y z
clc;
f1=x;
f2=y;
f4=x-16;
f5=y-20;
f6=1.5*x+y-30;
%dot3=solve(f1,f4);dot3=[dot3.x dot3.y]
dot4=solve(f1,f5);dot4=[dot4.x dot4.y];
dot5=solve(f1,f6);dot5=[dot5.x dot5.y];
dot6=solve(f2,f4);dot6=[dot6.x dot6.y];
%dot7=solve(f2,f5);dot7=[dot7.x dot7.y]
dot8=solve(f2,f6);dot8=[dot8.x dot8.y];
dot9=solve(f4,f5);dot9=[dot9.x dot9.y];
dot10=solve(f4,f6);dot10=[dot10.x dot10.y];
%dot11=solve(f5,f6);dot11=[dot10.x dot10.y]
z=inline(200*x+100*y);
cond=inline(1.5*x+y);
z1=0;
z2=z1;
z3=z1;
z4=z1;
z5=z1;
z6=z1;
if dot4(1)>=0 && dot4(1)<=16 && dot4(1)>=0 && dot4(2)<=20 && cond(dot4(1),dot4(2))<=30
z1=z(dot4(1),dot4(2));
end
if dot5(1)>=0 && dot5(1)<=16 && dot5(1)>=0 && dot5(2)<=20 && cond(dot5(1),dot5(2))<=30
z2=z(dot5(1),dot5(2));
end
if dot6(1)>=0 && dot6(1)<=16 && dot6(1)>=0 && dot6(2)<=20 && cond(dot6(1),dot6(2))<=30
z3=z(dot6(1),dot6(2));
end
if dot8(1)>=0 && dot8(1)<=16 && dot8(1)>=0 && dot8(2)<=20 && cond(dot8(1),dot8(2))<=30
z4=z(dot8(1),dot8(2));
end
if dot10(1)>=0 && dot10(1)<=16 && dot10(1)>=0 && dot10(2)<=20 && cond(dot10(1),dot10(2))<=30
z5=z(dot10(1),dot10(2));
end
if dot9(1)>=0 && dot9(1)<=16 && dot9(1)>=0 && dot9(2)<=20 && cond(dot9(1),dot9(2))<=30
z6=z(dot9(1),dot9(2));
end
ze=zeros(6,1);
ze(1)=z1;
ze(2)=z2;
ze(3)=z3;
ze(4)=z4;
ze(5)=z5;
ze(6)=z6;
zmain=max(ze)
toc
1 Kommentar
Jan
am 11 Apr. 2013
At first I would omit the repeated tests like:
if dot9(1)>=0 && dot9(1)<=16 && dot9(1)>=0 ...
If "dot9(1)" is greater equal zero in the first test, this is true for the 2nd test also.
Akzeptierte Antwort
Jan
am 11 Apr. 2013
Numbering the names of the variables is simply a bad programming technique. See Answers: FAQ How to create A1,A2,... in a loop.
1 Kommentar
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!