General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old January 11th, 2011, 07:07 PM
veronicak5678 veronicak5678 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2008
Posts: 3 veronicak5678 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 13 m 49 sec
Reputation Power: 0
Gaussian Elimination in Matlab

Sorry if I'm posting this in the wrong place. I am trying to write a Matlab program to perform Gaussian Elimination with Partial Pivoting. I getting bad results, but I can't see where my code deviates from the algorithm I'm using. I am not allowed to post a link, but this is the book with the steps I'm trying to follow:

http://books.google.com/books?id=wmcL0y2avuUC&pg=PA368&lpg=PA368&dq=gaussian+elimination+algorithm+6.2+numerical+an alysis&source=bl&ots=1esN2ZdIPZ&sig=jQkt8_9lM8CloVzy3vWz8vVxoR4&hl=en&ei=RvssTd_UD42usAOZ9ImbBw&sa=X&oi=book_result&ct=result&resnum=1&ved=0CBcQ6AEwAA#v=onepage&q&f=false

This is algorithm 6.2 which begins on page 362. Here is my code:

Code:
clear
A= [1 -1 2 -1 ; 2 -2 3 -3; 1 1 1 0; 1 -1 4 3 ]
[~,q]=size(A);
n=q-1;
x=zeros(n,1);
m=[n,q];
p=0;
nrow=ones(n,1);
ncopy = [1, q];
%-------------------------------Step 1
for i=1:n
    nrow(i,1)=i;
end
%------------------------------Step 2
for i=1:n-1
%-----------------------------Step 3
    maxval = 0;
    index=0;
    for j =i:n
        if abs(A(nrow(j),i))>maxval
            maxval=abs(A(nrow(j),i));
            index = j;
        end
    end
    p=index;
%-----------------------------Step 4
    if A(nrow(p),i) ==0
        display 'No!'
    end
%-----------------------------Step 5
    if  nrow(i,:)~=nrow(p,:)
        ncopy = nrow(i,:);
        nrow(i,:)=nrow(p,:);
        nrow(p,:)= ncopy;
    end
%------------------------------Step 6
    for j=i+1:n
%------------------------------Step 7
        m(nrow(j),i) =A(nrow(j),i)/A(nrow(i),i);
%------------------------------Step 8
        A(nrow(j),:) =A(nrow(j),:)- (m(nrow(j),i)*A(nrow(i),:));
    end
end
%------------------------------Step 9
if A(nrow(n),n)==0
    display 'No!'
end
%------------------------------Step 10
x(n,1)=A(nrow(n),q)/A(nrow(n),n);
%------------------------------Step 11
for i = n-1:-1:1
    sig=0;
    for j=i+1:n
        sig =sig + A(nrow(i),j)*x(j,1);
    end
    x(i,1) = (A(nrow(i),q) - sig)/A(nrow(i),i);
end
%-----------------------------Step 10
display ' A is'
disp (A)
display ' x is'
disp (x)

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > Gaussian Elimination in Matlab


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap