Math Help Forum

Math Help Forum Feed Site Feed

Go Back   Math Help Forum > Math Resources > Mathematics Software Discussion
Reply
 
Thread Tools Display Modes
  #1  
Old October 17th, 2009, 02:13 PM
Newbie
 
Join Date: Oct 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
shobii is on a distinguished road
Default Upper triangularization method (AX=B)

Function X = uptrbk(A,B)
%Input – A is an N x N nonsingular matrix
% B is an N x 1 matrix
% Output – X is an N x 1 matrix containing the solution to AX=B
% Initialize X and the temporary storage matrix C

[N N] = size(A);
X=zeros(N,1);
C=zeros(1,N+1);

%Form the augmented matrix: Aug=[A|B]

Aug=[A B];
for p=1 : N-1

%partial pivoting for column p
[Y,j] = max(abs(Aug(p:N,p)));

%Interchange row p and j
C=Aug(p,: );
Aug(p,: ) = Aug (j+p-1,: );
Aug(j+p-1,: )=C;
If Aug(p,p)==0
‘A was singular. No unique solution’
Break
end

% Eliminating process for column p
for k=p+1:N
m=Aug(k,p)/Aug(p,p);
Aug(k,p:N+1)=Aug(k,p:N+1)-m*Aug(p,p:N+1);
end
end

%Back substitution on [U|Y]
X=backsub(Aug(1:N,1:N),Aug(1:N,N+1));




The above program is to construct the solution to AX=B by reducing the augmented matrix [A B] to upper triangularization method and then performing back substitution.

I am trying to modify this program so that it will solve M linear systems with the same coefficient matrix A but different column matrices B . The M linear systems look like AX1 = B1 AX2 = B2 ...... AXm=Bm
(1 , 2 and m are in subscript)


Please help!!!
Reply With Quote
Advertisement
 
  #2  
Old October 17th, 2009, 04:06 PM
CaptainBlack's Avatar
Grand Panjandrum
 
Join Date: Nov 2005
Location: South of England
Posts: 11,379
Country:
Thanks: 667
Thanked 3,619 Times in 2,916 Posts
CaptainBlack has a reputation beyond reputeCaptainBlack has a reputation beyond reputeCaptainBlack has a reputation beyond reputeCaptainBlack has a reputation beyond reputeCaptainBlack has a reputation beyond reputeCaptainBlack has a reputation beyond reputeCaptainBlack has a reputation beyond reputeCaptainBlack has a reputation beyond reputeCaptainBlack has a reputation beyond reputeCaptainBlack has a reputation beyond reputeCaptainBlack has a reputation beyond repute
Default

Quote:
Originally Posted by shobii View Post
Function X = uptrbk(A,B)
%Input – A is an N x N nonsingular matrix
% B is an N x 1 matrix
% Output – X is an N x 1 matrix containing the solution to AX=B
% Initialize X and the temporary storage matrix C

[N N] = size(A);
X=zeros(N,1);
C=zeros(1,N+1);

%Form the augmented matrix: Aug=[A|B]

Aug=[A B];
for p=1 : N-1

%partial pivoting for column p
[Y,j] = max(abs(Aug(p:N,p)));

%Interchange row p and j
C=Aug(p,: );
Aug(p,: ) = Aug (j+p-1,: );
Aug(j+p-1,: )=C;
If Aug(p,p)==0
‘A was singular. No unique solution’
Break
end

% Eliminating process for column p
for k=p+1:N
m=Aug(k,p)/Aug(p,p);
Aug(k,p:N+1)=Aug(k,p:N+1)-m*Aug(p,p:N+1);
end
end

%Back substitution on [U|Y]
X=backsub(Aug(1:N,1:N),Aug(1:N,N+1));




The above program is to construct the solution to AX=B by reducing the augmented matrix [A B] to upper triangularization method and then performing back substitution.

I am trying to modify this program so that it will solve M linear systems with the same coefficient matrix A but different column matrices B . The M linear systems look like AX1 = B1 AX2 = B2 ...... AXm=Bm
(1 , 2 and m are in subscript)


Please help!!!
My guess is it should work as it is, just make B the matrix of the column vectors, all right you will have to modify the back substitution to do back sub for all the columns of augmentation (this can be done by looping over the extra columns, though the back substitution function might just work if you give it all the augmentation cols at once).

CB
__________________
Truth does not change because it is, or is not, believed by a majority of the people.

Giordano Bruno
Reply With Quote
Reply

Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off
Forum Jump


All times are GMT -7. The time now is 12:16 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 ©2008, Crawlability, Inc.
©2005 - 2009 Math Help Forum


Math Help Forum is a community of maths forums with an emphasis on maths help in all levels of mathematics.
Register to post your math questions or just hang out and try some of our math games or visit the arcade.