Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Gaussian Elimination by Partial Pivoting

Subject: Gaussian Elimination by Partial Pivoting

From: Ashley Daly

Date: 11 Feb, 2009 16:05:19

Message: 1 of 5

Question:
Let A be the nxn matrix with elements a_ij = -1 for i > j, a_ii = a_in = 1, 1 <=i<=n, and zero everywhere else. Let b be a random vector. Solve the linear system Ax = b by Gaussian elimination with partial pivoting.

Use functions tril, eye, and ones to generate A.
Generate b with rand.
No loops.



Now, I'm horrible with MATLAB. I've tried reading about it and everything, but I never seem to be able to get it exactly how my teacher wants it. Can anyone help me set this up? Do you actually have to factor A = PLU yourself, or is there something in MATLAB that does this? Also, when i > j, how can I note those entries? And, this statement: a_ii = a_in = 1, does that mean we have 1's on the diagonal and in the last column? Sorry, guys, I'm just always completely lost on this kind of stuff.

Subject: Gaussian Elimination by Partial Pivoting

From: Ashley Daly

Date: 11 Feb, 2009 16:41:01

Message: 2 of 5

"Ashley Daly" <kl0vis3000@hotmail.com> wrote in message <gmusvv$b2u$1@fred.mathworks.com>...
> Question:
> Let A be the nxn matrix with elements a_ij = -1 for i > j, a_ii = a_in = 1, 1 <=i<=n, and zero everywhere else. Let b be a random vector. Solve the linear system Ax = b by Gaussian elimination with partial pivoting.
>
> Use functions tril, eye, and ones to generate A.
> Generate b with rand.
> No loops.
>
>
>
> Now, I'm horrible with MATLAB. I've tried reading about it and everything, but I never seem to be able to get it exactly how my teacher wants it. Can anyone help me set this up? Do you actually have to factor A = PLU yourself, or is there something in MATLAB that does this? Also, I'm trying to generate A to begin with and the only thing I'm having trouble with is getting 1's in the last column (which I think I'm supposed to do since a_in = 1). Can anyone help me out with create a matrix with 1's in the last column? Sorry, guys, I'm just always completely lost on this kind of stuff.

Subject: Gaussian Elimination by Partial Pivoting

From: Steven Lord

Date: 11 Feb, 2009 18:54:21

Message: 3 of 5


"Ashley Daly" <kl0vis3000@hotmail.com> wrote in message
news:gmusvv$b2u$1@fred.mathworks.com...
> Question:
> Let A be the nxn matrix with elements a_ij = -1 for i > j, a_ii = a_in =
> 1, 1 <=i<=n, and zero everywhere else. Let b be a random vector. Solve the
> linear system Ax = b by Gaussian elimination with partial pivoting.
>
> Use functions tril, eye, and ones to generate A.
> Generate b with rand.
> No loops.
>
>
>
> Now, I'm horrible with MATLAB. I've tried reading about it and everything,
> but I never seem to be able to get it exactly how my teacher wants it. Can
> anyone help me set this up?

Post the code that shows how far you've gotten and describe specifically
where you're having trouble and you'll get suggestions on how to get past
that trouble spot.

> Do you actually have to factor A = PLU yourself, or is there something in
> MATLAB that does this?

There's something in MATLAB to generate L, U, and P such that P*A = L*U.
What's the name of that factorization? When you search the documentation
for that name, what function do you find to perform that factorization?

> Also, when i > j, how can I note those entries? And, this statement: a_ii
> = a_in = 1, does that mean we have 1's on the diagonal and in the last
> column?

Take n = 5 and write out (on paper, not in MATLAB) what A should look like
using those rules for the elements.

Look at the M-file help for the TRIL, EYE, and ONES functions. Try using
them to create matrices the same size as A. Can you figure out how to
combine them to create a matrix that looks very similar to A?

Once you've done that, I'll give you the last step:

    A(:, n) = 1;

[This sets the elements in A in all rows (from the colon) and column n to
1.]

> Sorry, guys, I'm just always completely lost on this kind of stuff.

Everybody (well, except for Cleve, but he's a bit of a special case) started
out as newbie MATLAB users. With time and practice, you'll get better at
it.

--
Steve Lord
slord@mathworks.com

Subject: Gaussian Elimination by Partial Pivoting

From: Ashley Daly

Date: 11 Feb, 2009 21:00:19

Message: 4 of 5

Steven, thank you very much for your reponse. Unfortunately, I won't have access to MATLAB again til Friday. Before I read your message, I actually did create a matrix by hand to recreate A for a certain order n, so I think I know what it should look like. Where I'm running into trouble is creating a matrix with 1's in the last column (or maybe even if the last column with a 0 in the a_nn spot since that spot is already taken care of by the diagonal matrix?). I created something like G = eye(n,n) to get a matrix with 1's on the diagonal, and a C = tril(-ones,(n,n),-1) to get a matrix with -1's where I think they should go, but I'm still unsure how to create an nxn matrix with 1's in the nth column.

Another thing, the PA = LU factorization, by that do you just mean Gaussian Elimination with Partial Pivoting (or maybe LU factorization)? Although I do not have access to MATLAB right now, I did read somewhere that there is a command
[L,U,P] = lu(A) which should give me these matrices (once I have A of course). I will definitely have to try that out when I can get back into MATLAB in a couple days. Again, thanks for your help.

Subject: Gaussian Elimination by Partial Pivoting

From: Selliah (Ram) Ramachchandran

Date: 20 Feb, 2009 10:10:20

Message: 5 of 5

"Ashley Daly" <kl0vis3000@hotmail.com> wrote in message <gmve93

Hello Ashley,

Just one little infor if you have access to a library near you look for a book called "Applied Numerical Analysis (7th Edition)by Curtis F. Gerald (Author), Patrick O. Wheatley (Author). I have one in loan from our library 4th Edition of the same. You will have the answers.

THE CODE Below is not mine its belong to: Miguel D. B. 10/03/2006




" function [A,t]=elimgauss03(A)
%[B,t]=elimgauss03(A) eleminaci?n de Gauss-Jordan por pivoteo parcial
%t: elapsed time

%Miguel D. B. 10/03/2006
tic;
s=size(A);
a=min(s);
for ii=1:a
   %Pivoteo parcial: se toma siempre como pivote fila que tiene el mayor n?mero para dividir por ?l, lo cual minimiza el error en la divisi?n
   [t,r]=max(abs(A(ii:end,ii)));
   t=A(r+ii-1,:);
   A(r+ii-1,:)=A(ii,:);
   A(ii,:)=t;
   %Eliminaci?n
   A(ii,[1:ii-1 ii+1:end])= A(ii,[1:ii-1 ii+1:end])/A(ii,ii);
   A(ii,ii)=1;
   ss=A(ii,[ii+1:end]);
   for jj=[1:ii-1 ii+1:a]
      A(jj,[ii+1:end])= A(jj,[ii+1:end])-A(jj,ii).*ss;
   end
   A([1:ii-1 ii+1:end],ii)=0;
end
t=toc;





Hope it would be a help.

Kind regards,
   "
$jvc$1@fred.mathworks.com>...
> Steven, thank you very much for your reponse. Unfortunately, I won't have access to MATLAB again til Friday. Before I read your message, I actually did create a matrix by hand to recreate A for a certain order n, so I think I know what it should look like. Where I'm running into trouble is creating a matrix with 1's in the last column (or maybe even if the last column with a 0 in the a_nn spot since that spot is already taken care of by the diagonal matrix?). I created something like G = eye(n,n) to get a matrix with 1's on the diagonal, and a C = tril(-ones,(n,n),-1) to get a matrix with -1's where I think they should go, but I'm still unsure how to create an nxn matrix with 1's in the nth column.
>
> Another thing, the PA = LU factorization, by that do you just mean Gaussian Elimination with Partial Pivoting (or maybe LU factorization)? Although I do not have access to MATLAB right now, I did read somewhere that there is a command
> [L,U,P] = lu(A) which should give me these matrices (once I have A of course). I will definitely have to try that out when I can get back into MATLAB in a couple days. Again, thanks for your help.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us