I need help please As soon as you can

조회 수: 1 (최근 30일)
Mahdi Almahuzi
Mahdi Almahuzi 2020년 4월 9일
댓글: DGM 2023년 5월 18일
I try to run this code to solve an n x n linear
system using the Gaussian Elimination Methods
but it says there is error in Error: File: mad.m Line: 7 Column: 20
Illegal use of reserved keyword "for".
can anybody solve the problem and send the code?
for i=j+1:m
a(i,:)=a(i,:)-a(j,:)*(a(i,j)/a(j,j));
enda = input('Enter the augument matrix:');
[m,n]=size(a);
for j=1:m-1
for z=2:m
if a(j,j)==for i=j+1:m
a(i,:)=a(i,:)-a(j,:)*(a(i,j)/a(j,j));
enda = input('Enter the augument matrix:');
[m,n]=size(a);
0;
t=a(j,:);a(j,:)=a(z,:);
a(z,:)=t;
end
end
end
end
end
x=zeros(1,m);
for s=m:-1:1
c=0;
for k=2:m
c=c+a(s,k)*x(k);
end
x(s)=(a(s,n)-c)/a(s,s);
end
disp('Gauss elimination method:');
a;
x';
  댓글 수: 4
Walter Roberson
Walter Roberson 2020년 4월 14일
There is no rule against posting assignment questions here.
The regular volunteers make attempts to guide people to understand the situation better, avoiding giving direct solutions for anything non-trivial.
DGM
DGM 2023년 5월 18일
This code came from the answer here. Don't invest too much time trying to fix random junk code you find on the internet.

댓글을 달려면 로그인하십시오.

답변 (1개)

Vinai Datta Thatiparthi
Vinai Datta Thatiparthi 2020년 4월 12일
To echo with what's already mentioned on this thread, "for" is a reserved keyword in MATLAB, we cannot use this as another variable. You might have to rearrange your code accordingly to avoid the error.

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by