Data Visualization - MATLAB Contest

cotton.jpg

The top map is voting patterns in the 2008 election– the bottom map is cotton production in 1860… Image Courtesy of Pin the Tail

Is there something fishy here? Whether or not you agree with the correlation you see, this data visualization presented a new perspective in looking at the data. As Edward Tufte writes:

“At their best, graphics are instruments for reasoning about quantitative information. Often the most effective way to deescribe, explore, and summarize a set of numbers is to look at pictures of those numbers.”

Not inspired yet? Check out the following:
Continue Reading »

delicious bookmark StumbleUpon technorati Digg reddit icon rss icon

Monday Math Madness #29: Clock Angle Problem

mmm

This is a cross post by Sol Lederman from http://wildaboutmath.com/:

The Problem Statement

I call this one the “mother of all clock angle problems.” Some of you may have run into those problems where you have to figure out the angle between the two hands of a clock at weird times. Well, I took that problem as a starting point and added a twist to it.

Consider a 12-hour analog clock with two hands and a round face. Consider the angle between the two hands at any given time and, when the angle between the hands is not 180 degrees, take the smaller of the two angles. Thus, at 12:00 the angle between the two hands is 0 degrees. At 3:00 and at 9:00 it’s 90 degrees.

If we me measure the angle between the two hands at each of the 61 consecutive minutes between 12:00 and 1:00 inclusively, what is the sum of those 61 angles?

Remember to show your work.

Rules for the Contest

1. Email your answers with solutions to mondaymathmadness at gmail dot com.
2. Only one entry per person.
3. Each person may only win one prize per 12 month period. But, do submit your solutions even if you are not eligible.
4. Your answer must be explained. You must show your work! Wild About Math! and Blinkdagger will be the final judges on whether an answer was properly explained or not.
5. The deadline to submit answers is Tuesday, April 7, 12:01AM, Pacific Time. (That’s Tuesday morning, not Tuesday night.) Do a Google search for “time California” to know what the current Pacific Time is.)
6. The winner will be chosen randomly from all timely well-explained and correct submissions, using a random number generator.
7. The winner will be announced Friday, April 10, 2009.
8. The winner (or winners) will receive a Rubik’s Revolution or a $10 gift certificate to Amazon.com or $10 USD via PayPal. For those of you who don’t want a prize I’ll donate $10 to your favorite charity.
9. Comments for this post should only be used to clarify the problem. Please do not discuss ANY potential solutions.
10. I may post names and website/blog links for people submitting timely correct well-explained solutions. I’m more likely to post your name if your solution is unique.

delicious bookmark StumbleUpon technorati Digg reddit icon rss icon

Monday Math Madness #28 Winner - Dropping MacBooks From Very High Places

MMM #28 Winner

mmmwin.jpg

The winner for this edition of MMM is Sue VanHattum. I thought this was a pretty fun problem. I didn’t arrive at the correct answer until a couple of faulty tries. Thanks for everyone who submitted!

We got some really cool explanations, and a sweet diagram from Vladimir Filimonov, which is shown below.

Hope you guys enjoyed this round of MMM, next week is Sol’s turn over at wildaboutmath.com. Be prepared!

The Answer by Nate Burchell

Resize_of_MMM_28.jpg

Suppose you have only one MacBook, because if and when the first one breaks, you will have only one. If you have only one MacBook, you will need to increase by consecutive heights in order to be certain of the maximum height from which a MacBook can be dropped. Prove this by supposing that you test at non-consecutive heights. If a MacBook survives a drop from the fourth floor and breaks when dropped from the sixth floor, we have no way of determining (since we have broken our one-and-only MacBook) if the fifth floor drop would have been survived or not by the MacBook. Therefore, we must proceed by consecutive heights when we have only one MacBook.

With two MacBooks, we can optimistically skip a number of floors. In case of breakage, we resort to the simpler procedure for one MacBook.

The method for finding the maximum height with two MacBooks and n drops needs to acknowledge that if the first drop breaks one of the MacBooks, we have only n-1 drops to check the remaining heights. Therefore, there should not be more than n-1 heights left to check. Drop the first MacBook from the nth floor. If it does break, we have n-1 drops left to check (beginning at floor 1 and moving up through consecutive floors) the n-1 heights that we skipped. If it does not break, we have n-1 drops left, so we drop from (n)+(n-1)=2n-1, knowing that in case it breaks on the second drop, we still have n-2 drops with the remaining MacBook to work through the n-2 heights between the nth floor and the (2n-1)th floor. This continues and we get n+(n-1)+(n-2)+(n-3)+…+3+2+1=(n(n+1))/2 total floors tested by n drops.

With n=8 drops, we could test a maximum of 8*9/2=36 floors. With 7 drops, we could only test (at most) 7*8/2=28 floors, so we will need at least eight, and eight is sufficient.

delicious bookmark StumbleUpon technorati Digg reddit icon rss icon

MATLAB - How much do you BENCH?

Matlab Logo On a good day, I can bench 185 lbs. My counterpart, Mr. Sutoyo, sometimes struggles with 135 lbs. Luckily, this post is about the MATLAB benchmark, and not about lifting weights. The MATLAB BENCH command allows you to see how fast your computer is when performing certain MATLAB tasks. In the world of computers, it also acts as a means to living vicariously through your souped up PC (or MAC).

 BENCH  MATLAB Benchmark
    BENCH times six different MATLAB tasks and compares the execution
    speed with the speed of several other computers.  The six tasks are:

     LU       LAPACK.                  Floating point, regular memory access.
     FFT      Fast Fourier Transform.  Floating point, irregular memory access.
     ODE      Ordinary diff. eqn.      Data structures and M-files.
     Sparse   Solve sparse system.     Mixed integer and floating point.
     2-D      plot(fft(eye)).          2-D line drawing graphics.
     3-D      MathWorks logo.          3-D animated OpenGL graphics.

Contents

I Can Bench This Much

My computer setup consists of the following:

  • Intel Pentium D 940 @ 3.2 GHz
  • 2 Gigabyte Ram @ 333 MHz
  • Nvidia GeForce 6800 XT
  • Windows XP OS

To run the bench command, type the following at the MATLAB command prompt:

>>bench(4)

After some intermediate plots and eye candy from MATLAB, you’ll be greeted by the following two images. These graphs will give you an idea of where your computer ranks among pre-selected computer configurations.

results of MATLAB bench part 1

results of MATLAB bench part 2

Why do we run the bench command 4 times? Well, your computer needs a couple of iterations to get acclimated to MATLAB’s benchmark test. Consider it a “warming up” exercise. Thus, let’s only look at the 4th row of data.

>> bench(4)

ans =

    0.2627    0.5587    0.3311    0.5966    0.7169    1.9982
    0.1752    0.2905    0.2472    0.4571    0.6253    0.7173
    0.1716    0.2941    0.2499    0.4568    0.6329    0.9594
    0.1705    0.2980    0.2481    0.4592    0.6530    0.7203

How Much Does Daniel Bench?

The following specs are for Daniel’s PC.

  • intel(R) Core(TM)2 Quad CPU Q6600 @2.40 GHz
  • 4 Gigabyte Ram @ 500 MHz
  • Nvidia Geforce 8800
  • Windows Vista 32-bit

His output obviously outclasses mine.

    0.0859    0.1977    0.1503    0.8001    0.3879    0.7092
    0.0825    0.1892    0.1528    0.4042    0.3720    0.6801
    0.0824    0.2024    0.1526    0.4041    0.3889    0.6973
    0.0938    0.2063    0.1528    0.3936    0.3855    0.7016

Beaten by a Laptop?

If someone told me that a Laptop could outperform my desktop, I would have found the thought laughable. Apparently, Rob’s Laptop did the impossible. The final benchmark we will share today belongs to Rob’s miniature beast know as the Lenovo.

  • Intel® Core™2 Duo processor T9600
  • 2GB of PC2-8500 1066MHz DDR3
  • Discrete Open GL Graphics ATI Fire GL M86-GL (512MB)
  • Windows XP Pro 32-bit
    0.1195    0.1318    0.1095    0.2314    0.2870    0.2213
    0.0763    0.1335    0.1064    0.2294    0.2698    0.2286
    0.0764    0.1309    0.1065    0.2296    0.2706    0.2354
    0.0906    0.1349    0.1090    0.2306    0.2853    0.2343

Wow!

How Much do YOU Bench?

How does your computer perform when using the BENCH command? Give it a try and report your results! Don’t forget to list your computer specs as well!

delicious bookmark StumbleUpon technorati Digg reddit icon rss icon

MATLAB - Avoiding the CD command

Matlab LogoThe CD command allows you to change the working directory. Most people use this command to either move to a particular directory wherein input files are stored or to move to a directory to write output files. In theory, there isn’t anything wrong with changing the working directory in the middle of a script/function. But in practice, it’s better to avoid doing that. In this post, we’ll discuss using the FULLFILE command to help us avoid the CD command.

Contents

The CD Command - Good or Evil?

To me, the CD command shouldn’t be used if it can be avoided. When commands such as IMPORTDATA, XLSREAD, XLSWRITE, LOAD, SAVEAS, etc are used, they require an input string that designates the file name. If the files are stored within the MATLAB current directory from where the m-file is being executed, then you don’t have to include the entire path name of the file. For example, you can do the following:

%this command will work if the file is located in the current directory
load('mydata.txt')

But if you specified the full file path, as shown in the example below, then it doesn’t matter where the file is located!

%this command will work no matter what directory the m-file is running from
load('C:/MATLAB/blinkdagger/data/mydata.txt.')

Example of Script using CD

A lot of times, people will use the CD command to move to a designated directory in order to write output files. Here’s an example of a script that does this.

currentDir = pwd;  %save the current directory

%outputDir is the directory where we'll write the output
outputDir = 'C:/output';
%outputFileName is the name of the output file
outputFileName = 'myData.xls';

cd(outputDir) %change directory

xlswrite(outputFileName ,data)     %write the output data in Excel
cd(currentDir) % go back to the original directory

FULLFILE is your Friend: Example of Script without CD

Instead of doing the above, there’s an easier, and less cumbersome way that will make your code more robust. By using absolute file paths, we can avoid using the CD command. Notice that we don’t have to change the directory, write the output file, and then change back to the original directory.

%outputDir is the directory where we'll write the output
outputDir = 'C:/output';
%outputFileName is the name of the output file
outputFileName = 'myData.xls';

%build the full path of the outputfile
fullPath = fullfille(outputDir,outputFileName);

xlswrite(fullPath ,data)     %write the output data in Excel

Another reason why I like the FULLFILE command is because I don’t have to worry that I have the appropriate number of ‘”/” in my file path. FULLFILE makes sure that the path name is arranged correctly.

Absolute is better than Relative!

The lesson learned in this post is that absolute file paths are more robust than relative file paths. In general, it’s good practice to use the absolute file path instead of the relative ones as it will make your code more flexible and portable.

delicious bookmark StumbleUpon technorati Digg reddit icon rss icon

« Prev - Next »