Loren on the Art of MATLAB

July 29th, 2009

Math in Poetry, Poetry in Math

You hear a fair amount about the mathematically inclined people who are really into music. You hear less about that subset of the same group who are into poetry, and particularly, poetry and math together.

You may already be familiar with the poems of Tim Davis. He's also contributed some poems on my blog starting with this comment.

I just ran into this set of poems that were collected for a homework assignment for a course on Numerical Methods, tailored for mechanical engineers. Notice the first one, spelling out "Engineer" using the first letters on each line.

If you are feeling so inclined, please feel free to wax lyrical about math and MATLAB here.


Get the MATLAB code

Published with MATLAB® 7.8

21 Responses to “Math in Poetry, Poetry in Math”

  1. matt fig replied on :

    Hello Loren,

    After noticing several NG threads in which it was found that a For loop solution was faster than any offered vectorized solution, I wrote a silly little poem in honor of the For loop. It can be found here:

    http://www.mathworks.com/matlabcentral/newsreader/view_thread/256123#665693

  2. Loren replied on :

    Nice one, Matt!

  3. Tim Davis replied on :

    My favorite math poem on my web page (at least at the moment) is a recent translation of one of Burn’s poems, The Mouseholder QR. It has lots of MATLAB puns in it (with links back to the MATLAB documentation, no less):

    http://www.cise.ufl.edu/~davis/Poetry/Mouseholder_QR.html

    That poem is about a nasty matrix that gets help from Nick Higham. (Nick is the author of the MATLAB gallery, expm, logm, sqrtm, funm, polyeig, and condest functions, among other things).

    I haven’t put up the audio mpeg of me reading that poem yet; it’s really needed since it’s not easy to read Scots-flavored English. I’ll try to do that later today. My colleague and former postdoc advisor, Iain Duff, enjoys the Burns take-offs, but cringes at my pseudo-Scots accent! Iain Duff is the author of MA49, used in the sparse LDL’ factorization in the recent versions of MATLAB (see “doc ldl”).

    I do have audio mpegs of this Burn’s takeoff (as read by me, and by Iain Duff, a true Scot himself):

    http://www.cise.ufl.edu/~davis/Poetry/Ode_to_a_Matrix.html

    which also has lots of MATLAB references.

    And if I get inspired, I’ll have to write a new one and post it here in reply.

    Thanks,
    Tim

  4. Loren replied on :

    Tim-

    Another good one!

    –Loren

  5. us replied on :

    dear loren,
    to be very honest with you:
    your famous blog has seen better days…
    urs

  6. Loren replied on :

    Us-

    Perhaps you can offer topic recommendations you would like to see covered. The offer is open to all readers, by the way.

    –Loren

  7. Tim Davis replied on :

    A well-written code is itself mathematical poetry. Concise, expressive, with clear structure and powerful themes …that describes good math, good code, and good poetry. Alas, my poetry isn’t as good as my code. So enjoy (or not…) a poem I wrote this morning, for all ye MATLUBBers (MATLAB functions and keywords in all-caps).

    A PI-RATS LEGEND, by T.D.
    
    I'll sing for you a old C-shanty,
    Or in M most certainantly.
    "A PI-RATS LEGEND" is the TITLE,
    Thar be no PAUSE in my recital:
    
    Our ship is Arg Two-Thousand Nine,
    She PACKs nine cannon, sleek and fine.
    Above the waterline she's M,
    Beneath is naught but C.
    And altogether quite a gem;
    No use to TRY AND CATCH ME!
    
    We came across a lucky BREAK,
    And SPY'd an easy take.
    A treasure ship amidst the SURF,
    She's stuck in our own turf.
    And so we came, with WARNING's ('OFF'),
    On wavelets, crest and trough!
    
    Our captain cried out "Argh! me men!"
    We ANSwered him back thrice!
    "Our FUNCTION'sPRIME," we gloat with glee;
    (NARGIN be one, NARGOUT be three).
    "We wait until the count of ten,
    with BACKSLASH quick to SLICE.
    With JAVACHK'ed (the JIT, I'll ken)
    And rum, the PI-RATS vice!"
    
    And so we pounced upon their ship,
    I know you'll think we're MEAN.
    When all the gold was in our grip,
    Our ERROR M routine
    Had captured all their lazy crew
    And beat them SCHUR and TRUE.
    
    "There's surely MORE!" our chief ASSERTs,
    "Or on the plank you'll walk!
    I'll SAVE your lives, but NOT your shirts,
    For gold upon my DOC!"
    And so he shouts until it hurts;
    He's TIC'ed until they TOC.
    
    So now our TOOLBOX carries gold
    With PERL's and treasure to behold.
    Now don't ye cry, ye' poor MATLUBBer,
    My tale is nary CASE to blubber.
    IF MEM'RY serves, we SAVE'd them ALL;
    RETURN'ed ONCLEANUP, EYE recall.
    
  8. us replied on :

    dear loren,

    first and foremost: when i re-read my own comment, it looks indeed somewhat ’short’…
    but: in absolutely no way did i intend to offend/… anyone participating in this blog; we all know that i most highly respect all(!) people who showed up…
    i simply thought it was a silly -silly season- blog filler…

    now, for possible topics:
    some people would like to see an in-depth blog or two about JAVA stuff: not just the simple things one can look up in the docs but rather the ‘hidden’ bits and pieces, ie, things related to the (current) graphics handles and some of its apps as well as the very useful stuff related to ML’s very engine (eg, the various com.mathworks.*s).

    a lot of these hidden helpers/engines have been available(unchanged, despite warnings from TMW[!]) for years - and have often been advertised on CSSM by various people (like yair altman now even devoting a web site for this and myself), who took the time to dig into matters, eg,

    methods com.mathworks.mlservices.MLEditorServices
    methods com.mathworks.mlservices.MLCommandHistoryServices
    methods com.mathworks.mlservices.MLWorkspaceServices

    just to mention a few with goodies like

    d=MatlabDesktopServices.getDesktop
    d.setClientDocked(…)
    d.setGroupMinimized(…)

    and zillions more…

    as ever, best from zurich
    urs

  9. StephenLL replied on :

    One topic others might benefit from is an overview of the new .net integration with matlab. While windows specific, being able to leverage the .net library is very useful.

    Lately I have used it for sending emails, doing file hashes, writing to the windows event log, writing to databases, xml parsing ,and sending data across a tcp/ip connection.

    I realize you can do these with java too. I’m finding sometimes it is just easier to do with .net.

    Just an idea.

    Stephen

  10. Naor replied on :

    Hopefully everyone here is familiar with Stanislaw Lem’s “Love and Tensor Algebra.” Here it is just in case:

    Come, let us hasten to a higher plane,
    Where dyads tred the fairy fields of Venn,
    Their indices bedecked from one to n,
    Commingled in an endless Markov chain!

    Come, every frustum longs to be a cone,
    And every vector dreams of matrices.
    Hark to the gentle gradient of the breeze
    It whispers of a more ergodic zone.

    In Riemann, Hilbert or in Banach space
    Let superscripts and subscripts go their ways.
    Our asymptotes no longer out of phase,
    We shall encounter, counting, face to face.

    I’ll grant thee random access to my heart,
    Thou’lt tell me all the constants of thy love;
    And so we two shall all love’s lemmas prove,
    And in our bound partition never part.

    For what did Cauchy know, or Christoffel,
    Or Fourier, or any Boole or Euler,
    Wielding their compasses, their pens and rulers,
    Of thy supernal sinusoidal spell?

    Cancel me not–for what then shall remain?
    Abscissas, some mantissas, modules, modes,
    A root or two, a torus and a node:
    The inverse of my verse, a null domain.

    Ellipse of bliss, converge, O lips divine!
    The product of our scalars is defined!
    Cyberiad draws nigh, and the skew mind
    Cuts capers like a happy haversine.

    I see the eigenvalue in thine eye,
    I hear the tender tensor in thy sigh.
    Bernoulli would have been content to die,
    Had he known such a^2 cos(2 \pi) !

  11. Tim replied on :

    No fear … no offense taken. Yes, this post is just for some light-hearted fun.

  12. Loren replied on :

    Urs-

    While I understand your desire to have me write about hidden features, and I know there’s pent up demand (as you said, see Yair’s successful blog (http://undocumentedmatlab.com/), that’s an area where I plan to not venture. I don’t want to mislead people about what is supported in MATLAB. I do believe there should be ways to get the open files in the editor, find out or set a group to minimized, etc. The best way to make this happen for real is for users to put in enhancement requests so there is an approved MATLAB api for expressing those various notions that would be a supported and documented part of the package.

    –Loren

  13. Steve Eddins replied on :

    Urs, if you don’t want to see the occasional silliness, in which we MathWorks bloggers let our personalities show through … well, there’s always the doc. ;-)

  14. Amin replied on :

    Hi loren,
    Are you familiar with Hakim Omar Khayyam? He was an Iranian mathematician, philosopher, astronomer and poet.
    He wrote a several articles, for example a Treatise on Demonstration of Problems of Algebra, which laid down the principles of algebra.
    Modern Iranian calendar is based on his calculation of the solar year as 365.2425 days. His calendar was more accurate than 500 years later the Gregorian calendar.
    His poetic work famous as the Rubaiyat of Omar Khayyam, and translated to English by Edward FitzGerald.
    You can find more information in http://en.wikipedia.org/wiki/Omar_Khayyam

  15. Petr replied on :

    Hi Loren.

    What about the poem about the halting theorem?
    http://www.lel.ed.ac.uk/~gpullum/loopsnoop.html

    Petr

  16. Petr replied on :

    Sorry… about halting problem, of course.
    Petr

  17. Tim Davis replied on :

    I’ve enjoyed this recent book that delves into the connections between math and poetry:

    “Discoverying Patterns in Mathematics and Poetry”, Birken & Coon, Rodopi, 2008.

    http://www.amazon.com/Discovering-Mathematics-Internationale-Vergleichenden-Literaturwissenschaft/dp/9042023708/

    It’s not a book on poems about math, but a book on the similar patterns in both mathematics and poetry.

  18. Autar replied on :

    And if you want to see if the engineering students can wrap too - here is the link. http://www.youtube.com/watch?v=WRTjkZnZ0Nk

  19. Sarah replied on :

    Hi Loren,

    You might enjoy this poetry anthology: Strange Attractors, Poems of Love and Mathematics, edited by Sarah Glaz and JoAnne Growney, A K Peters Ltd., 2008.

    Publisher website:
    http://www.akpeters.com/product.asp?ProdCode=3417

    amazon.com website:
    http://www.amazon.com/Strange-Attractors-Poems-Love-Mathematics/dp/1568813414/ref=sr_1_1?ie=UTF8&s=books&qid=1235762902&sr=1-1

  20. Loren replied on :

    Thanks for the pointer, Sarah. Good luck with the book!

    –Loren

  21. E. Friedman replied on :

    “Strength in Numbers”

    A blanket covered in inked figures, draped over my knees.
    Security.
    Symmetry.
    A hint of the universe.
    How can there be so much comfort in something that is disguised in coldness?
    But each one is alive.
    Four straddles two, as both its double and its even elder.
    Seventeen is perfect, beautifully round like a circle, like the earth.
    Three forty three, a three-dimensional one-one-one, built like a heptagon, except better.
    And infinity, the most magnificent of them all.
    Like a white cloud of mist and snow.
    Like joy.
    Like God.

Leave a Reply

Wrap code fragments inside <pre> tags, like this:

<pre class="code">
a = magic(3);
sum(a)
</pre>

If you have a "<" character in your code, either follow it with a space or replace it with "&lt;" (including the semicolon).


Loren Shure works on design of the MATLAB language at The MathWorks. She writes here about once a week on MATLAB programming and related topics.

  • Jun: I totally can not believe it, Loren. You are really helpful. Thank you so much, MATLAB master!
  • Loren: Wow folks- Always lots of interest when there’s a quickie to try out! I will only make 2 general...
  • Loren: Jun- ismember is your friend here: >> [aa,ind] = ismember(Array2,Arra y1) aa = 1 1 1 1 1 1 1 ind = 1 2 1 4 4 3...
  • Dan: I like the first way better than the second way. Combining the arrays into one and running any is nice, although...
  • James Myatt: How about I = (a == 0 | b == 0); a(I) = []; b(I) = [];
  • Tunc: Hello Loren, love your blog because of such inspiring and challenging comments to such ’small’...
  • Pekka Kumpulainen: Here is my tradeoff. I usually want to keep the original variables as they are most probably...
  • Iain: Followup: Of course, to allow NaNs (counting them as non-zero): mask = (a~=0) & (b~=0); The mask says “a...
  • Matt Fig: I would usually go with something like this: y = a&b; x = a(y); y = b(y); But I was surprised to find...
  • kk: c=all([a;b]) a(c) a(b)

These postings are the author's and don't necessarily represent the opinions of The MathWorks.