http://www.mathworks.com/matlabcentral/newsreader/view_thread/270380
MATLAB Central Newsreader  What does this syntax mean
Feed for thread: What does this syntax mean
enus
©19942015 by MathWorks, Inc.
webmaster@mathworks.com
MATLAB Central Newsreader
http://blogs.law.harvard.edu/tech/rss
60
MathWorks
http://www.mathworks.com/images/membrane_icon.gif

Fri, 15 Jan 2010 21:15:22 +0000
What does this syntax mean
http://www.mathworks.com/matlabcentral/newsreader/view_thread/270380#708803
Ender
I am trying to use MATLAB to do LU factorization. I originally tried to use the MATLAB function to do the factorization, but the answers that MATLAB gave me utilizing the [L,U] = lu(A) command, but MATLAB does not give me the correct answer. I am not sure why.<br>
<br>
So I am currently trying decipher a code that I found on the internet. The internet code gives the correct answer, however I cannot understand some of the syntax. Could someone tell me what "m~=n " means. The code before this line reads:<br>
<br>
A=input('Enter the square matrix to be factorized ');<br>
[m,n]=size(A);<br>
<br>
Ender

Fri, 15 Jan 2010 21:29:05 +0000
Re: What does this syntax mean
http://www.mathworks.com/matlabcentral/newsreader/view_thread/270380#708807
Oleg Komarov
"Ender " <br>
> I am trying to use MATLAB to do LU factorization. I originally tried to use the <br>
> MATLAB function to do the factorization, but the answers that MATLAB gave me <br>
> utilizing the [L,U] = lu(A) command, but MATLAB does not give me the correct <br>
> answer. I am not sure why.<br>
<br>
What is the expected answer and which was matlab's answer?<br>
<br>
> <br>
> So I am currently trying decipher a code that I found on the internet. The internet code gives the correct answer, however I cannot understand some of the syntax. Could someone tell me what "m~=n " means. The code before this line reads:<br>
> <br>
> A=input('Enter the square matrix to be factorized ');<br>
> [m,n]=size(A);<br>
> <br>
> Ender<br>
<br>
help logical operator<br>
<br>
Oleg

Fri, 15 Jan 2010 21:36:19 +0000
Re: What does this syntax mean
http://www.mathworks.com/matlabcentral/newsreader/view_thread/270380#708810
us
"Ender " <jr147@msstate.edu> wrote in message <hiqlta$25v$1@fred.mathworks.com>...<br>
> I am trying to use MATLAB to do LU factorization. I originally tried to use the MATLAB function to do the factorization, but the answers that MATLAB gave me utilizing the [L,U] = lu(A) command, but MATLAB does not give me the correct answer. I am not sure why.<br>
> <br>
> So I am currently trying decipher a code that I found on the internet. The internet code gives the correct answer, however I cannot understand some of the syntax. Could someone tell me what "m~=n " means. The code before this line reads:<br>
> <br>
> A=input('Enter the square matrix to be factorized ');<br>
> [m,n]=size(A);<br>
> <br>
> Ender<br>
<br>
well,...<br>
 the syntax<br>
m~=n<br>
returns LOGICAL TRUE if M is NOT EQUAL N<br>
returns LOGICAL FALSE if M is EQUAL N<br>
<br>
[m,n]=size(magic(3));<br>
tf=m~=n<br>
% tf = 0 % < false<br>
[m,n]=size(rand(3,4));<br>
tf=m~=n<br>
% tf = 1 % < true<br>
<br>
note: TF typically is used in conditional expressions, eg,<br>
IF/ELSEIF/ELSE<br>
WHILE<br>
SWITCH/CASE<br>
<br>
us

Fri, 15 Jan 2010 21:43:45 +0000
Re: What does this syntax mean
http://www.mathworks.com/matlabcentral/newsreader/view_thread/270380#708811
Bobby Cheng
Can you send the matrix here? Not sure what you mean by "MATLAB does not <br>
give me the correct answer".<br>
<br>
Bob.<br>
<br>
"us " <us@neurol.unizh.ch> wrote in message <br>
news:hiqn4j$joj$1@fred.mathworks.com...<br>
> "Ender " <jr147@msstate.edu> wrote in message <br>
> <hiqlta$25v$1@fred.mathworks.com>...<br>
>> I am trying to use MATLAB to do LU factorization. I originally tried to <br>
>> use the MATLAB function to do the factorization, but the answers that <br>
>> MATLAB gave me utilizing the [L,U] = lu(A) command, but MATLAB does not <br>
>> give me the correct answer. I am not sure why.<br>
>><br>
>> So I am currently trying decipher a code that I found on the internet. <br>
>> The internet code gives the correct answer, however I cannot understand <br>
>> some of the syntax. Could someone tell me what "m~=n " means. The code <br>
>> before this line reads:<br>
>><br>
>> A=input('Enter the square matrix to be factorized ');<br>
>> [m,n]=size(A);<br>
>><br>
>> Ender<br>
><br>
> well,...<br>
>  the syntax<br>
> m~=n<br>
> returns LOGICAL TRUE if M is NOT EQUAL N<br>
> returns LOGICAL FALSE if M is EQUAL N<br>
><br>
> [m,n]=size(magic(3));<br>
> tf=m~=n<br>
> % tf = 0 % < false<br>
> [m,n]=size(rand(3,4));<br>
> tf=m~=n<br>
> % tf = 1 % < true<br>
><br>
> note: TF typically is used in conditional expressions, eg,<br>
> IF/ELSEIF/ELSE<br>
> WHILE<br>
> SWITCH/CASE<br>
><br>
> us<br>
>

Sun, 17 Jan 2010 19:21:04 +0000
Re: What does this syntax mean
http://www.mathworks.com/matlabcentral/newsreader/view_thread/270380#709066
Ender
MATLAB does not give me the same answer that is in the back of the Numerical Analysis book that I am using. The Matrix A is:<br>
<br>
A=[0,2,1;1,1,2;1,1,4]<br>
<br>
The answer is:<br>
<br>
L = [1,0,0;1.5,1,0;1.5,1,1] & U = [2,1,1;0,4.5,7.5;0,0,4]<br>
<br>
When using the MATLAb LU Factorization code [L,U] = lu(A)<br>
I do not get this answer. I don't know why. However there is a code that I found on the internet:<br>
<br>
<a href="http://www.mathworks.com/matlabcentral/fileexchange/7779lufactorization">http://www.mathworks.com/matlabcentral/fileexchange/7779lufactorization</a><br>
bydoolittlesmethod<br>
<br>
That gives me the answer that I am looking for. I just don't totally understand what the code is doing to get the right answer.<br>
<br>
<br>
"Bobby Cheng" <bcheng@mathworks.com> wrote in message <hiqnih$h83$1@fred.mathworks.com>...<br>
> Can you send the matrix here? Not sure what you mean by "MATLAB does not <br>
> give me the correct answer".<br>
> <br>
> Bob.<br>
> <br>
> "us " <us@neurol.unizh.ch> wrote in message <br>
> news:hiqn4j$joj$1@fred.mathworks.com...<br>
> > "Ender " <jr147@msstate.edu> wrote in message <br>
> > <hiqlta$25v$1@fred.mathworks.com>...<br>
> >> I am trying to use MATLAB to do LU factorization. I originally tried to <br>
> >> use the MATLAB function to do the factorization, but the answers that <br>
> >> MATLAB gave me utilizing the [L,U] = lu(A) command, but MATLAB does not <br>
> >> give me the correct answer. I am not sure why.<br>
> >><br>
> >> So I am currently trying decipher a code that I found on the internet. <br>
> >> The internet code gives the correct answer, however I cannot understand <br>
> >> some of the syntax. Could someone tell me what "m~=n " means. The code <br>
> >> before this line reads:<br>
> >><br>
> >> A=input('Enter the square matrix to be factorized ');<br>
> >> [m,n]=size(A);<br>
> >><br>
> >> Ender<br>
> ><br>
> > well,...<br>
> >  the syntax<br>
> > m~=n<br>
> > returns LOGICAL TRUE if M is NOT EQUAL N<br>
> > returns LOGICAL FALSE if M is EQUAL N<br>
> ><br>
> > [m,n]=size(magic(3));<br>
> > tf=m~=n<br>
> > % tf = 0 % < false<br>
> > [m,n]=size(rand(3,4));<br>
> > tf=m~=n<br>
> > % tf = 1 % < true<br>
> ><br>
> > note: TF typically is used in conditional expressions, eg,<br>
> > IF/ELSEIF/ELSE<br>
> > WHILE<br>
> > SWITCH/CASE<br>
> ><br>
> > us<br>
> > <br>
>

Mon, 18 Jan 2010 00:41:03 +0000
Re: What does this syntax mean
http://www.mathworks.com/matlabcentral/newsreader/view_thread/270380#709107
Phil Goddard
lu factorizations aren't unique so getting a different result doesn't necessarily mean that either implementation is wrong.<br>
<br>
But I would also point out that the L and U that you assert are correct do not reproduce your A.<br>
<br>
>> L = [1,0,0;1.5,1,0;1.5,1,1], U = [2,1,1;0,4.5,7.5;0,0,4], L*U<br>
L =<br>
1.0000 0 0<br>
1.5000 1.0000 0<br>
1.5000 1.0000 1.0000<br>
U =<br>
2.0000 1.0000 1.0000<br>
0 4.5000 7.5000<br>
0 0 4.0000<br>
ans =<br>
2 1 1<br>
3 3 9<br>
3 3 5<br>
<br>
Phil.

Mon, 18 Jan 2010 03:58:13 +0000
Re: What does this syntax mean
http://www.mathworks.com/matlabcentral/newsreader/view_thread/270380#709109
Steven Lord
<br>
"Ender " <jr147@msstate.edu> wrote in message <br>
news:hivnv0$nq5$1@fred.mathworks.com...<br>
> MATLAB does not give me the same answer that is in the back of the <br>
> Numerical Analysis book that I am using. The Matrix A is:<br>
><br>
> A=[0,2,1;1,1,2;1,1,4]<br>
><br>
> The answer is:<br>
><br>
> L = [1,0,0;1.5,1,0;1.5,1,1] & U = [2,1,1;0,4.5,7.5;0,0,4]<br>
><br>
> When using the MATLAb LU Factorization code [L,U] = lu(A)<br>
> I do not get this answer. I don't know why.<br>
<br>
When I use LU in MATLAB, I too receive a different answer than the one you <br>
cited above. When I check the output of the LU call in MATLAB (by computing <br>
L*U) I receive your original matrix. When I check the product of the two <br>
matrices you gave above, I do not receive your original matrix.<br>
<br>
It's entirely possible that your numerical analysis textbook may have the <br>
wrong answer, or it could be that you read the answer to the wrong problem.<br>
<br>
 <br>
Steve Lord<br>
slord@mathworks.com<br>
comp.softsys.matlab (CSSM) FAQ: <a href="http://matlabwiki.mathworks.com/MATLAB_FAQ">http://matlabwiki.mathworks.com/MATLAB_FAQ</a>

Tue, 19 Jan 2010 16:35:20 +0000
Re: What does this syntax mean
http://www.mathworks.com/matlabcentral/newsreader/view_thread/270380#709550
Ender
It is entirely possible that I mixed up the problems. I will check again than get back to you.<br>
<br>
Ender<br>
<br>
<br>
"Steven Lord" <slord@mathworks.com> wrote in message <hj0m8i$f9q$1@fred.mathworks.com>...<br>
> <br>
> "Ender " <jr147@msstate.edu> wrote in message <br>
> news:hivnv0$nq5$1@fred.mathworks.com...<br>
> > MATLAB does not give me the same answer that is in the back of the <br>
> > Numerical Analysis book that I am using. The Matrix A is:<br>
> ><br>
> > A=[0,2,1;1,1,2;1,1,4]<br>
> ><br>
> > The answer is:<br>
> ><br>
> > L = [1,0,0;1.5,1,0;1.5,1,1] & U = [2,1,1;0,4.5,7.5;0,0,4]<br>
> ><br>
> > When using the MATLAb LU Factorization code [L,U] = lu(A)<br>
> > I do not get this answer. I don't know why.<br>
> <br>
> When I use LU in MATLAB, I too receive a different answer than the one you <br>
> cited above. When I check the output of the LU call in MATLAB (by computing <br>
> L*U) I receive your original matrix. When I check the product of the two <br>
> matrices you gave above, I do not receive your original matrix.<br>
> <br>
> It's entirely possible that your numerical analysis textbook may have the <br>
> wrong answer, or it could be that you read the answer to the wrong problem.<br>
> <br>
>  <br>
> Steve Lord<br>
> slord@mathworks.com<br>
> comp.softsys.matlab (CSSM) FAQ: <a href="http://matlabwiki.mathworks.com/MATLAB_FAQ">http://matlabwiki.mathworks.com/MATLAB_FAQ</a> <br>
>

Wed, 20 Jan 2010 17:43:04 +0000
Re: What does this syntax mean
http://www.mathworks.com/matlabcentral/newsreader/view_thread/270380#709905
Ender
I did make a mistake. I put the wrong value of A<br>
<br>
A is:<br>
A=[2 ,1 ,1; 3 ,3 ,9; 3 ,3 ,5]<br>
<br>
The answer should still be:<br>
L = [1,0,0;1.5,1,0;1.5,1,1] U = [2,1,1;0,4.5,7.5;0,0,4]<br>
<br>
If you multiply L*U you will get the same answer for A.<br>
<br>
However, when I use [L,U]=lu(A)<br>
<br>
I do not get the same result for L & U.<br>
<br>
The link for this program "Doolittle.m" does give the correct answer with my original value of A. The link is:<br>
<a href="http://www.mathworks.com/matlabcentral/fileexchange/7779lufactorizationbydoolittlesmethod">http://www.mathworks.com/matlabcentral/fileexchange/7779lufactorizationbydoolittlesmethod</a><br>
<br>
I do not know why the MATLAB code does not produce the same result. How can I make the MATLAB code output the answer that I am looking for.<br>
<br>
Ender<br>
<br>
"Ender " <jr147@msstate.edu> wrote in message <hj4n08$kme$1@fred.mathworks.com>...<br>
> It is entirely possible that I mixed up the problems. I will check again than get back to you.<br>
> <br>
> Ender<br>
> <br>
> <br>
> "Steven Lord" <slord@mathworks.com> wrote in message <hj0m8i$f9q$1@fred.mathworks.com>...<br>
> > <br>
> > "Ender " <jr147@msstate.edu> wrote in message <br>
> > news:hivnv0$nq5$1@fred.mathworks.com...<br>
> > > MATLAB does not give me the same answer that is in the back of the <br>
> > > Numerical Analysis book that I am using. The Matrix A is:<br>
> > ><br>
> > > A=[0,2,1;1,1,2;1,1,4]<br>
> > ><br>
> > > The answer is:<br>
> > ><br>
> > > L = [1,0,0;1.5,1,0;1.5,1,1] & U = [2,1,1;0,4.5,7.5;0,0,4]<br>
> > ><br>
> > > When using the MATLAb LU Factorization code [L,U] = lu(A)<br>
> > > I do not get this answer. I don't know why.<br>
> > <br>
> > When I use LU in MATLAB, I too receive a different answer than the one you <br>
> > cited above. When I check the output of the LU call in MATLAB (by computing <br>
> > L*U) I receive your original matrix. When I check the product of the two <br>
> > matrices you gave above, I do not receive your original matrix.<br>
> > <br>
> > It's entirely possible that your numerical analysis textbook may have the <br>
> > wrong answer, or it could be that you read the answer to the wrong problem.<br>
> > <br>
> >  <br>
> > Steve Lord<br>
> > slord@mathworks.com<br>
> > comp.softsys.matlab (CSSM) FAQ: <a href="http://matlabwiki.mathworks.com/MATLAB_FAQ">http://matlabwiki.mathworks.com/MATLAB_FAQ</a> <br>
> >

Thu, 21 Jan 2010 03:41:08 +0000
Re: What does this syntax mean
http://www.mathworks.com/matlabcentral/newsreader/view_thread/270380#710066
Phil Goddard
<br>
The lu algorithm used by MATLAB for a full matrix uses partial pivoting, which the Doolittle algorithm does not, hence the difference in results.<br>
(You'd need to look at the references near the end of the help for the lu function to see the specifics of the pivoting.)<br>
<br>
It seems that you can only turn pivoting off when doing an lu on a sparse matrix, so you could (rather inefficiently) do the following:<br>
<br>
>> [l,u] = lu(sparse(A),0); %the 0 specifies not to pivot<br>
>> L = full(l)<br>
>> U = full(u)<br>
<br>
to get the U and L that you seek.<br>
<br>
Phil.