determinant of magic square in matlab 2010a

  • Permalink
  • submit to reddit
  • Email
  • Follow


I am newer to MATLAB. 
I followed getting started, and calculate the det of 4*4 magic square, it gives finite value instead of 0. Why?

>> A=magic(4);
>> det(A)

ans =

 -1.4495e-012
0
Reply Wei 4/26/2010 8:27:05 AM

See related articles to this posting


"Wei " <weitong@ustc.edu> wrote in message <hr3iop$mtm$1@fred.mathworks.com>...
> I am newer to MATLAB. 
> I followed getting started, and calculate the det of 4*4 magic square, it gives finite value instead of 0. Why?
> 
> >> A=magic(4);
> >> det(A)
> 
> ans =
> 
>  -1.4495e-012

Considering the magnitude of the magic square components this is numerically equivalent to zero. Its due to a rounding error somewhere.
0
Reply Thomas 4/26/2010 8:59:05 AM

Yes, I know it  (-1.4495e-012)  is somehow "zero".
But, I tried some previous version, e.g., 2009a, 7.1, and 6.1, and they all gave "0" answer as the Help says.
So, I wish to know why it happens to 2010a, and where can I change it.

Thanks.

"Thomas Britton" <benjamin.britton@materials.ox.ac.remove.uk> wrote in message <hr3kkp$nt4$1@fred.mathworks.com>...
> "Wei " <weitong@ustc.edu> wrote in message <hr3iop$mtm$1@fred.mathworks.com>...
> > I am newer to MATLAB. 
> > I followed getting started, and calculate the det of 4*4 magic square, it gives finite value instead of 0. Why?
> > 
> > >> A=magic(4);
> > >> det(A)
> > 
> > ans =
> > 
> >  -1.4495e-012
> 
> Considering the magnitude of the magic square components this is numerically equivalent to zero. Its due to a rounding error somewhere.
0
Reply Wei 4/26/2010 9:18:04 AM

"Wei " <weitong@ustc.edu> wrote in message <hr3loc$5sa$1@fred.mathworks.com>...
> Yes, I know it  (-1.4495e-012)  is somehow "zero".
> But, I tried some previous version, e.g., 2009a, 7.1, and 6.1, and they all gave "0" answer as the Help says.
> So, I wish to know why it happens to 2010a, and where can I change it.

Sigh. The determinant did not change, nor can you
make it magically become zero again.

This matrix is numerically singular. In fact, it is truly
singular. Of course, testing for singularity using the
determinant is a fool's game, best reserved for
textbooks written by authors who live in a fool's
world. The determinant is a terrible way to do that
test. Here I will define a fool's world as someplace
where the people understand (or care) nothing
about floating point arithmetic.

Computation of the determinant of a matrix is a
nasty thing for large order matrices, at least if you
do it using the textbook way. This will get impossibly
inefficient for very reasonable size matrices. So
MATLAB uses a better scheme. One such scheme is
to recognize that the determinant is simply the
product of the eigenvalues of the matrix. Thus

  M = magic(4);
ans =
  -5.5968e-12

Note that this is a slightly different "zero" than
det gives. This is because det actually uses a better
scheme. det uses the product of the diagonal
elements of U, taken from the LU factorization
(with pivoting) of your matrix.

[L,U,P] = lu(M);
U
U =
           16            2            3           13
            0         13.5        14.25        -2.25
            0            0      -1.8889       5.6667
            0            0            0   3.5527e-15

prod(diag(U))
ans =
  -1.4495e-12

Note that the result is not a true "zero". Get
used to living in the numerical world of floating
point arithmetic.

John
0
Reply John 4/26/2010 9:56:07 AM

Thank you very much for exhaustive explanation of numerical algorithm.

Why do the previous versions give exact "zero"? Is the newest 2010a using a different algorithm for calculating determinant?

"John D'Errico" <woodchips@rochester.rr.com> wrote in message <hr3nvn$44$1@fred.mathworks.com>...
> "Wei " <weitong@ustc.edu> wrote in message <hr3loc$5sa$1@fred.mathworks.com>...
> > Yes, I know it  (-1.4495e-012)  is somehow "zero".
> > But, I tried some previous version, e.g., 2009a, 7.1, and 6.1, and they all gave "0" answer as the Help says.
> > So, I wish to know why it happens to 2010a, and where can I change it.
> 
> Sigh. The determinant did not change, nor can you
> make it magically become zero again.
> 
> This matrix is numerically singular. In fact, it is truly
> singular. Of course, testing for singularity using the
> determinant is a fool's game, best reserved for
> textbooks written by authors who live in a fool's
> world. The determinant is a terrible way to do that
> test. Here I will define a fool's world as someplace
> where the people understand (or care) nothing
> about floating point arithmetic.
> 
> Computation of the determinant of a matrix is a
> nasty thing for large order matrices, at least if you
> do it using the textbook way. This will get impossibly
> inefficient for very reasonable size matrices. So
> MATLAB uses a better scheme. One such scheme is
> to recognize that the determinant is simply the
> product of the eigenvalues of the matrix. Thus
> 
>   M = magic(4);
> ans =
>   -5.5968e-12
> 
> Note that this is a slightly different "zero" than
> det gives. This is because det actually uses a better
> scheme. det uses the product of the diagonal
> elements of U, taken from the LU factorization
> (with pivoting) of your matrix.
> 
> [L,U,P] = lu(M);
> U
> U =
>            16            2            3           13
>             0         13.5        14.25        -2.25
>             0            0      -1.8889       5.6667
>             0            0            0   3.5527e-15
> 
> prod(diag(U))
> ans =
>   -1.4495e-12
> 
> Note that the result is not a true "zero". Get
> used to living in the numerical world of floating
> point arithmetic.
> 
> John
0
Reply Wei 4/27/2010 12:18:04 AM
comp.soft-sys.matlab 203726 articles. 536 followers. Post

4 Replies
423 Views

Similar Articles

[PageSpeed] 7


  • Permalink
  • submit to reddit
  • Email
  • Follow


Reply:

Similar Artilces:

Excel error 429 when running Matlab magic square example from Matlab builder
Hi, I was working with the Matlab builder magic square example (can be found in matlab builder users guide) in Matlab to compile and build m-files into COM objects for Excel. Essentially, the building process creates a .bas file which can be imported into Visual Basic Editor in MS Excel. In the VB code, the Matlab functions essentially end up being wrapped up inside COM objects and you can invoke these functions in the excel spreadsheet. The example works successfully for output to a single cell. For outputing to multiple cells simultaneously, the code changes a little as a macros are in...

Problems with matlab builder for java
hi all iam trying to use the matlab builder for java trial version i configured everything as mentioned in the example and documentation....i get the following error message in the build process... i am using the following version : matlab 7.4.0, matlab builder for java11, matlab compiler 46 Build output( 2007-04-10 10:42:51). mcc -F 'C:\Program Files\MATLAB\R2007a\javabuilder_examples \magic_square\magicsquare.prj' ************************************************errormessage************************************************* mcc -W java:magicsquare,magic -d C:\Program Files\MA...

Function eval
Hello, i'm a braziliam master's degree student in applied mathematics. I found different results working with the eval function in versions 7.0 and 7.10 of Matlab, could you explain these differences? I managed to circumvent the problem with small changes in my algorithm, but I wonder what changed. I thank you for your cooperation. Adriano Verdério On Jun 23, 7:31=A0am, "Adriano Verd=E9rio" <adri...@gmail.com> wrote: > Hello, i'm a braziliam master's degree student in applied mathematics. > I found different results working with the eval fu...

magic square
I would like to know if the 6x6 magic square can be done using the backtracking algorithm and if so how long would it take. I found a link online that does this pretty quick though: www.faust.fr.bw.schule.de/mhb/backtrack/mag6en.htm I've found some information on the siamese method and is this related to the backtracking algorithm? j_depp_99@yahoo.com wrote: > I would like to know if the 6x6 magic square can be done using the > backtracking algorithm and if so how long would it take. I found a > link online that does this pretty quick though: > > www.faust.fr.bw.schule.d...

magic square~ what should i do
can any one tell me?? what should i do before i strating wirtitng the magic square programe jyck91@gmail.com said: > can any one tell me?? what should i do before i strating wirtitng the > magic square programe Do some research into magic squares, and then do some more research into programming. -- Richard Heathfield "Usenet is a strange place" - dmr 29/7/1999 http://www.cpax.org.uk email: rjh at the above domain, - www. At about the time of 4/5/2007 9:07 AM, jyck91@gmail.com stated the following: > can any one tell me?? what should i do before i strating wirtit...

How to import geometry of COMSOL to pdetool box MATLAB? or how to draw square with rounded corners in matlab
Dear Friends, I am trying to solve partial differential equation using FEM method. For that I need x and y coordinates at each nodes of triangles. I can get that from matlab pdetool box. But I am not able to draw my geometry (square with rounded corners). It is easy to draw that in COMSOL which I want to import it to matlab. Can anyone help me with this? Thanks in advance. With best regards ...

diaboloc magic square
I'm trying to create a function that succeeds if it is a diabolic magic square (4x4). My logic is, get the sum of the rows, columns, diagonals of the matrix then compare each list if its = 34. I have a function to return the rows. row([A, B, C, D, _, _, _, _, _, _, _, _, _, _, _, _ |[]], [A, B, C, D]). and so fort.. I also have a function to add the integers on a list addup(list, X). I'm thinking of creating another program, call my row function, and my addup() together, then compare X (sum), if it's equal to 34. I have this. my_test(row(List1, R)) :- addup(R, X), X =:= 34, ...

cost of matlab 2010a
Hello, i want to ask about the cost of matlab student version 2010a including the new wavelet toolbox. Thanx On Feb 6, 5:31=A0am, "talal hammouri" <tala...@yahoo.com> wrote: > =A0Hello, > > =A0i want to ask about the cost of matlab =A0student version 2010a includ= ing =A0the new wavelet toolbox. > > =A0Thanx ---------------------------------------------------------------------------= ----------------------------- OK. So (to state the obvious) call up the Mathworks and ask them. Or ask them via the web: http://www.mathworks.com/company/aboutus/contact_...

MATLAB square wave
Hello smart people...I'm a CS major who has to take CPET lab. There is one lab project that is well out of the scope of my understaning...it could have just as well been written in Chinese. Here's what the problem asks: Question: http://reflectionsvideo.com/ebay/capture.JPG We have already used (and I guess are supposed to modify) this code: clear; clf; t = 0:0.001:1; % Time vector e = sin(2*pi*60*t); figure(1), stem(e(1:30)); figure(2), stem(e(1:30)), grid on; figure(3), plot(t,e), grid on, figure(4), plot(t(1:50),e(1:50)), grid on; figure(5), plot(t(1:100),e(1:100...

Magic wand for Matlab
I found a magic wand tool (written by Daniel Leo Lau) on Matlab Central File Exchange, I use the updated version for v6.5 (by Yoram Tal). It works fine on Windows XP but on Linux I get the error message - "One or more output arguments not assigned during call to 'magicwand1'". I'm a novice at Linux. Help me, please... ...

square root in matlab ?????????
Hi please can you help me How i can solve this problem ? write a matlab programe to compute the square root using the algorithm of equation y(n)=x(n)-y^2(n-1)+y(n-1) and show that the output y(n) of this system for an input x(n)=a�(n) with y(-1)=1 convergs to a^1/2 as n?? plot the error as a function of n for several different values of a. and how i can compute the squre root of anumber a with value greater than one for this problem ???? please help me Really you are a genteel,generous and a magnanimous man Thanks alot my names soso I am a girl from Jordan(this country located in Middle east...

Square wave Matlab
hi on the net i found how to make a square wave and i got this code and it works sw=a*(sin(2*pi*f*t)>0)-a/2 but i dont understand how the >0 makes it a square wave because if i take it away use like this sin(2*pi*f*t) then as expected it will make standard sin wave . I dont understand what the >0 does to make it a square. Can any one help James Bond The thing is that the >0 is a condition that returns a 1 or a 0 based on if it is true or false (or vice versa, you can check on that). If you type a command like 1>0 in the command line, you can see the answer. So basically, you...

Time Frame for MATLAB 2010a
When is the new release of MATLAB 2010a going to be? I hope it is Febuary, and most importantly I hope it works with Excel 2007 very well ade77 wrote: > When is the new release of MATLAB 2010a going to be? I hope it is > Febuary, and most importantly I hope it works with Excel 2007 very well "Those who know, can't say; and those who say, don't know". In other words, release dates are proprietary Mathworks information and anyone you encounter here that actually knows the planned release date would not be authorized to give it out. For what it is worth...

diaboloc magic square #2
I'm trying to create a function that succeeds if it is a diabolic magic square (4x4). My logic is, get the sum of the rows, columns, diagonals of the matrix then compare each list if its = 34. I have a function to return the rows. row([A, B, C, D, _, _, _, _, _, _, _, _, _, _, _, _ |[]], [A, B, C, D]). and so fort.. I also have a function to add the integers on a list addup(list, X). I'm thinking of creating another program, call my row function, and my addup() together, then compare X (sum), if it's equal to 34. I have this. my_test(row(List1, R)) :- addup(R, X), X =:= 34, ...

R Square or coefficient of determination
Hello, I need to creat a vector of *R square*, in that size of predicors or 'X' is 100-by-9 and size of responses is 100-by-6. Therefore, I would expect that the size of *R square* should be 56-by-1. I suppose that the function regress each column of 'X' vs. each column of 'Y' sperately. Please let me know which function I could use to compute this *R squre*. RSQUARE=fun(x,y) ; What is fun? Thanks, Frank Frank Sabouri wrote on 25-Oct-10 20:58 ... > Hello, > > I need to creat a vector of *R square*, in that size of predicors or 'X'...

matlab precision determinant problem
I have the following program %*************************** format compact; format short g; clear; clc; L = 140; J = 77; Jm = 10540; G = 0.8*10^8; d = L/3; for i=1:500000 omegan=1.+0.0001*i; a(1,1) = ((omegan^2)*(Jm/(G*J))*d^2)-2; a(1,2) = 2; a(1,3) = 0; a(1,4) = 0; a(2,1) = 1; a(2,2) = ((omegan^2)*(Jm/(G*J))*d^2)-2; a(2,3) = 1; a(2,4) = 0; a(3,1) = 0; a(3,2) = 1; a(3,3) = ((omegan^2)*(Jm/(G*J))*d^2)-2; a(3,4) = 1; a(4,1) = 0; a(4,2) = 0; a(4,3) = 2; a(4,4) = ((omegan^2)*(Jm/(G*J))*d^2)-2; if(abs(det(a))<1E-10) sprintf('omegan= %8.3f det= %8.3f',omegan,det...

Testing an array for magic squares
function log=csvMagic(file1) x=csvread(file1); s=size(x); sum1=sum(x); if s(1)==s(2)&&sum(sum1)/length(x)==sum(diag(x))&&sum(all(x))==length(x) log=true; else log=false; end end This reads a file with a matrix of numbers and determines if it's a magic square. What I've written here works for some but not all. I used a conditional to find if a few big important characteristics were present, but obviously this doesn't catch everything and some non-magic squares slip past. How would I write this differently to sum ALL rows, columns, and diagonals as well as find ...

jbuilder tutorial magic square
I am facing problems compiling the magic square in the command line its in step 9 of the tutorial. javac -classpath ;C:\Program Files\MATLAB\R2006b\toolbox\javabuilder\jar\javabuilder.jar;C:\Program Files\MATLAB\R2006b\work\MagicSquareExample\magicsquare\distrib\magics quare.jar getmagic.java i tried typing the above command in but the command line keeps showing me this error msg javac: invalid flag: Files\MATLAB\R2006b\toolbox\javabuilder\jar\javabuilder.jar m Usage: javac <options> <source files> use -help for a list of possible options I tried the whole night but still cant ...

Magic square : Help with my homework
This is a multi-part message in MIME format. ------=mesnews_0_1116091355 Content-Type: text/plain; charset="iso-8859-15" Content-Transfer-Encoding: quoted-printable Hello! Yes it is a homework. We've been asked to make a generic magic squares generator (N x N). I've done a 3 x 3 generator, but whenever it must deal with an arbitrary number of things I am stuck!! I am not asking for a full solution but some hints on data structure and how to loop through data... Thank you ------=mesnews_0_1116091355 Content-Type: text/html Content-Transfer-Encoding: ...

How to plot square wave in Matlab?
Hi, i have done analysis on simple sine wave x[n]=sin(2*pi*fo*n*(Ts)) , and by perfoming fft(x) I can get the frequency content of the signal..Now, i need to do spectral analysis on some other waveforms, such as square/rectangular wave..thats why i need to know the programming code or the Function Equation for square wave.. I have no idea how to write coding to represent a square wave, hope you can help me..thankyou.. In Matlab Help-> Signal Processing toolbox->waveform generation only show x=Square(t); however i fail to generate a square plot with this 1 line of coding, actually ...

Matlab 2010a dir cmd
I found this to be kind of interesting. I was trying to find all the subdirectories in my current directory when I used dir *. In my 2009a and previous version of matlab it always returned just the directories. Now it is returning everything. I tried a dos('dir *.') and that worked as expected, but I can't use the output. Anyone know if this is a bug in 2010a, or am I doing something incorrectly. Thanks! "Derik " <derik.alles+matlab@gmail.com> wrote in message <hsf7bc$f7m$1@fred.mathworks.com>... > I found this to be kind of interesting. I was tryi...

Matlab 2010a PPPoe conflict
When I am trying to start Matlab 2010a and my PPPoe connection is active Matlab takes 50% CPU and doesn't start...This is under windows 7 X64. When I remove the ethernet cable and start Matlab everything works fine. Is this due licensing checking or something? On 10-09-15 02:50 PM, Lennart wrote: > When I am trying to start Matlab 2010a and my PPPoe connection is active > Matlab takes 50% CPU and doesn't start...This is under windows 7 X64. > When I remove the ethernet cable and start Matlab everything works fine. > Is this due licensing checking or something? ...

Determinant of a non-square matrix?
Is there a determinant of a non-square matrix? >> det ([sym('a'), sym('b')]) ans = a Dear Joerg, > Is there a determinant of a non-square matrix? > >> det ([sym('a'), sym('b')]) > ans = > a How do you define "determinant of a non-square matrix" ? As far as I know and after asking wikipedia I have the impression, that "determinant" are defined for square matrices only. Jan "Joerg Buchholz" <buchholz@hs-bremen.de> wrote in message <i0h9lp$3t6$1@fred.mathworks.com>... >...

imresize not work in our matlab 2010a
Hi all, The imresize is not work in our matlab 2010a and i don't know why my question how can i install such function from a pervious version like mat lab 2008a or is it possible to install it from 2010a again. Thank you "talal hammouri" <talalah@yahoo.com> wrote in message <i33ju0$es9$1@fred.mathworks.com>... > Hi all, > > The imresize is not work in our matlab 2010a and i don't know why > my question how can i install such function from a pervious version like mat lab 2008a or is it possible to install it from 2010a...