MATLAB Answers

error in my code

조회 수: 1(최근 30일)
José Carlos Ramos Salido Adame
답변: Star Strider 27 Oct 2020
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

  댓글 수: 0

댓글을 달려면 로그인하십시오.

답변(1개)

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

  댓글 수: 0

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by