How to multiply, in a loop, a function by a variable from a matrix and plot the change.
Mostrar comentarios más antiguos
In a loop the variable 'x' is changing each itteration and I plot that. I want to include in this plot 'p3' as defined in line 18 of the code.
The ploted line of p3 suggests the value of 'x3' is a consistant 1; when I know that 'x' (which is [x1;x2;x3]) is changing with each itteration.
--Code used--
x1=1;
x2=1;
x3=1;
for j=300:20:2000
h3=j;
x=[x1;x2;x3];
c=[500;100;2000;];
A=[-1,-1,-1;1,0,0;0,1,0;0,0,1;200,2300,h3];
b=[-150;25;120;150;180000];
x=linprog(c,A,b);
A;
x;
p3=(95-(j-700)*.1)*x3;
plot(j,x,'.',j,p3,'.'); hold on
end
Note: "linprog" is for system optimization and is minimizing c^T*x subject to A*x<=b
the negative straight line is "p3" and only looks like this because the variable 'x3' is not updating (I think)

Also I am getting this error code in the terinal window (probable related)
Error using plot
Vectors must be the same length.
Error in Loop_Maximization_h3 (line 20)
plot(j,x,'.',j,p3,'.'); hold on
(thanks in advanse everyone, Started MATLAB this week)
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Programming en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
