need help with gauss elimination

16 ビュー (過去 30 日間)
Matt Thomas
Matt Thomas 2022 年 5 月 20 日
編集済み: Matt Thomas 2022 年 5 月 22 日
I have no idea where to even start with this. i can do very very very basic things with matlab but a practice example the professor wants me to do is solve the following using gauss
2𝑥1 + 𝑥2 − 𝑥3 = 1
x1 + 2𝑥2 + 𝑥3 = 8
−𝑥1 + 𝑥2 − 𝑥3 = −5
thanks

回答 (3 件)

Sam Chak
Sam Chak 2022 年 5 月 21 日
Can you show the Gaussian elimination method in pen and paper?
This is not Gauss method, but requires the Inverse of Matrix A for checking the Answer.
% A*x = b
A = [2 1 -1; 1 2 1; -1 1 -1]
b = [1; 8; -5]
x = A\b
x =
2
1
4
  3 件のコメント
Sam Chak
Sam Chak 2022 年 5 月 21 日
編集済み: Sam Chak 2022 年 5 月 21 日
Alright, you can try something like this:
R1 = [2 1 -1 1]
R2 = [1 2 1 8]
R3 = [-1 1 -1 -5]
R22 = R2 - R1/2
R33 = R3 + R1/2
R333 = R33 - R22
R = [R1; R22; R333]
U = R(:, 1:3)
y = R(:, 4)
x = U\y
Matt Thomas
Matt Thomas 2022 年 5 月 21 日
thank you. i will try this code out and see how it goes.

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


Torsten
Torsten 2022 年 5 月 22 日
There are thousands of MATLAB codes for Gaussian elimination in the internet.
If you are not able or willing to program it on your own, just take one of them.
  1 件のコメント
Matt Thomas
Matt Thomas 2022 年 5 月 22 日
編集済み: Matt Thomas 2022 年 5 月 22 日
has nothing to do with NOT willing to, which i can see what you are saying because i do agree with you. Its a matter of i have never programed ever, and this was a surprise assignment the professor gave and it was due the same night.
I have rented multiple matlab books from the library to acomplish some of the things he is asking haha. Im trying to teach myself matlab but the things he is requrieing use very advanced code. I have just reached how to do a .* or ./ operation in a book from the library haha
I agree there are thousands of Gauss codes in the internet, hence why i came here. Its beeter to get it from the source rather than not. Bad practice does not make perfect and i am assuming that most here have better practice than some

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


Image Analyst
Image Analyst 2022 年 5 月 22 日
Sorry I just got back to this after leaving it for a day. If the equation is Ax = y, it seems natural that, dividing both sides by A would get you x, so you'd do x = y \ A. However that's not right (it was what I tried first). It's inverse of that -- A is in the "numerator" and y is in the "denominator" so it's x = A \ y. I think it's non intuitive but it is what it is.
% Ax = y
A = [2,1,-1;
1,2,1;
-1,1,-1]
A = 3×3
2 1 -1 1 2 1 -1 1 -1
y = [1;8;-5]
y = 3×1
1 8 -5
% Find coefficients, called "x" for some reason.
x = A \ y
x = 3×1
2 1 4
% Double check that we get the right y's out
y1 = 2 * x(1) + x(2) - x(3) % Should be = 1
y1 = 1
y2 = x(1) + 2 * x(2) + x(3) % Should be = 8
y2 = 8
y3 = -x(1) + x(2) - x(3) % Should be −5
y3 = -5
yCheck = A * x
yCheck = 3×1
1 8 -5
  1 件のコメント
Matt Thomas
Matt Thomas 2022 年 5 月 22 日
ok, this is awesome. now im going to write this code down and see how and why it works. thanks for this.
i can do all the numerical methods by hand for a few iterations, but this class is ment to use matlab or excell and i have never ever used both. i have always done my math by hand. i am old school. Never ever used a graphing calculator in any of my classes either. I wanted to learn how to do it rather than my calculator, plus my school wouldnt allow them anyway haha. calc 3 was really interesting with no graphing calculator

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by