How can I code a naive gauss elimination to show step by step after each elimination?

30 ビュー (過去 30 日間)
Quinten
Quinten 2016 年 9 月 6 日
コメント済み: moses 2023 年 11 月 2 日
I have this 3x3 matrix and my professor wants me to code this where it shows the steps for the forward and backwards elimination.
clc
clear
A = [3 -0.1 -0.2; 0.1 7 -0.3; 0.3 -0.2 10];
b = [7.85; -19.3; 71.4];
  2 件のコメント
Steven Lord
Steven Lord 2016 年 9 月 6 日
So go ahead and give it a try. The algorithm for Gaussian elimination should be in your textbook; it should be relatively easy to convert that into MATLAB code. If while you're implementing the algorithm you encounter difficulties at a particular step, show what you've done and ask a specific question about that particular step.
moses
moses 2023 年 11 月 2 日
does this solve your problem:
function upper_triangular_matrix = NaiveGauss(A)
[n, ~] = size(A);
upper_triangular_matrix = A;
for i = 1:n
for j = i+1:n
factor = upper_triangular_matrix(j, i) / upper_triangular_matrix(i, i);
upper_triangular_matrix(j, i:end) = upper_triangular_matrix(j, i:end) - factor * upper_triangular_matrix(i, i:end);
end
end
end

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

回答 (0 件)

カテゴリ

Help Center および File ExchangeMathematics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by