How can generalize several "For loop" ?

2 views (last 30 days)
STamer
STamer on 20 Feb 2013
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

Accepted Answer

Babak
Babak on 20 Feb 2013
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

More Answers (0)

Categories

Find more on Read, Write, and Modify Image in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!