need help with gauss elimination
37 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(3 个)
Sam Chak
2022-5-21
Hi @Matt Thomas
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
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.
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]
y = [1;8;-5]
% Find coefficients, called "x" for some reason.
x = A \ y
% Double check that we get the right y's out
y1 = 2 * x(1) + x(2) - x(3) % Should be = 1
y2 = x(1) + 2 * x(2) + x(3) % Should be = 8
y3 = -x(1) + x(2) - x(3) % Should be −5
yCheck = A * x
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!