필터 지우기
필터 지우기

How to continue performing this flowchart about Gauss - Jordan method in a matlab code?

조회 수: 1 (최근 30일)
% 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

답변 (1개)

Steven Lord
Steven Lord 2022년 7월 26일
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
2 3 4 5
% Looser translation with n = 5
for k = 2:5
disp(k)
end
2 3 4 5
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')
For loop #1 complete
% Loose, n = 1
for k = 2:1
disp(k)
end
disp('For loop #2 complete')
For loop #2 complete

카테고리

Help CenterFile Exchange에서 Linear Algebra에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by