How can generalize several "For loop" ?

조회 수: 2 (최근 30일)
STamer
STamer 2013년 2월 20일
Hello;
I want to generalize the expression.It goes "for i=5:n"......"for i=n:n".
I tried nested loop statement but couldn't manage..Is there any help? Thanks and regards
A=input('Enter nxn matrix:')
B=input('Enter solution matrix(n*1):')
[n n]=size(A);
L=zeros(n);
for i=1:n
L(i,i)=1;
end
for i=2:n
L(i,1)=A(i,1)/A(1,1);
end
for i=3:n
L(i,2)=A(i,2)/A(2,2);
end
for i=4:n
L(i,3)=A(i,3)/A(3,3);
end

채택된 답변

Babak
Babak 2013년 2월 20일
A=input('Enter nxn matrix:')
B=input('Enter solution matrix(n*1):')
[n n]=size(A);
L=zeros(n);
for i=1:n
L(i,i)=1;
end
for k = 1:n
for i=k+1:n
L(i,k)= A(i,k)/A(k,k);
end
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Read, Write, and Modify Image에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by