Gaussian Elimination Script Help

조회 수: 1 (최근 30일)
Callum C
Callum C 2016년 3월 13일
편집: John D'Errico 2016년 3월 13일
I'm trying to use the attached script.
No matter what matrix, I always get a similar response:
Gaussian elimination completed successfully
it needed 0 row exchanges
x =
0
0
0
0
0
Test: the product A*x for this x is:
ans =
0
0
0
0
0
I've been trying to figure this out for a while now, and would really appreciate some help! Thanks.
  댓글 수: 1
John D'Errico
John D'Errico 2016년 3월 13일
The simple answer is to learn to use the debugger. Use it to follow through your code at each step. Check on every line that it is doing something rational. It is not that hard to do once you learn how to use the tools.
HOWEVER...
You are a rarity, in that your code is actually reasonably well written. It is even documented. So I'll take a look at it.
Over the long term though, you will find your answer much sooner with the debugger.

댓글을 달려면 로그인하십시오.

답변 (1개)

John D'Errico
John D'Errico 2016년 3월 13일
편집: John D'Errico 2016년 3월 13일
Ok, I looked at your code. A serious MAJOR problem found.
You never finished writing the code. I'll list the pertinent lines of code:
% Backward substitution:
% perform on each vector b separately:
% Step B3:
disp('Gaussian elimination completed successfully');
fprintf('it needed %d row exchanges\n\n', counter);
Exactly where in there do you do the final steps?
Oh, by the way, there was a serious problem earlier in the code, but it will be non-fatal, MUCH of the time. Just serious.
When you compute the pivot element, you just test to see if it was zero. The idea behind pivoting is that you don't want to divide by a tiny number. So if your pivot element was 1e-16, the test will not look for another. Non-zero is non-zero after all.
The idea behind pivoting is to find the pivot element that is as LARGE as possible in magnitude. Then you divide by a big number. This lessens the errors in Gaussian elimination. It is why you use pivoting, because without pivoting, Gaussian elimination is not robust as an algorithm.
Perhaps the idea behind pivoting was missed by you, or perhaps that comes in your next class when that will be explained.

카테고리

Help CenterFile Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by