JustPaste
HomeCategoriesAboutDonateContactTerms of UsePrivacy Policy
JustPaste

Free online notepad — write and share instantly

Navigate

  • Home
  • Timeline
  • Categories

Info

  • About
  • Donate
  • Contact

Legal

  • Terms of Use
  • Privacy Policy

© 2026 JustPaste.app. All rights reserved.

Made with ♥ by JustPaste

Gauss elimination method | JustPaste.app
14 days ago2 views
👨‍💻Programming

Gauss elimination method

clc;        % Clear command window
clear;      % Clear variables

A = [2 1 -1;
    -3 -1 2;
    -2 1 2];     % Coefficient matrix

b = [8; -11; -3];   % Constant vector

aug = [A b];   % Augmented matrix
n = 3;

% Forward Elimination
for i = 1:n-1
    for j = i+1:n
        factor = aug(j,i) / aug(i,i);   % Find factor
        aug(j,:) = aug(j,:) - factor * aug(i,:); % Row operation
    end
end

% Back Substitution
x = zeros(n,1);

for i = n:-1:1
    sum = 0;
    for j = i+1:n
        sum = sum + aug(i,j)*x(j);
    end
    x(i) = (aug(i,end) - sum) / aug(i,i);
end

fprintf('x = %f\n', x(1));
fprintf('y = %f\n', x(2));
fprintf('z = %f\n', x(3));

⚠️Content was pasted as plain text and auto-formatted as a code block. Use the Code Block button in the editor for proper formatting.

← Back to timeline