Code to zero the elements above major diagonal

Hi, I’m finding an inverse of a matrix using Gaussian elimination. So, the first step is that I had to carry out row operations zero the elements below the diagonal and that has no problem with me. The problem is I don’t know what code I need to write on the script to zero the elements above the major diagonal. If I could get an answer for that it would be very great. Thank you.

1 件のコメント

James Tursa
James Tursa 2018 年 10 月 22 日
Please post your code and then tell us what steps you are doing or output you are getting that you think needs fixing.

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

回答 (2 件)

madhan ravi
madhan ravi 2018 年 10 月 22 日

0 投票

Example:
A = ones(4)
B = tril(A)
Or
B= tril(A,1)

3 件のコメント

madhan ravi
madhan ravi 2018 年 10 月 22 日
編集済み: madhan ravi 2018 年 10 月 22 日
The above answer makes the upper triangular matrix zero
Tiny Rick
Tiny Rick 2018 年 10 月 22 日
Do you have a specific formula to be written as a code to carry out the row operations?
madhan ravi
madhan ravi 2018 年 10 月 22 日
you mean rref? example of your output is there in my answer?

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

Tiny Rick
Tiny Rick 2018 年 10 月 22 日

0 投票

What I mean is there are values for the elements above the diagonal let’s say a matrix;
[5 7 9;0 4 2;0 0 3]
Do you have a formula that can be to carry out the row operations so that we can reduce the elements above the diagonal to zero? And It can accept any size of matrix

1 件のコメント

Steven Lord
Steven Lord 2018 年 10 月 22 日
Since this is almost certainly a homework assignment, your textbook probably has some pseudocode you can adapt into a function.
If this is not a homework assignment, don't invert and/or use Gaussian elimination. Use the backslash operator \ to solve your linear system of equations, or (if you absolutely must compute the inverse) use the inv function.

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

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

質問済み:

2018 年 10 月 21 日

コメント済み:

2018 年 10 月 22 日

Community Treasure Hunt

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

Start Hunting!

Translated by