How to continue performing this flowchart about Gauss - Jordan method in a matlab code?
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
% I'm using matlab to convert this flowchart in a matlab code using "for loop", but I don't know how to continue here in this point. I guess it is possible to use else - if, but I´'m not sure. Please, could you check that?

%Here is the code that I did, but I don't know how to continue:
%Equations SOLVER by Gauss-Jordan METHOD
G=input('Put the n*(n+1) matrix to solve: ');
sz=size(G)
n=sz(1)
for i=1:n
c=G(i,i)
for j=1:n+1
G(i,j)=G(i,j)/c;
end
for k=1:n
0 commentaires
Réponses (1)
Steven Lord
le 26 Juil 2022
That check basically says to skip the first iteration of the loop. You could do this with an if statement and a continue statement, but rather than translate this strictly I'd probably instead just start the loop with k = 2.
% Strict translation with n = 5
for k = 1:5
if k == 1
continue
end
disp(k)
end
% Looser translation with n = 5
for k = 2:5
disp(k)
end
If n is less than 2 the loop over k won't do anything anyway, so starting at k = 2 doesn't cause any problems. Neither of the code examples below will display anything (other than the message that the loop is complete, since I wanted to prove to you that the code did in fact run.)
% Strict, n = 1
for k = 1:1
if k == 1
continue
end
disp(k)
end
disp('For loop #1 complete')
% Loose, n = 1
for k = 2:1
disp(k)
end
disp('For loop #2 complete')
0 commentaires
Voir également
Catégories
En savoir plus sur Numerical Integration and Differentiation 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!