Question

In: Advanced Math

Write your own routine to solve a system of n linear equations and n unknowns using...

Write your own routine to solve a system of n linear equations and n unknowns using the LU decomposition. Input should take an augmented matrix and the number of equations n. Output should be the augmented matrix. L and U matrices and the solution. Also compare your results to those of Matlab’s built in LU decomposition. Use your code to solve the systems given as (a) and (b) below: a) 3a − 2b + c = −3, a − 4b + 2c + 2d = 6, a + 3b = 5, −3a + 7b + 9c + d = 5

Solutions

Expert Solution

MATLAB Script (Run it as a script, not from command window):

close all
clear
clc

A = [3 -2 1 0;
1 -4 2 2;
1 3 0 0;
-3 7 9 1];
b = [-3 6 5 5]';
n = size(A,1);
Ag = [A b];
fprintf('Using custom function:\n---------------------------------------------\n')
[Ag,L,U,x] = customLU(n, Ag)
fprintf('\nUsing inbuilt lu() function:\n---------------------------------------------\n')
[l,u] = lu(A);
x = u\(l\b)

function [Ag_,L,U,x] = customLU(n, Ag)
Ag_ = Ag;
A = Ag(:,1:end-1);
b = Ag(:,end);
L = eye(n);
for i = 1:1:n
L(i+1:n, i) = A(i+1:n, i) / A(i, i);
for j = i+1:1:n
A(j, :) = A(j, :) - L(j, i)*A(i, :);
end
end
U = A;
x = U\(L\b);
end

Output:


Related Solutions

how to solve a system of 4 equations with 4 unknowns?
how to solve a system of 4 equations with 4 unknowns?
Write a function to solve a system of linear equations of the form Ax= b using...
Write a function to solve a system of linear equations of the form Ax= b using the iterative Gauss-Seidel method. You are free to use any basic MATLAB operation to implement the algorithm (i.e. you may use any combination of loops, indexing, math, etc.), but avoid “built-in” solution methods — you would not be allowed to use the GaussSeidel function if such a function existed. The function must also test for a number of possible issues. If an issue is...
Write a python program that can solve system of linear equations in three variables using input...
Write a python program that can solve system of linear equations in three variables using input function. Paste your program in a word document or notepad. Note that I am using pycharm. please use a not really complex codes, thanks
Write a system of equations that represents the situation. Then, solve the system using the inverse...
Write a system of equations that represents the situation. Then, solve the system using the inverse of a matrix. Students were asked to bring their favorite fruit to class. 93% of the fruits consisted of bananas, apples, and oranges. If oranges were twice as popular as bananas, and apples were 19 percentage points less popular than bananas, what are the percentages of each individual fruit?
1) Solve the system of linear equations, using the Gauss-Jordan elimination method. (If there is no...
1) Solve the system of linear equations, using the Gauss-Jordan elimination method. (If there is no solution, enter NO SOLUTION. If there are infinitely many solutions, express your answer in terms of the parameters t and/or s.) 3y + 2z = 1 2x − y − 3z = 4 2x + 2y − z = 5 (x, y, z) = 2) Solve the system of linear equations, using the Gauss-Jordan elimination method. (If there is no solution, enter NO SOLUTION....
Write the second order differential equation as a system of two linear differential equations then solve...
Write the second order differential equation as a system of two linear differential equations then solve it. y" + y' - 6y = e^-3t y(0) =0   y'(0)=0
Solve the system of linear equations using partial pivoting. 144a1 + 12a2 + a3 = 279.2...
Solve the system of linear equations using partial pivoting. 144a1 + 12a2 + a3 = 279.2 64a1 + 8a2 + a3 = 177.2 25a1 + 5a2 + a3 = 106.8
Write the augmented matrix for the following system of linear equations. Solve the equation (x,y,z) by...
Write the augmented matrix for the following system of linear equations. Solve the equation (x,y,z) by row reduction. x+3y-2z=5 3x+5y+6z=7 2x+4y+3z=8
When using Gaussian elimination to solve a system of linear equations, how can you recognize that...
When using Gaussian elimination to solve a system of linear equations, how can you recognize that the system has no solution?
Describe at least three distinct ways to solve a system of equations using linear algebra. (Distinct...
Describe at least three distinct ways to solve a system of equations using linear algebra. (Distinct means that the approach is fundamentally different.) Be specific and detailed using linear algebra vocabulary. It might be helpful to pick an example problem and illustrate each of the three methods.   Suppose T1 and T2 are linear transformations from Rn to Rn. Let T(x) = T2(T1(x)) The responses should be very clear like you are writing instructions to someone who doesn’t know the process.  ...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT