More Matrices (and a site update)

I’ve added a function to determine the trace of a matrix, since even though it doesn’t come up that often, it does come up occasionally, and it only takes about thirty seconds to code.

		public static double trace(double[,] matrix)
		{
			int n = Convert.ToInt32(Math.Sqrt(matrix.Length));
			double trace = 0;
			for(int i = 0; i< n; i++)
				trace += matrix[i,i];
			return trace;
		}

You may be wondering about the square root part. C#’s Length function returns the total number of elements in a matrix.  Since we’re passing in a square matrix, taking the square root gives the number of rows/columns.  At some point I should add code to check that the matrix is indeed square and error out gracefully if it isn’t.

I’ve also upgraded the site to WordPress 2.7 and changed the theme to something nice and simple.  The 2.7 migration shouldn’t result in any appearance or functionality changes, but the admin section is much nicer now.

This entry was posted in Science and tagged , , . Bookmark the permalink.

One Response to More Matrices (and a site update)

  1. Pingback: LESLIE

Leave a Reply

Your email address will not be published. Required fields are marked *

*

*


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>