determinant of magic square in matlab 2010a

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
Wei
4/26/2010 8:27:05 AM
comp.soft-sys.matlab 206921 articles. 560 followers. lunamoonmoon (258) is leader. Post Follow

4 Replies
495 Views

Similar Articles

[PageSpeed] 41
"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
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
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
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
Wei
4/27/2010 12:18:04 AM
Reply:
Similar Artilces:

Bugs in Matlab Robotics Toolbox R6 ????
Hi guys, I am currently using the version 6 of your toolbox. I understand there is a bug for version 7. I wonder if the bug applies to version 6 as well. From the version 7 website it is written: "There is a bad bug with rne() for the case with friction and gear ratio greater than 1 (eg. the default puma560) model. The friction torque is too big by a factor of the gear ratio. This problem exists in both the MEX and M file versions. This zip file contains 3 replacement files, unzip it in the Robot Toolbox root directory. If you use the MEX file then you'll have to recompil...

errors in using matlab
Hi, I met a problem with error message saying "Invalid MEX-file '/root/2008b/bin/spm5/spm_slice_vol.mexglx': /root/2008b/bin/spm5/spm_slice_vol.mexglx: symbol mxGetNumberOfDimensions, version libmx.INTERNAL not defined in file libmx.so with link time reference." I tried to search the reason, but found no solution. Does anyone have any idea? I'm totally lost. The matlab version is 2008b. Thank you in advance! Lin ...

matlab functions and structures
Hi, I am wondering if it is legal to return a structure from a matlab function. Also, is it allowed to take as input to a function a matlab structure. I would appreciate some examples if it is possible to do so. Thanks. Majid Example: In file test1.m: function test1 clc; inputStruct.v1 = 42; inputStruct.v2 = 69 outputStruct = MakeStruct(inputStruct) return; function outputStr = MakeStruct(inputStr) outputStr.Value1 = 10 * inputStr.v1; outputStr.Value2 = 10 * inputStr.v2; return; "wm m" <wm.do.not.use@yahoo.com> wr...

Is this possible, area of a sheetmetal part (square area)
I know that if you click on a face, and use the measure tool, SolidWorks will give you the area of that face. If the part has a hole or multiple holes in, this area isnt calcualted. What I need though is the square area of the part. In the example image below, the hole in the center would most likely be scrapped, unless someone nested a small part in that area (which doesnt happen much here). Is there a way to get this value automatically? Macro maybe? http://img.photobucket.com/albums/v154/3eleven/SolidWorks/sheetmetal.jpg "SW Monkey" <google311.50.spydermonkey@spamgourme...

Linux is power squared
Linux is power squared ---------------------- The thing about GNU/Linux and open source I like most is the entire ecosystem is power squared. Doing something requires tools, and if they are free and readily available, then time taken to complete a task is reduced by the square of the number of tools. Linux easily has more than double the number of readily available tools that are free which reduce time scales for doing a project to a quarter and less than any competing OS. A few days ago, I was doing some embedded project and got bored with looking through reams of output. Then I thought, ...

Determine If Object Exist
I have a script that will set the focus to a particular input box. I want the script to check to see if the input box exist also. I'm receiving the following error: 'document.ScheduleForm.txtGrossPayroll99' is null or not an object. The txtGrossPayroll99 is a field that does not exist. I've hard-coded this name into the script to see if it is working correctly. I'm using the OnLoad event inside the <Body> tag to execute this function. var formInUse = false; function setFocus() { if ((!formInUse) && (typeof(document.ScheduleForm.txtGrossPayroll99) != "...

How to determine true sender of message
Hello Is there a way to look at the message header and determine the true sender of an email message. Is it the "Message-ID:"? Or is it the "X-UIDL:" Is there a source that explains all aspects of the message header? Thanks cdoc wrote: > Hello > Is there a way to look at the message header and determine the true > sender of an email message. > Is it the "Message-ID:"? > Or is it the "X-UIDL:" > Is there a source that explains all aspects of the message header? > Thanks The only thing one can determine is the true source (provide...

Determine if a directory is currently used as a mount point
Hello, I can't seem to find a simple solution to this seemingly simple problem. (I'm using Linux, in case there are no portable solutions.) I need to determine whether a directory is currently used as a mount point. (Because I need to run fsck on the underlying device, and running fsck on a mounted file system is not safe.) http://man7.org/linux/man-pages/man8/e2fsck.8.html On Linux, rmdir returns EBUSY when its argument "is currently used as a mount point, or is the root directory of the calling process." http://man7.org/linux/man-pages/man2/rmdir.2....

send/receive data via ethernet in matlab
Hi, I have to be able to read and receive data through an Ethernet port from and to a FPGA. This data is supposed to be just streams of number. I´ve seen the code given in this url: http://www.mathworks.com/matlabcentral/fileexchange/27290-collect-and-plot-data-from-a-tcpip-server-in-real-time And I have some questions.. about the IP address, can I set the one I prefer? and, how to send the information I have just received without doing anything with it? Hope anyone can help me. Thanks in advance Greetings, Guillermo. ...

Matlab ignores subfunction
I have a GUI that uses a fairly complex Buttondownfcn for one object. Instead of putting it all inside of one sting, I decided to give the whole procedure a name and call it as function at buttondown. As long as I save this as a seperate file, it works fine. As soon as I include it in the main function file, as a subfunction, Matlab reports: '??? Undefined function or variable 'track_on'. ??? Error while evaluating figure WindowButtonDownFcn.' Any ideas? In order to give you a more complete idea of what's going on, the whole script looks something like this: function o...

How to determine whether an expression equals to zero
Hi all. I have the following data type: data Expr = Literal Integer | Add Expr Expr -- x + y | Multipy Expr Expr -- x*y | Power Expr Expr -- x^y It represents an expression, which can consist of signed integer literals (arbitrary size), and operators: addition, multiplication, exponentiation. Semantically, this expression may denote a complex number. If an exponentiation is ambiguous, let it represent a complex number with a minimal non-negative argument. For instance, Power (Literal (-1)) (Power (Literal 2) (Literal (-1))) represents I (the imaginary unit), not (-I). One can see...

Running Flowmaster from Matlab
I work for a company that has both matlab and flowmaster, and I am wondering if there is a way to get matlab to run flowmaster (similar to the way excel can run matlab). According to matlab's website, simulink will run flowmaster (which means matlab should be able to as well) but there is no explanation of how to make that happen. I would prefer to avoid simulink if possible; I am more famaliar with matlab coding. Does anyone have any examples of running flowmaster through matlab? Is there an add-on required to do this? How do I know if I have that add-on? Thanks. ...

How to determine if a window is maximized ?
Hi, I didn't have found a function like IsMaximized in wxWindow class documentation. Is there a way how to do this ? Thanks, Lothar Sorry, have overseen wxToplevelWindow :-( ...

TCP/IP how to determine which process uses what IP-port?
Hello! How do I determine/show which processes is currently using what IP-port (TCP and UDP)? The Alphaserver is running OpenVMS 7.3.2 wiht HP TCP/IP Services 5.4. Regards Martin Hi ! ucx sho dev sho dev /full Martin Eismann wrote: > Hello! > > How do I determine/show which processes is currently using what > IP-port (TCP and UDP)? The Alphaserver is running OpenVMS 7.3.2 wiht > HP TCP/IP Services 5.4. > > Regards > Martin > -- + WBR, OpenVMS [Sys|Net] HardWorker .................................+ Delta Telecom Inc., NMT-450i, IMT-MC-450(CDMA2000) cellular ...

how to determine
Hi there, I have projected a number of surface points onto a plane in real space. My intention is to determine if the individual points are either convex/concave locally. May I know how to test them?? I try to use the 3x3 determinants since I know the cord. of points on the plane but gives me wrong outcome.What should do? thanks :) julia julia <joy_julia446@yahoo.com> wrote: > I have projected a number of surface points onto a plane in real > space. My intention is to determine if the individual points are > either convex/concave locally. That doesn't really make much ...

on using matlab to plot stock charts
Hi, I am interested in using matlab to plot stock charts. Free charts are everywhere and matlab has a financial tool box, but I am just interested in knowing how to do this using basic matlab plot functions. Here is a desciption of a stock chart: For each trading day, we have four trading prices [open high low close]. When charting, a thin vertical bar is generated at the specific trading day with "high" and "low" as its extremes, "close" and "open" are plotted as ticks to the right side and the left side of the bar, respectively. The task is to plot...

Is it possible for a matlab to have forks or threads?
I need to write a program where MATLAB is always in a loop looking for an event to occur. At the same time, other program execution must occur. Is this possible? -brian Brian wrote: > > > I need to write a program where MATLAB is always in a loop looking > for an > event to occur. At the same time, other program execution must > occur. Is > this possible? Yes. In our application, Matlab forks and then execs to start a child program. Then the two communicate on a frequent basis. Under Windows we do something similar, only we use a spawn function instead. - Stev...

Determine Rise
Is their any possibility to determine the rise time and the other characteristic control values out of a simulink model ? The LTI Viewer offer many options for systems in form of zpk,tf and ss systems, but I can't find a possibility to investigate the results of my simulink simulation! Thanks Thomas "Thomas Weingarten" <T.Weingarten@web.de> wrote in message news:i40g2i$2l6$1@fred.mathworks.com... > Is their any possibility to determine the rise time and the other > characteristic control values out of a simulink model ? > The LTI Viewer offer many...

Passing Data into the MATLAB environment
I have external software that I'd like to combine with MATLAB. I can successfully call a non-GUI version of MATLAB that'll execute whatever operations I want then send them back into the code. But what I'd really like to do is have a full-blown version of MATLAB running and just tell it to wait for data from the external program. Once that data arrives I'd then have all those variables in my workspace that I could play with. I suppose I could use the disk as an intermediary but that seems clunky to me and I'd have to go tell MATLAB to execute. I'd much rather it sit an...

determinant
hi, i need to solve this determinant; det(150000-150w^2 0 -195000;0 150000-150w^2 243750;-195000 243750 15649593,75-16900w^2)=0 from this determinant , i got this equation if it's true: -380250000(w^2)^3+1,11262*10^12*(w^2)^2-3,65634*10^14*(w^2)+3,375*10^17=0 and finally i got 3 roots as shown below, 1= 2691,2767 2= 117,3728+562,156i 3= 117,3728-15677i according to me, it's supposed to be found 3 reel roots but 2 of them were imaginary. i think something went wrong... could anyone help me please? On 6/7/2012 6:54 AM, K wrote: > hi, > > i need ...

Add more color levels in matlab contour #2
Dear friends I have to plot CONTOUR plot in MATLAB using contourf but by default it will show few color levels to plot or display the contour. I want to plot the same with more color level. Can you please give me some idea about this. Thanks Amlan "Amlan Datta Chowdhury" <amlanforyou@gmail.com> wrote in message news:lq0htr$stn$1@newscl01ah.mathworks.com... > Dear friends > > I have to plot CONTOUR plot in MATLAB using contourf but by default it > will show few color levels to plot or display the contour. I want to plot > the same with more ...

determine when imrect is changed
I have an image routine that grabs a frame of camera data and displays it with imshow(). I use imrect() to highlight a region of interest for processing. I wan the user to be able to move or resize this box. Without putting a wait() function inside my loop, how can my process keep running but if someone changes the size or location of the box, be able to update those parameters in the code? I mean when someone clicks on the rectangle on the image, and move the box, what event/method, etc... can used to update the x1, x2,y1,y2 parameters? My pseudo code: figure while(1) % Grab im from ca...

determine if DB is in a DataGuard config #2
Is there a value that can be queried to absolutely determine if a database is in a DataGuard config? I see a few things in v$database that would *IF* it were not the primary, OR if it were the primary *AND* managed by the DG Broker. But what if it were the primary and NOT manged by the DG Broker? ...

print (fh, '-dpng', ...) MATLAB 2008b
I create my figure handle as: fh = figure('Position', [10,100,1200,800]); ....then do various plotting operations.... followed by: set(gcf,'PaperPositionMode','auto'); hgsave(fh,filename); printf(fh,'-dpng', [filename, '.png']); Worked like a charm always everywhere with 2007b but now with 2008b some of the figure's xlabel position are incorrectly positioned so they overlap the xaxis tic labels. huh? I don't understand and I really need this feature working otherwise saving out all the plots by hand will take forever. Anyone else out the...

How to control the color of a single cell in a uicontrol of table in matlab?
I want to change the color of the text or the background of a specific cell of a uitable. How can I make it? ...