Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

error in my code

조회 수: 1 (최근 30일)
José Carlos Ramos Salido Adame
José Carlos Ramos Salido Adame 2020년 10월 27일
마감: MATLAB Answer Bot 2021년 8월 20일
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

답변 (1개)

Star Strider
Star Strider 2020년 10월 27일
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