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.

Friday, May 15, 2009

WolframAlpha is Live! Hmmm...

Still seems interesting but not very useful yet! The search results are not as advertised, it is slow (very slow at times and it is 11:45pm PST), and could not get to the WA Vista gadget. I tried the following searches:

  • RTV 630: No response.
  • Coastline Greece: No response (the info is available in the CIA Factbook).
  • PHG RTN: Came up with airport info with option for financial entity (OK).
  • 100*1.05^5: Calculation correct
  • wave equation: No response.
  • pair of jacks: (See screen capture)


























I gave up after that. I will try again in a few days.

Wednesday, May 13, 2009

Computational Search Engine WolframAlpha

 

Pretty soon (May 2009) Wolfram Research (of the Mathematica fame) will release a computational search engine called Wolfram|Alpha. It seems like an awesome math engine. Just check out the blog entry Math? Of Course!

 

WolframAlpha_

UPDATE 1:

WolframAlpha goes live on May 15.

Set /3GB Startup Switch for MATLAB Memory Performance

The May 8 entry of the MATLAB blog File Exchange Pick of the Week offers information on a user submitted function CHKMEM.M that can provide good information about the status of your computer's memory. I downloaded the file and run it and among other things it notified me that

3GB switch status:
The MATLAB process limit has been detected as 2047MB, therefore the 3GB switch in your system's boot.ini file is NOT SET. If you add this switch you can gain an additional 1GB of memory space for MATLAB.

Good catch! I forgot to set that when I set up my new PC.

The /3GB switch is set in the Boot.ini file and it increases the amount of virtual memory from 2 GB to 3 GB which will help with some MATLAB 'out of memory' errors.

Detailed instructions on how to set are available from Microsoft in article How to Set the /3GB Startup Switch in Windows.

For Windows XP my initial Boot.ini file read:

[boot loader]
timeout=30
default=multi(0)disk(0)rdisk(0)partition(1)\WINDOWS
[operating systems]
multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Microsoft Windows XP Professional" /noexecute=optin /fastdetect

and was changed to:

[boot loader]
timeout=30
default=multi(0)disk(0)rdisk(0)partition(1)\WINDOWS
[operating systems]
multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Microsoft Windows XP Professional" /noexecute=optin /fastdetect /3GB

After PC restart and rerun of CHKMEM.M the message changed to:

3GB switch status:
The MATLAB process limit has been detected as is 3071MB, therefore the 3GB switch in your system's boot.ini is SET.

The memory available on my R2008b MATLAB increased from 1491 MB to 2572 MB (can check by running the MEMORY function at the command prompt).

matlabCmdWindow_

Thursday, May 7, 2009

gk. Axiom

And now that it is out of system, here is my project management axiom:

Every project is a trade off between cost, schedule, and performance and at any one time you can have two out of three but never all three together.

I read this somewhere years ago and stuck in my mind. It is absolutely true. I wish everyone kept it in mind...


Scream…

scream_

Wednesday, May 6, 2009

FIFA World Ranking Top 20: May 2009

Rank Team Points
1 Spain 1729
2 Germany 1362
3 Netherlands 1360
4 Brazil 1281
5 Italy 1271
6 Argentina 1195
7 England 1173
8 Croatia 1151
9 Russia 1117
10 France 1074
11 Portugal 1013
12 Czech Republic 968
13 Greece 927 (No new action)
14 Turkey 923
15 USA 919
16 Uruguay 909
17 Paraguay 906
18 Switzerland 883
19 Cameroon 871
20 Bulgaria 840

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

Monday, May 4, 2009

Windows Live Writer

I just downloaded a tool from Microsoft that ‘makes it easy to share your photos and videos on almost any blog service’.

Writer is available for download here for Windows Vista and XP SP2 (32 bit).

090503 Writer Capture

UPDATE 1:

It works reasonably well (at least basic functionality) and it seems pretty straight forward. It connected to my blog without trouble and updates are easy.