Question

Write an advanced function (a program) in MATHCAD to perform Gauss-Jordan Elimination. Your program should be...

Write an advanced function (a program) in MATHCAD to perform Gauss-Jordan Elimination. Your program should be able to handle problems of any size. Remember that you MUST explain each and every line of code with comments. (Preferable with for loops)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

A=0;
x=0;
n=input('How many variables=');
disp('Enter the coefficients along with constants For instance if x+y+3z=-5 then enter 1 1 3 -5 each number followed by an enter not space');
for i=1:n
    for j=1:n+1
        A(i,j)=input('');
    end
end
%pivoting
for i=1:n-1
    for j=i+1:n
        if abs(A(j,i))>abs(A(i,i))
            T=A(j,:);
            A(j,:)=A(i,:);
            A(i,:)=T;
        end
    end
end
disp('After pivoting');
disp(A);
for k=1:n-1
    for i=k+1:n
        m=A(i,k)/A(k,k);
        for j=k:n+1
            A(i,j)=A(i,j)-m*A(k,j);
        end
    end
end
disp('Triangularize Form ');
disp(A);
          
if A(n,n)==0
    disp('No unique solution');
end
    x(n)=A(n,n+1)/A(n,n);
    for j=n-1:-1:1
        sum=0;
    for i=1:n
        sprintf('x%.0f=%.10f',i,x(i))
    end
          for i=1:n-j
            sum=sum+A(j,n+1-i)*x(n+1-i);
        end
        x(j)=(A(j,n+1)-sum)/A(j,j);
    end   

Add a comment
Know the answer?
Add Answer to:
Write an advanced function (a program) in MATHCAD to perform Gauss-Jordan Elimination. Your program should be...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT