Effacer les filtres
Effacer les filtres

How can generalize severel "For loop" ?

2 vues (au cours des 30 derniers jours)
STamer
STamer le 20 Fév 2013
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
  2 commentaires
Mark Whirdy
Mark Whirdy le 20 Fév 2013
Modifié(e) : Mark Whirdy le 20 Fév 2013
Hi there
What are the values of A & n?
Could you values for all variables and the required output as well as describing what you are trying to do?
José-Luis
José-Luis le 20 Fév 2013
This is the second time in less than an hour that the same question has been asked in the forum. Looks like the instructor recommended Matlab answers. This can be done in a rather straightforward way. Please read the "Getting started" part of the documentation and ask specific questions whenever you encounter problems. People will be happy to help you then.

Connectez-vous pour commenter.

Réponse acceptée

Sean de Wolski
Sean de Wolski le 20 Fév 2013
Use a nested for loop:
for ii = 1:n
for jj = ii:n
stuff
end
end

Plus de réponses (1)

STamer
STamer le 20 Fév 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 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

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by