need help with gauss elimination

16 views (last 30 days)
Matt Thomas
Matt Thomas on 20 May 2022
Edited: Matt Thomas on 22 May 2022
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

Answers (3)

Sam Chak
Sam Chak on 21 May 2022
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 Comments
Sam Chak
Sam Chak on 21 May 2022
Edited: Sam Chak on 21 May 2022
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 on 21 May 2022
thank you. i will try this code out and see how it goes.

Sign in to comment.


Torsten
Torsten on 22 May 2022
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 Comment
Matt Thomas
Matt Thomas on 22 May 2022
Edited: Matt Thomas on 22 May 2022
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

Sign in to comment.


Image Analyst
Image Analyst on 22 May 2022
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 Comment
Matt Thomas
Matt Thomas on 22 May 2022
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

Sign in to comment.

Categories

Find more on MATLAB in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!