Info

Cette question est clôturée. Rouvrir pour modifier ou répondre.

error in my code

1 vue (au cours des 30 derniers jours)
José Carlos Ramos Salido Adame
Clôturé : MATLAB Answer Bot le 20 Août 2021
clear
R=1000*[5, 100, 200, 250];
v1=100;
A=[R(1),0,0,R(4),0;...
0,R(2),0,-R(4),R(5);...
0,0,R(3),0,-R(5);...
1,-1,0,-1,0;...
0,1,-1,0,1];
A=inverse(A);
v2=50;
B=[v1;0;-v2;0;0];
I_t=A*B;
K=1;
while transpose(I_t)< 0.0001*ones(1,5) & transpose(I_t)>=zeros(1,5)
I=I_t;
v2=v2+0.1;
B(3)=-v2;
I_t=A*B;
K=K+1;
end
v_max=v2 %max v2
v2=50;
B=[v1;0;-v2;0;0];
I_t=A*B;
K=1;
while transpose (I_t)< 0.0001*ones(1,5) & transpose(I_t)>=zeros(1,5)
I=I_t;
v2=v2-0.1;
B(3)=-v2;
I_t=A*B;
K=K+1;
end
v_min=v2 %min v2
Im having a problem in line 6 it says Index exceeds the number of array elements (4).
I need help please

Réponses (1)

Star Strider
Star Strider le 27 Oct 2020
The way you coded ‘R’:
R=1000*[5, 100, 200, 250];
it only has 4 elements. Nothing exists beyond ‘R(4)’.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by