As I said in my
last post, here at the MathWorks 亚搏体育app网站下载链 blog we are currently celebrating an important milestone: MATLAB Central is 20 years old!
It's a fine number, 20. Certain numbers just come across as friendly, and I've always been fond of 20. It's hanging out at the corner of Binary and Decimal, smiling pleasantly to everyone who walks by. What can we do to honor it and MATLAB Central? What are some of the factors that make 20 so admirable? I can think of a few.
Its literal factors make it clear that 20 is a so-called pronic number. That just means it takes the form n*(n+1).
That's pronicity for you. I love how you can take an uninteresting fact about a number, give it a fancy name, and suddenly it becomes more interesting [strokes goatee, saying "Yes, pronic. Yes."].
Now, what can we do with those factors?
This is fun. The answer to life, the universe, and everything may be 42, but what is the question? Now you know: it's "What is the sum of the divisors of 20?" (Note for those of you following along at home: divisors is from the Symbolic Math Toolbox.)
I wrote a short poem of admiration for 20. It goes like this.
Two, four, six, eight!
Who do we appreciate?
Yes, it's our friend 20. We can refactor our code and our poem like so.
Twice the sum of one through four!
What's the number we adore?
triangular = cumsum(linear)
tetrahedral = cumsum(triangular)
Two, four, six, eight!
How do we accumulate?
Okay, I'll lay off the poetry. But all this accumulation reminds me that this same set of numbers can be found in
Blaise Pascal's favorite triangle. And there, surveying all, seated serenely in the bottom right corner, is our guest of honor.
pascal(4)
1 1 1 1
1 2 3 4
1 3 6 10
1 4 10 20
Twenty Characters
Those are some things we can do with the number 20. But enough number theory! What can we do with 20 characters of code? Here's a nifty plot that uses only 15 characters. The default colors make for a nice Mexican blanket effect. Call it an area rug. Heh.
It looks better without the axis on, but that would put me over the character limit.
Here's one in honor of Cleve Moler, the father of MATLAB. Behold, 20 characters that reveal the
Moler matrix of order 20.
gallery("moler", 20)
1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
-1 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
-1 0 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
-1 0 1 4 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
-1 0 1 2 5 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3
-1 0 1 2 3 6 4 4 4 4 4 4 4 4 4 4 4 4 4 4
-1 0 1 2 3 4 7 5 5 5 5 5 5 5 5 5 5 5 5 5
-1 0 1 2 3 4 5 8 6 6 6 6 6 6 6 6 6 6 6 6
-1 0 1 2 3 4 5 6 9 7 7 7 7 7 7 7 7 7 7 7
-1 0 1 2 3 4 5 6 7 10 8 8 8 8 8 8 8 8 8 8
I need another two lines to show you what it looks like. Pretty easy on the eyes, eh? But beware! It has one very small eigenvalue that can easily upset naive elimination methods. Or so I'm told.
Twenty Lines
What can we do with 20 lines of code? This little Mandelbrot set just fits. All without even cheating by cramming multiple statements onto one line of code.
x = linspace(x0-r, x0+r, p);
colormap([parula(k-1);0 0 0])
A Contest of Characters: the MATLAB Mini Hack
Playing around with numbers, code, and images is fun, but there is a point to my meandering. I want to introduce an exciting anniversary celebration contest that we're going to launch next week. We call it the
MATLAB Mini Hack. It's a constrained character-count coding contest. And as long as I'm alliterating, I can tell you that it is also collaborative and colorful.
The contest centers around this question: what fun image can you make in MATLAB using no more than 280 characters of code? I'll give you an example. Weighing in at only 278 characters, the Mandelbrot code shown above fits the bill.
We're calling the Mini Hack a contest, but it's really meant to be mostly about the fun. With that in mind, we encourage you not only to contribute your original ideas, but also to steal, or rather "remix", other people's code. Build on top of their ideas, and make even more colorful mischief. And if you see someone remixing your code, remember: that's a good thing! Be proud.
I'm so excited about this contest, I'll be doing a live Instagram event this Friday (1 October) at 10am EST. I'll be talking about the history of MATLAB Central, how we are celebrating the 20th Anniversary, and everything you need to know about this crazy, kaleidoscopic contest.
Speaking of kaleidoscopes, I'll close with 280 characters of rotationally symmetric hgtransformed joy.
h1 = plot(x, y, LineWidth=6);
set(h2,Parent=t,Color=c(n,:))
rot = makehgtform(ZRotate=theta);
Comments
To leave a comment, please click here to sign in to your MathWorks Account or create a new one.