for k=n:n-2,
for i=n-1:1
m=A(i,k)/A(k,k)
for j=n:1
A(i,j)=A(i,j)-A(k,j)*m
end
b(i)=b(i)-b(k)*m
end
end
I am trying to write a for loop code for Guess Jordan Elimination, where n=length(b) A and b are both matrices of a system of equations.
I think the problem is with k because the value of k in the workspace is []

2 件のコメント

per isakson
per isakson 2017 年 10 月 25 日
KSSV
KSSV 2017 年 10 月 26 日
YOu have not specified all the variables and you have not specified what error you face.

サインインしてコメントする。

 採用された回答

Jos (10584)
Jos (10584) 2017 年 10 月 26 日

0 投票

To have a for-loop iterate backwards you have to specify the increment
for k=1:10 % forward
...
end
for k = 10:-1:1 % backward
...
end

1 件のコメント

Fatimah Alghazal
Fatimah Alghazal 2017 年 10 月 26 日
I did what you said and it works..
Thanks,
This is the correct code.
for k=n:-1:n-2,
for i=(k-1):-1:1
m=A(i,k)/A(k,k)
for j=(k):-1:1
A(i,j)=A(i,j)-A(k,j)*m
end
b(i)=b(i)-b(k)*m
end
end

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で Loops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by