0% found this document useful (0 votes)
2 views

guideee

The document describes three methods for solving systems of linear equations: the Elimination Method, Cramer's Rule, and Gaussian Elimination. Each method includes steps for defining coefficient matrices, performing necessary calculations, and back substitution to find the values of the variables. The document provides detailed mathematical procedures and displays solutions for each method.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

guideee

The document describes three methods for solving systems of linear equations: the Elimination Method, Cramer's Rule, and Gaussian Elimination. Each method includes steps for defining coefficient matrices, performing necessary calculations, and back substitution to find the values of the variables. The document provides detailed mathematical procedures and displays solutions for each method.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

ELIMINATION METHOD (Where x,y,z = a,b,c)

// Step 1: Define the coefficients of the system

A = [5 8 -7; 2 12 -1; -8 5 12]; // Coefficient matrix

b = [8; 15; 5]; // Constants on the right-hand side

// Step 2: Eliminate x from equations 2 and 3 by subtracting appropriate

// multiples of the first row

mult21 = A(2,1) / A(1,1); // Multiplier to eliminate x in row 2

mult31 = A(3,1) / A(1,1); // Multiplier to eliminate x in row 3

// Subtract multiples of the first row from rows 2 and 3

A(2,:) = A(2,:) - mult21 * A(1,:);

b(2) = b(2) - mult21 * b(1);

A(3,:) = A(3,:) - mult31 * A(1,:);

b(3) = b(3) - mult31 * b(1);

// Step 3: Eliminate y from equation 3 by subtracting appropriate multiples of row 2

mult32 = A(3,2) / A(2,2);

A(3,:) = A(3,:) - mult32 * A(2,:);

b(3) = b(3) - mult32 * b(2);

// Step 4: Back substitution

z = b(3) / A(3,3);

y = (b(2) - A(2,3)* z) / A(2,2);

x = (b(1) - A(1,2) * y - A(1,3) *z) / A(1,1);

// Display the solution

disp("Solution using elimination method: ");

disp([x y z]);
CRAMERSRULE METHOD (Where x,y,z = a,b,c)

// Step 1: Define the coefficient matrix A and the constants vector b

A = [3 12 -4;22 -1 -4;1 -8 4]; // Coefficient matrix

b = [12; 9; 7]; // Constants on the right-hand side

// Step 2: Manually compute the 3x3 determinant of A

det_A = A(1,1)*(A(2,2)*A(3,3) - A(2,3)*A(3,2)) - A(1,2)*(A(2,1)*A(3,3) - A(2,3)*A(3,1)) +


A(1,3)*(A(2,1)*A(3,2) - A(2,2) * A(3,1));

// Step 3: Construct A_x by replacing the first column of A with b

A_x = A; // Copy matrix A

A_x(:,1) = b; // Replace the first column of A with b

// Step 4: Manually compute the determinant of A_x

det_Ax = A_x(1,1)*(A_x(2,2)*A_x(3,3) - A_x(2,3)*A_x(3,2))- A_x(1,2)*(A_x(2,1)*A_x(3,3) -


A_x(2,3)*A_x(3,1)) + A_x(1,3)*(A_x(2,1)*A_x(3,2) - A_x(2,2)*A_x(3,1));

// Step 5: Construct A_y by replacing the second column of A with b

A_y = A; // Copy matrix A

A_y(:,2) = b; // Replace the second column of A with b

// Step 6: Manually compute the determinant of A_y

det_Ay = A_y (1,1)*(A_y(2,2)*A_y(3,3) - A_y(2,3)*A_y(3,2)) - A_y(1,2)*(A_y(2,1)*A_y(3,3) -


A_y(2,3)*A_y(3,1)) + A_y(1,3)*(A_y(2,1)*A_y(3,2) - A_y(2,2)*A_y(3,1));

// Step 7: Construct A_z by replacing the third column of A with b

A_z = A; // Copy matrix A

A_z(:,3) = b; // Replace the third column of A with b

// Step 8: Manually compute the determinant of A_z

det_Az = A_z(1,1)*(A_z(2,2)*A_z(3,3) - A_z(2,3)*A_z(3,2)) - A_z(1,2)*(A_z(2,1)*A_z(3,3) -


A_z(2,3)*A_z(3,1)) + A_z(1,3)*(A_z(2,1)*A_z(3,2) - A_z(2,2)*A_z(3,1));
// Step 9: Apply Cramer's Rule to solve for x, y, and z

disp("A = "), disp(det_A);

disp("Ax = "), disp(det_Ax);

disp("Ay = "), disp(det_Ay);

disp("Az = "), disp(det_Az);

x = det_Ax / det_A;

y = det_Ay / det_A;

z = det_Az / det_A;

// Step 10: Display the solution

disp("Solution using Cramers Rule:");

disp("x = "), disp(x);

disp("y = "), disp(y);

disp("z = "), disp(z);

GAUSSIANELIMINATION METHOD (Where x,y,z = a,b,c)

// Step 1: Define the coefficient matrix and the constants

A = [16 0 6;8 -7 0;1 14 12]; // Coefficient matrix

b = [10; 18; -3]; // Constants on the right-hand side

// Combine A and b into an augmented matrix

augmented_matrix = [A, b];

disp("Augmented Matrix:")

disp(augmented_matrix);

// Step 2: Forward elimination process to convert into upper triangular form

for i = 1:2

for j = i+1:3

factor = augmented_matrix(j,i) / augmented_matrix(i,i);

augmented_matrix(j,:) = augmented_matrix(j,:) - factor * augmented_matrix(i,:);


disp("Augmented Matrix:")

disp(augmented_matrix);

end

end

// Step 3: Back substitution to find the values of z, y, and x

z = augmented_matrix(3,4) / augmented_matrix(3,3);

y = (augmented_matrix(2,4) - augmented_matrix (2,3) * z) / augmented_matrix(2,2);

x = (augmented_matrix(1,4) - augmented_matrix(1,2) * y - augmented_matrix(1,3) * z) /


augmented_matrix(1,1);

// Display the solution

disp("Solution using Gaussian Elimination:");

disp([x y z]);

You might also like