Question

In: Computer Science

MATLAB script Gaussian Elimination without pivoting, not working no matter what I try. So far my...

MATLAB script Gaussian Elimination without pivoting, not working no matter what I try.

So far my script is :

function [x] = myGauss( A, b )

n = size(A,1); % getting n
Ab = [A,b];      % produces the augmented matrix
x = zeros(n,1); % solution
fprintf('Augmented matrix \n')

%FORWARD ELIMINATION  

for k=1:n-1
    for i=k+1:n
        lambda = A(i,k)/A(k,k);
        for j=k+1:n
            A(i,j) = A(i,j) - lambda*A(k,j);
        end;
        b(i) = b(i) - lambda*b(i)
    end;
end;

%Backwards substitution

x(n) = b(n) / A(n,n);
for k = n-1:1
    for j = k+1: n
        sums = b(k) - A(k,j) * x(j);
    end
    x(k) = sums / A(k,k);
end

and to launch it I have:

%Question 1:
A = [2, -4, -1;
    1, -3, 1;
    3, -5, -3]

b = [1; 1; 1];

x = myGauss( A, b )

Any highly appreciated.

Solutions

Expert Solution

Corrected script:

function y=myyygauss(M, Y)
[m,n] = size (M);
D = [M Y];
for j = 1:n-1
for i = j+1:m
T = D(i,j)/D(j,j);
D(i,j:n+1) = D(i,j:n+1)-T*D(j,j:n+1);
end
end
x = zeros(m,1);
x(m) =D(m,n+1)/D(m,m);
for i = m-1:-1:1
x(i) = (D(i,n+1)-D(i,i+1:n)*x(i+1:n))/D(i,i);
end
y=x
end

To use the above script:

a1=[1 2 3;-4 5 6; -7 8 9];
a2=[10 20 30]';
a=myyygauss(a1,a2);

Output:

>> a
a =

0.00000
0.00000
3.33333

_____________________________________________________________

sample 2:

a1=[1 -2 -3;-4 5 6; -7 8 -9];
a2=[10 20 30]';
a=myyygauss(a1,a2);

output:

>> a
a =

-31.1111
-22.2222
1.1111

____________________________________________________________________________________

But for the given matrix A, the determinant value is equal to 0.Gauss elimination method can be applied only for linear set of equations. If the det ==0 , then the set of equations say that the system is non linear.

>> A = [2, -4, -1;
1, -3, 1;
3, -5, -3]
A =

2 -4 -1
1 -3 1
3 -5 -3

>> det(A)
ans = -8.8818e-16

This is almost equal to zero. Hence the solution cannot be obtained. But the script will work for all the linear set of equations.

Before applying gauss elimination method or any other method to find the solution of linear equations, check whether the determinant is zero or not.


Related Solutions

Implement Gaussian elimination(with partial pivoting) and backward substitu- tion in MATLAB. You need to submit your...
Implement Gaussian elimination(with partial pivoting) and backward substitu- tion in MATLAB. You need to submit your code on moodle page.
Can you explain in detail what Gaussian Elimination with pivoting is? and how is it different...
Can you explain in detail what Gaussian Elimination with pivoting is? and how is it different from Gaussian Elimination without pivoting?
The code following is what I have so far. It does not meet my requirements. My...
The code following is what I have so far. It does not meet my requirements. My problem is that while this program runs, it doesn't let the user execute the functions of addBook, isInList or compareLists to add, check, or compare. Please assist in correcting this issue. Thank you! Write a C++ program to implement a singly linked list of books. The book details should include the following: title, author, and ISBN. The program should include the following functions: addBook:...
Here is my C++ program so far. Is there anyway I can make it display an...
Here is my C++ program so far. Is there anyway I can make it display an error if the user enters a float? Thanks #include <iostream> using namespace std; // Creating a constant for the number of integers in the array const int size = 10; int main() { // Assigning literals to the varibles int a[size]; int sum=0; float avg; // For loop that will reiterate until all 10 integers are entered by the user for(int i=0; i<size; i++)...
Please try to type your solution for this question, so I can read it without a...
Please try to type your solution for this question, so I can read it without a problem. I truly appreciate you for typing in advance. The Question: An FBI survey shows that about 80% of all property crimes go unsolved. Suppose that in your town 3 such crimes are committed and they are each deemed independent of each other. X is the number of crimes will be solved in your town. Complete the table below for the probability mass function...
Please try to type your solution for this question, so I can read it without a...
Please try to type your solution for this question, so I can read it without a problem. I truly appreciate you for typing in advance. The Question: For some Mechanical Engineer students, data for 224 student’s GPAs in their first 4 semesters of college were compared using several predictors, namely HSM, HSS, HSE, SATM, and SATV. Here significant level α is 0.05. Then, the researcher fit a regression model and got the following results (intercept is included in the model):...
This is what I have so far. The out print I am looking for is Date...
This is what I have so far. The out print I am looking for is Date is 7/22/2020 New month: 9 New day: 5 New Year: 2020 Date is 9/5/2020 #include    class Date {    public:        Date::Date(int dateMonth, int dateDay, int dateYear)        month{dateMonth}, day{dateDay}, int dateYear}{}               //void displayDate();         //set month        void Date::setMonth(std::int dateMonth){            month = dateMonth;        }        //retrieve month   ...
Need solution for 3rd question I solved first part below is my answers so far. Really...
Need solution for 3rd question I solved first part below is my answers so far. Really need help on second question. Below is the Background, What I need to do, and the price data to start with. Any help with getting me started is appreciated.    Background The Book Emporium wants to price books to optimize profits. The spreadsheet for this homework has sales data on Harry Potter book 7. For each week, the Book Emporium varied prices on Harry...
So pretty much I need my code without the arrays, or lists. Please and thank you!...
So pretty much I need my code without the arrays, or lists. Please and thank you! Important: You may not use arrays, lists, or similar for your questions. This will be covered in the next module. The objective is to use conditionals in order to achieve the overall task. Checkpoint 3 is a continuation of the “Quiz” Programming Project. This module week, you will implement repetitive tasks in your program while using conditional and iteration statements in C#. Implement a...
How to schematize a diagnostic argument? This is what i have so far not sure if...
How to schematize a diagnostic argument? This is what i have so far not sure if its right, need help with this one in order to figure out rest of homework. ----------- IQ: Is drinking milk healthy? (5 items of Support TD or NTD) S1: S2: S3: S4: S5: C1: More than half of the population in north America are lactose intolerant meaning they cannot digest milk properly. C2: Article: https://milk.procon.org/
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT