Tuesday, June 9, 2009

gk. Matrix

Inspired by Case from the book ‘Neuromancer’ by William Gibson. A punk hacker from hell that quite possibly inspired the character Neo from The Matrix trilogy. The book is enjoyable and a fast read provided that you do not try to make sense out of every little detail about Straylight, Wintermute, Tessier-Ashpool, etc. The book requires a healthy dose of abstraction!

gk.Matrix3

(Made possible by Photoshop Elements.)

Thursday, June 4, 2009

FIFA World Ranking Top 20: June 2009

Rank (previous) Team Points
1 (1) Spain 1761
2 (3) Netherlands 1442
3 (2) Germany 1378
4 (5) Italy 1292
5 (4) Brazil 1288
6 (7) England 1225
7 (6) Argentina 1203
8 (8) Croatia 1200
9 (9) Russia 1167
10 (10) France 1067
11 (11) Portugal 1004
12 (14) Turkey 964
13 (17) Paraguay 961
14 (15) USA 947
15 (12) Czech Republic 943
16 (18) Switzerland 931
17 (13) Greece 922 (No new action)
17 (16) Uruguay 922
19 (22) Ukraine 891
20 (23) Serbia 870

You can find the latest complete list at the official FIFA website.

Monday, June 1, 2009

MATLAB: Favorite Shortcuts

Some of my favorite (and most used MATLAB shortcuts).

Description Callback
Open folder XX winOpen ‘C:\XX\’
Change directory to folder XX cd ‘C:\XX\’
Open Help Browser helpbrowser
Close Help Browser com.mathworks.mde.desk.MLDesktop.getInstance.closeHelpBrowser
Clear Workspace

clear all

close all

clc

Set Editor at specific state
(See also here and here)

editorServices = com.mathworks.mlservices.MLEditorServices;

load('C:\MATLAB\Editor State Files\xxxxAnalysis.mat')

for id = 1:length( editorState )
      editorServices.openDocument( editorState(id) )
      end

Sunday, May 31, 2009

MATLAB: Shortcut Editor State

In an earlier blog entry I documented a way to preserve that state of the editor (that is all windows open in the editor) in a .mat file that can be reloaded whenever needed.

I decided to make a shortcut of the most frequently re-loaded set of windows. It is easy to do in MATLAB:

  • Highlight code of interest.
  • Drag to shortcut toolbar.
  • Enter ‘Label’
  • Done!

For my case I added the shortcut to a personal folder accessible from the Start button (Start – Shortcuts).

shortcuts_organizer_

The code entered in the Callback field:

editorServices = com.mathworks.mlservices.MLEditorServices;

load('C:\Documents and Settings\User\My Documents\MATLAB\Editor State Files\xxxxAnalysis.mat')

for id = 1:length( editorState )
      editorServices.openDocument( editorState(id) )
      end

GRIPE ON:

What is the point of having a personal folder accessible from the Start button??

I am using it as a repository of commands that would be good to have close but not necessarily add to toolbar (and thus add to clatter). However, they do not count as ‘shortcuts’. A shortcut is an 1-2 clicks operation not something that essentially takes 3-4 clicks to launch. That counts as a sub-sub-… menu! Not to mention ‘out of sight out of mind’.

It would have been much better if by making a personal shortcut folder you actually place it as an icon to the toolbar that can be launched via a 2-click operation. And everything is right there in front of you so you do not forget your shortcuts. And everything is organized.

Thursday, May 28, 2009

MATLAB: Spline My Monogram

I saw that exercise as an assignment for a MATLAB course and it reminded me of my senior year in college studying aerospace engineering. As a senior project me and 3 other people designed and build and aeroplane (great fun!) and among other things I used a plastic spline and some weights called ‘ducks’ (to set the curvature). Much easier to do generate splines with a computer!

The code to generate cubic splines is well known and makes use of a tridiagonal system of matrices which lends itself well to MATLAB programming. However, the MATLAB people have made available standard spline functions (also exotic versions for a friendly fee!) which makes the whole operation pretty straight forward. See below; All code is entered in the MATLAB command window.

I first wrote my monogram on an 8x10 engineering paper and determined the (x, y) coordinate pairs (my ducks!) See plot below for my data set. (Set axis to equal for proper appearance.)

>> M = load('monogram data.txt');

>> x = M(:,1);
>> y = M(:,2);

>> plot(x, y, 'o', 'markersize', 5)
>> grid on
>> axis equal

step1_data

If the MATLAB Spline toolbox is available then the function SPCRV will work well.

>> values = spcrv(M,2); % 2nd order

>> subplot(121)
>> plot(x, y, '.b', values(:,1), values(:,2), '-r', 'linewidth', 1)
>> grid on
>> axis equal

>> subplot(122)
>> plot(values(:,1), values(:,2), '-r', 'linewidth', 1)
>> axis equal

step2_spcrv

It is almost as easy to generate the spline using the standard 3rd order SPLINE function available with basic MATLAB. I need to define common parameter t so x(t) and y(t) can be found.

>> n = size(M,1); % number of data points

>> t = 1:n;

>> ts = 1:1:n;

>> xs = spline(t,x,ts);
>> ys = spline(t,y,ts);

>> subplot(121)
>> plot(x, y, '.b', xs, ys, '-g', 'linewidth', 1)
>> grid on
>> axis equal

>> subplot(122)
>> plot(xs, ys, '-g', 'linewidth', 1)
>> axis equal

step3_spline

Compare the two solutions (spcrv vs. spline); The two curves are identical.

step4_compare

Reduce the step size of parameter ts to improve appearance of my monogram.

ts = 1:1/20:n;

xs_ = spline(t,x,ts);
ys_ = spline(t,y,ts);

subplot(121)
plot(x, y, '.b', xs_, ys_, '-g', 'linewidth', 1)
grid on
axis equal

subplot(122)
plot(xs_, ys_, '-c', 'linewidth', 1)
axis equal

 

step5_splineFine

Looks pretty nice!

Now I just have to create my own code (as I have done years ago in FORTRAN) and compare with the MATLAB result. Another day maybe!

Wednesday, May 20, 2009

From PhDComics.com: Funny and True!

From the 5/19/09 PhDComics.com comic strip (Piled Higher &Deeper). I could not resist preserving it here. The comic by Jorge Cham is very funny and right on with regards to the academic life of a graduate student.

The Science News Cycle

Monday, May 18, 2009

WolframAlpha: Another Try!

Today I tried WolframAlpha again (still being excited about the possibilities of the computational search engine). I tried the following searches:

  • One pound of gold: Result OK.
  • Autocorrelation: Resulted in Wolfram|Alpha isn't sure what to do with your input. Interestingly Wolfram MathWorld has a much better result here. (You would think that the knowledge search engine would know about other products in the same family...)
  • Integrate x^n: Result OK.
  • Total derivative x^n: Result OK
  • Legendre Polynomial: Result OK (mostly after clicking on definition link to Wolfram MathWorld)
So far it has not met my expectations for a very smart pure math/physics related content search engine. It might be that the hype was excessive and thus my expectation too high. It might realize its potential some day. For now it just seems like a subset of MathWorld with a dose of real data that Google can (at the very least) get for me much faster.