Last active
October 19, 2017 15:05
-
-
Save pureexe/1dc94cc357847fcac2e700eff8f9b7f8 to your computer and use it in GitHub Desktop.
my gaussian_elimination
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function X = gaussian_elimination(A,B) | |
| N = length(A); | |
| R = [A B]; | |
| for i = 1:N | |
| [val,pos] = max(abs(R(i:N,i))); | |
| R([pos+i-1 i],:) = R([i pos+i-1],:); | |
| R(i,:) = R(i,:) / R(i,i); | |
| for j = i+1:N | |
| m = R(j,i)/R(i,i); | |
| R(j,:) = R(j,:) - (m*R(i,:)); | |
| end | |
| end | |
| % backward subsitution | |
| for i = N:-1:1 | |
| for j = i-1:-1:1 | |
| m = R(j,i)/R(i,i); | |
| R(j,:) = R(j,:) - (m*R(i,:)); | |
| end | |
| end | |
| X = R(:,N+1); | |
| end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment