Showing posts with label MATLAB. Show all posts
Showing posts with label MATLAB. Show all posts

Friday, May 3, 2013

Math and Music

It’s said that there’s a connection between the logical realm of math and the more abstract land of music. Scientists have done studies analyzing the rhythmic and structural underlyings of music to try and understand how they help to enhance math skills. They've got the research. I have the real life experience. Now presenting: How to become a math genius in three easy steps with the three Bs: Bach, Brahms, and Beethoven. That time in MATLAB I was reminded of pep band. Which isn't that hard, because a lot of things remind me of pep band.

Anyway, it was the last MATLAB lecture of the semester, and we were finishing up with sorting methods. We’d just done recursion, so the last sorting method we were learning (after insertion and bubble sort) was the merge sort. To start our discussion of the merge sort, the professor asked us if it would be easier to straight up sort a thousand items or merge two sets of five hundred items that had already been sorted. Well, this one time in band . . .

Actually, it’s been a lot of times in band. So the pep band “folders” are stacks of half sheets of music shoved into a pocket-type holder made of construction paper and/or duct tape. Normally, people keep their music alphabetized so they can find it more easily. However, during our busier events (hockey), most people don’t have time to put their music away between sets, so after the game there’s the folder, and then there’s the giant pile of music outside the folder . . . that needs to be sorted.

At this point, you have three options: one, take each piece of music and go through your folder to find out where it goes; two, alphabetize the music outside of your folder and then combine (hint: merge) the two piles; and three, ignore the giant stack of un-alphabetized music by shoving it into your folder and regretting it the next time you have to find a piece of music. Well, if you ask me, options one and two sound a lot like the insertion and merge sorts.

Speaking from experience, if around half your folder is sitting in a heap waiting to be put back into the folder, alphabetize it first so you don’t have to flip through the a’s seven billion times. (Merge sort) Otherwise, just sort each song in the order you find it. (Insertion sort)

And that is how math (okay, computer science, which needs math) is like music.

Thursday, February 14, 2013

For Want of an Asterisk

Saturday morning.  Nemo has just blanketed Cornell’s campus with four inches of fresh snow.  When I step out of my dorm, the snow is fresh and untouched.  That’s because it’s nine in the morning of the first full day of our weekend.

That’s right.  Nine am and I’m about to embark on a two and a half hour coding journey with MATLAB.  I’m a morning person, so I leave my 7:15 alarm on all weekend and go to bed when people are heading out for the night.  Which is why I had no problems when a friend and my current MATLAB partner suggested meeting early on Saturday morning to take a look at the homework.

Since my parents wouldn’t pay for MATLAB I didn't buy MATLAB for my computer, we went over to the lab at RPCC.  Another plus of starting that early was that the lab was empty except for one other person, and he left after a few minutes, so we didn't have to worry about bothering anyone with our talking.

Two and a half hours . . . sounds an awful lot like our Intro to ChemE homework sessions.  Anyhow, I’d looked at the first problem beforehand, so we got that one done in . . . an hour, maybe.  The second problem I hadn't looked at, so I was doing all the coding as I figured out the problem.  I handwrote the code, typed it into MATLAB, and was trying to test it when I kept getting an error message.  Usually, MATLAB’s good about giving you the problem and which line is causing the problem, and it did this time too, but I couldn't understand what MATLAB was trying to tell me.

I turned to Google to explain the error and got something about an array.  What array?  I don’t even know what an array is or how to program one.

Sixty-seven trials later (and extensive use of the pause function – I was told this would be useful in debugging, but I’m not sure the professor would have expected its use this soon), I found the error.  I was trying to multiply a variable by a quantity and typed it as x(2*k+1).  Yep, I forgot an asterisk.  (It should have been written as x*(2*k+1).)  I typed in the asterisk and the program worked perfectly.

Wednesday, February 6, 2013

MATLAB Troubles

I know I did say I was going to write about my first week back at Cornell, but it’s actually not all that interesting, so I’m going to focus on my Intro to CS class.  It’s technically called Introduction to Computing Using MATLAB, but I will refer to it as either Intro to MATLAB or MATLAB from here on out.

I’ve never taken a programming class before, so everything has been completely new to me.  So far I really like the class, especially the actual programming.  During lectures, it’s a little weird learning about how to code without actually getting to code, but the professor is enthusiastic about the class, which is always a positive.

As of a few days ago, I coded my first entire program (we calculated the surface area of an oblate spheroid) with the extensive help of MATLAB’s error detection system.  Honestly, if anyone got a nickel for every time I forgot to end a line with a semicolon, they’d probably be rich by the time I finish this class.  Or at least have enough money to pay for next semester’s textbooks.

Then there’s all those things that aren’t necessary, but are “good form.”  When creating my Intro to ChemE spreadsheets last semester, I was in the camp of people-who-don’t-want-to-scroll-a-lot, so everything would kind of be shoved into whichever cells I could see on one screen of Excel.  Similarly, if I didn’t have that 80-character-per-line good form limit, why waste time scrolling when you can jam five short lines of code into one long line the width of your computer screen?

By the way, who decided that we need both a slash and a backslash?  I found out the difference when I was trying to do a line return after a printed statement.

I’m really not complaining about the class or MATLAB, but rather, pointing out my sometimes utter disregard for style.  Apparently things not only have to work, but also look pretty.

Can’t think of a good way to finish this post, so I’ll go with this one:
end