How to use one code to solve different system of equations?

4 次查看(过去 30 天)
I'm new to matlab and I'm absolutely lost of how to work this program. I'm trying to solve three different system of equations with only one code, that computes a row echelon form of any 3x4 matrix and a reduce row echelon form of any 3x4 matrix without using the rref() command. Thank you so much in advance.
The system of equations:
1. 2x1 − 3x2 + x3 = 2
−x1 − x2 + 5x3 = −2
3x1 − 2x2 − x3 = 5
2. −4x2 + 2x3 = 5
−x1 + 3x3 = 2
3x1 − 2x2 = 1
3. −4x2 + x3 = −2
−x1 − x2 + 5x3 = −3
7x1 − 2x2 = −1
  3 个评论
Stephen23
Stephen23 2020-4-22
Original question by Rachel trent, recovered from Google Cache:
"How to use one code to solve different system of equations?"
I'm new to matlab and I'm absolutely lost of how to work this program. I'm trying to solve three different system of equations with only one code, that computes a row echelon form of any 3x4 matrix and a reduce row echelon form of any 3x4 matrix without using the rref() command. Thank you so much in advance.
The system of equations:
1. 2x1 − 3x2 + x3 = 2
−x1 − x2 + 5x3 = −2
3x1 − 2x2 − x3 = 5
2. −4x2 + 2x3 = 5
−x1 + 3x3 = 2
3x1 − 2x2 = 1
3. −4x2 + x3 = −2
−x1 − x2 + 5x3 = −3
7x1 − 2x2 = −1

请先登录,再进行评论。

回答(1 个)

Anirudh Singh
Anirudh Singh 2020-4-17
Create augumanted matrix (A) form the euqation , then use following code :
function A = row_echelon(A)
[m,n]=size(A);
for j=1:min(m,n)
A(j,:) = A(j,:)/A(j,j);
for i = j+1:m
A(i,:)= A(i,:)- A(j,:)*A(i,j);
end
end
end
Note : This code does not work when A(j,j)=0, So try to madify logic in this code according to your requirements.

类别

Help CenterFile Exchange 中查找有关 Linear Algebra 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by