Programming Throwdown - Matlab and Octave
Episode Date: April 27, 2011This show covers Matlab, a matrix-based interpreted multiprocessing function language. This episode talks about cloud computing, gaming, and then DIY hardware. The tools of the day are TI MSP...430 Launchpad, a hobbyist single board computer (SBC) and Sketchup, a 3d prototyping software. ★ Support this podcast on Patreon ★
Transcript
Discussion (0)
programming throwdown episode number four matlab and octave take it away jason man episode number four it's pretty pretty epic it's a milestone
for yeah yeah it's uh eight weeks yeah there we go eight weeks we have soon we'll be at 140
yeah that's right we have uh what is it like uh over 150 downloads so uh quite a few of you have
been listening and so we appreciate that yeah got a number of reviews on iTunes, five stars. Thank you all
for doing that. Yeah, that's good times,
good times.
So I think
there was something in the news about like Amazon
with their like EC2, their
cloud server went down. Did you see that one?
Yeah, it was all over the news all day.
Saw a bunch of that. Their web
services went down. I guess it was all
of them, their S3, EC2, all of them.
Oh, really?
I thought it was just EC2.
Maybe.
Okay, I'm not really sure about that.
But, yeah, I saw that Amazon's stuff went down.
And it's interesting how many popular websites now are actually running on top of Amazon's web service.
I guess that's a praise of how good it really is.
But things like Quora, which is a question and answer site was down.
I know Heroku, which is a was bought.
Who is it bought by?
Oh, well, it's a company that's a platform as a service and they host like Ruby apps
and stuff.
And I know they were down.
I think Dropbox was even having problems.
Pretty much, you know, a large portion of the popular websites we go to and use every day
use Amazon Web Services as a back-end because they've done such a good job making it so cheap and reliable.
And then it goes down, and then it's like, uh-oh, the world comes to a halt.
Yeah, I mean, this is similar to, what was that one company?
It started with an E, that they did email surveys, and they got hacked.
And as a result, your email and your name got leaked out.
Oh, yeah, a couple weeks ago.
Yeah.
I got an email from TripAdvisor saying that my email got leaked out.
And then I got one from the university that I was a student at.
And it's almost the same exact email every time.
I got another one from, I think, American Airlines.
And all of them used this one service that had an exploit.
Yeah.
So it's common.
It's surprising because a lot of people let their,
what do they call it, I guess, white labeling, right,
where you make a product,
but then somebody else can basically put their own label on it
or their own front end or high.
It's not obvious to people that you're using their backend.
And so, yeah, it's kind of interesting that when Amazon went down, all these websites
that are completely unrelated to Amazon went down as well.
And the e-company was Epsilon.
Oh, that's right.
Epsilon.
That's it.
So, yeah, hopefully they'll come back.
I guess maybe they're back by now.
But, yeah, it was down for a couple hours or whatever,
which is a pretty big deal with their increase in popularity.
I guess they've been down once before.
And when that happened, it was a while ago.
They weren't quite as popular.
And they came out and were really apologetic and said,
you know, we're not going to settle in making our product better until it's perfect.
Right.
I mean, the interesting thing about the Amazon cloud is just how accessible they've made it.
I mean, there's that library, that Python library, PyCloud, where you can take Python code and run it on the Amazon cloud with, like, virtually no effort.
It just literally takes your function calls and tries to guesstimate.
I think you might have to provide it,
like what actual data you think that function is going to use.
But it handles sending it to the cloud,
and you can pull the cloud and say,
are you done yet, are you done yet?
And then as soon as it's done, it'll let you know.
And so you can be using the cloud right now um from python and many
other languages uh with just a trivial amount of work and that's that's very interesting it really
puts a lot of power in our hands yeah and it's obviously lucrative for amazon i i saw some some
article we don't have this in our news but they were talking about that oh you're pointing out
to me that dropbox runs on top of of storage and how much a year I was in the millions that Dropbox is paying for.
Yeah, it was about $4 million a month.
Oh, a month?
Yeah.
Oh, wow.
I thought it was like per year.
So, yeah, they're paying a lot of money to Amazon to do this
because it's so accessible.
It's so easy to use, and they're doing it at a fair enough cost.
You know, it's cheap.
Yep.
So what have you been spending a large portion of your last day or two doing?
So I've been pretty into Portal 2.
It was a lot of fun to play.
I won't give any spoilers.
Now do we need to spoil?
Okay, I was going to ask.
No, no, I won't spoil anything, although I will say that the story is amazing.
There are a lot of twists, which, you know, assuming that no one has spoiled it for you,
you will find very enjoyable, especially if you've played the first one, because it requires sort of
a lot of the knowledge from the first to fully appreciate the storyline. But yeah, so Portal 2
is kind of interesting. So they preloaded all of the data for the game onto your machine when you pre-purchased the game.
So in my case, I pre-purchased it about a month ago, and it actually loaded all of the content at that time.
And Half-Life 2 did this as well, but one thing that Portal did that's unique is they encrypted all of the data.
So, you know, when I got up in the morning uh the day portal 2 was
released i guess three or four days ago um i actually it took about an hour and it went through
and decrypted all of the data that it had downloaded and then also uh as part of decrypting
you know downloaded the executable and started running. Interesting. So what encouraged you, this is digitally available,
right? Whatever. So what encouraged you to pre-buy it, give them your money early?
So in this case, they gave a deal. So for, yeah, so for, if you pre-purchased, you could,
you get 10% off and you also got a free copy of Portal 1 that you could gift to somebody else.
Considering you probably already had Portal 1, if you were that interested in Portal 2.
Yeah, exactly.
So, yeah, Portal 2 actually had another interesting thing
where originally there was rumors
that they were going to release the game on Friday,
a couple of Fridays ago.
And then they decided, or on Friday they announced
that if you bought the potato pack which is a
set a collection of indie games for each for these little sort of achievements or little
aspects of these different indie games that you accomplished you know in one of them it was every
time you beat a level you would earn a potato and once a certain number of potatoes had been accumulated by the entire community,
everyone on Steam, the Portal 2 game would become unlocked.
Interesting.
Yeah, so this is kind of a double-edged sword.
A lot of people felt like, you know, we waited so long for this game,
and now you're making us buy these games that we don't even want to play
so that we can get to Portal 2.
But a lot of other people thought it was kind of fun
and a little ingenious of them to you know make some extra money and also you know provide some
entertainment and give uh you know give a little love to uh the people who make indie games so
yeah interesting now one thing i was thinking about when i saw that we were going to be talking
about portal 2 was the fact that i don't i guess it was a couple months ago
i could have been longer now when they originally had their release date and people were getting
all excited and then valve came out and said you know oh is it valve i don't know whoever yeah
valve okay they came out and said that um yeah it's going to be delayed sorry making software
is harder than we thought, or is hard.
And so I thought that was kind of interesting that they said,
yeah, this is hard.
It's going to take longer.
We're going to make it awesome.
We're not going to release it any sooner.
And that's interesting as a programmer, and I'm like, yay, that's true.
Making software is hard.
Oh, that sounded very enthusiastic.
So, yeah, I mean, it's really hard to do software estimation, you know,
saying how long is this function going to take to write?
How long is this level going to take to make?
How long is it going to take to test this feature?
It's hard to estimate that, especially if you're doing something, you know, new or never been done before.
Yeah, I mean, really, at this level, programming is almost an art.
And, you know, in general, you just cannot put a time on, you know, art.
It's just there's a level of creativity.
And often it's there's just no such thing as perfect, you know.
You can, you know, if you have a function and it needs to add two numbers or whatever,
then there is, you know, obviously a perfect answer to that.
But often things come down to.
Maybe not, but most of the time.
Yeah, it depends what world you're living in. But, you know, often things come down to... Maybe not, but most of the time. Yeah, it depends what world you're living in.
But, you know, often these come down to design choices.
And design is something that's never perfect.
It always comes down to your interpretation
and different designs fit different forms,
you know, more optimally or sub-optimally.
So, you know, optimally or sub optimally so you know yeah again designing
software and uh you know implementing software at a high level is very unpredictable yeah that's
true yeah it's true but yeah everybody always thinks we can do it we are able to predict and
figure it out and make a number even though the numbers are tend to mostly be really wrong
yeah yeah definitely.
Unless it's very similar to something you've done before,
in which case it's important, as much as we all hate the infamous M word, metrics.
They're terrible.
They can be useful because as you build up enough of a backlog of history
of what something was, how long it took you, what you thought it would take you,
you can begin to learn a lot and do that kind of introspection and say, how long, how have I estimated in the past
and begin to improve your estimates and get better at them and, uh, or compare with other
people and say, you know, what are you using?
What numbers are you taking?
But I guess a lot of companies treat it as proprietary, but you know, if your company
uses that or does that, you know, if they fuss you about metrics, sometimes there's
a good reason, not all the time, but sometimes it is helpful to make estimations better yeah i mean you'll
notice that a lot of the people who are in charge of you know cost and estimation are senior and
that's just because that's not something that you can really learn in school it's something that
you have to kind of just do a lot of software and get down to,
you know, make estimations that are wrong and find out, you know, along what dimensions did you
spend a lot of time and then what are the areas in which there is a lot of variability.
And so a lot of the senior engineers will kind of have a good understanding, just an intuition
on how long something will take.
Although we do like to complain that they make the estimates,
but then they don't have to do the work.
That's always a dangerous situation if somebody else gets to make the estimates.
Yeah, exactly.
Not the people having to do the work.
Yeah.
So on games, did you hear the rumors that were flying all around about the Wii 2?
Yeah, yeah.
It looks pretty cool.
I like how, you know, the Wii is sort of coming out of the gate early with the Wii 2,
considering that the Wii doesn't have a lot of the, you know, HD, you know, graphics capabilities as some of the other consoles.
So you heard any of, what are the good rumors you've heard so far?
Well, I've heard that it'll launch early 2012.
All right.
That's not that far from now.
No, it's pretty soon.
You know, the Wii, I believe you looked it up, right?
The Wii was the last one of the three. Yeah, it was right around the same time, I think, as the PlayStation 3.
Yeah.
But pretty close, yeah.
But I haven't heard anything about a new Xbox or a PlayStation 4.
No, no.
What is it going to be, Xbox 720 now?
Yeah, let's try the Tony Hawk version. Oh, or the 1080 4. No, no. What is it going to be? Xbox 720 now? Yeah, that's right.
The Tony Hawk version.
Oh, or the 1080, the Sean White version.
Yeah, that's right.
Yeah, so I heard that they were talking about
maybe having touchscreen controllers for the Wii
because that was a big deal that, you know,
the Wii 1 kind of forsook going the route of blingy eye candy
and instead went the route of having new intuitive controls
and having the ability to get up and dance around your TV
and look completely stupid.
But people loved it.
And when they did,
it kind of helped them capture a whole new audience of people
that weren't into gaming before, is the idea.
And that's pretty interesting that they did that. So it would be cool if they kind of continued that weren't into gaming before is the idea. And that's pretty interesting that they did that.
So it would be cool if they kind of continued that path and say,
everybody else now kind of has motion controllers, right?
And Xbox even has the Kinect, which has no controller to do the motion.
That's kind of cool, and everybody's kind of catching up.
So now it would be interesting to see if they're able to actually leapfrog everybody again
and say, yeah, we are totally going to do this new amazing thing
nobody else was even thinking about.
That would be pretty cool.
Yeah, one thing that Nintendo did,
which it didn't catch on just because of the price point
and the way that gaming works in the U.S.,
but it was pretty popular in Japan,
and it was actually awesome technology.
The GameCube had a thing where you could plug in gameboy advances
uh into the gamecube as many as there were players and um you would actually play on the gameboy
advance um and so there would be one screen so the gamecube would be on your tv just like you
know regular console and that screen would be shared by everyone. But your Game Boy Advance controller has its own screen since that's a portable console itself.
And that screen would be private information that only you could see.
So, for example, there was a game called Four Swords, Legend of Zelda Four Swords.
And it was a multiplayer Legend of Zelda.
And you could actually hurt the other players so that you could take their rubies.
So as part of the game, not only were you trying to get through the dungeon like a traditional
Zelda dungeon crawler, but you're trying to get through with the most points and that might mean
sabotaging the other players. And so they use the, you know, screens built into the controllers to,
you know, give you private information
and allow for these competitive games and these sort of treachery, treacherous games.
I think I remember there being, I don't think I ever played it that way,
but I remember seeing pictures of people in football games being able to select the plays on their Game Boy Advance.
Yeah, that's right.
And so the problem at the time was that, you know, you had to either buy four Game Boy Advances and a GameCube
or have three friends with Game Boy Advances who all wanted to play that game.
And so that was the challenge.
That's what kind of killed it.
You mean nerds had to actually get together in the same place and socialize?
Yeah, it was pretty much impossible.
So that was the end of that.
But I'm hoping with these touchscreen controllers that they will sort of bring back some of that.
That's a good call.
That's interesting.
That's interesting.
I also heard rumors that they were going to do 3D support, which is interesting because Nintendo 3DS.
I'll get it right.
Have you seen one of these yet?
Have you used one?
I haven't used one, but I saw pictures of it.
It looks pretty awesome.
Have you actually stood in front of one, though?
No.
I saw one in the store.
I couldn't use it.
It's really cool.
No 3D glasses.
You stand in front of it, and yeah, things pop out of the screen.
It's pretty cool.
I don't know how it would be long-term, but it's pretty awesome.
So if I remember right, it uses several layers of LCD, right?
And each one can be clear or a certain color.
And so the layers give a parallax that creates the 3D illusion.
Yeah, I think that's right. Something like that.
And it's adjustable with a slider.
Oh, really?
Yeah, so you can kind of adjust how much 3D it is.
I heard some people talking about some of the games are actually really useful
because it helps you give that extra depth perception you need
to be able to avoid a wall coming up or fly under something or walk around something.
It's kind of cool.
But Nintendo, with the 3DS, their whole thing is, right,
oh, we're better, no 3D glasses needed.
We're going to do this so that everybody can use it
and not have to wear silly-looking 3D glasses.
So it would be interesting if they decide to go with 3D glasses
to kind of go back on themselves.
Although it's not uncommon for companies to do that.
Apple does that all the time.
It would be a terrible idea to do this,
and then their very next product does exactly that thing.
Yeah, exactly.
So there's going to be a Star Fox 3D on the 3DS.
Remember Star Fox?
Yes.
Oh, man.
I think I might have to go and buy one right now.
Oh, no, no, no.
That would be kind of crazy.
Yeah, but I heard it was going to be called a stream as well.
But I remember, I don't remember what the Wii,
the Wii had a different code name before that I actually kind of liked better.
It was, oh, what was it?
I liked it better than what Wii was, I remember.
And then Wii came out and everybody was like making jokes about Wii.
But now that, no, I kind of like it.
Wii is kind of fun.
It's Wii.
I don't know, I kind of like saying it.
Yeah, and the whole Wii would like to play, you know, advertising campaign.
And the Miis, you make your Miis.
Yep, yep.
I kind of liked it.
I think it was called the Revolution.
That was the Nintendo Revolution, right?
Before it was the Wii.
Yeah, that's right, that's right.
Yeah.
I guess maybe, now in hindsight, it kind of seems stupid.
Oh well.
The time has passed and my opinion has changed.
So going from really high tech to somewhat low tech,
another story here is about this Lego assembly line.
Is that where they make Legos?
No, this is actually somebody taking lego and building an
assembly line out of lego what wait wait so they assemble legos with legos that's right is that
right okay okay i gotta keep track of this it's like it's like meta okay hang on keep going all
right keep going yeah i think this this as, you know, the first, like, reproductive organ that's ever been made out of Lego.
Because now he's able to, if he can produce itself, then we have a complete species here of Lego.
Uh-oh.
I, for one, welcome our Lego overlords.
That's right.
So, yeah, you guys should definitely visit the blog and check this link out.
Yeah, it has a killer video.
It sounds like the big dog robot walking because all these different Mindstorm.
Big dog's awesome.
Yeah, all these different Mindstorm parts, axes.
So can it rebuild itself?
No.
Or it just builds other things?
Yeah, right now it's pretty simplistic.
It only has four robot arms.
But I think it can build these little cars.
Oh, that's kind of cool.
Yeah, it can build like a block.
It can take Legos and build essentially a bigger Lego,
like a macro Lego block by stacking several of these together.
Yeah, I got interested recently in what I guess is called the RepRap, which is the idea
of a replicating machine that can replicate itself.
So it prints parts, and it prints parts for itself so it can make new itselfs.
Right.
And then that drives down costs, because if you can do it perfectly, you can end up making
them really cheap, because then you end up having lots and lots of things that can make
more of those things, up making them really cheap. Because then you end up having lots and lots of things that can make more of those things.
And, you know, it becomes really awesome.
And it's really clever because they have parts that at this point in time they're not able to print.
So, like, circuit boards, metal rods, screws, things like that.
Or things that are economically prohibitive to print.
And then they call those things vitamins, which is things your body needs but can't make.
So I thought it was kind of clever. And it's really interesting. Maybe I'll have to talk about that sometime. And then they call those things vitamins, which is things your body needs but can't make.
So I thought it was kind of clever.
And it's really interesting.
Maybe I'll have to talk about that sometime.
But, yeah, this sounds like not quite the same thing because it can't make its own self out of Legos, which would be even cooler.
But maybe it's a step in that direction. Maybe somebody will inspire it and make its own bootstrapping Lego factory.
And then one day giant Lego robots will appear outside of our house and knock knock knock we've come to take over give us your children uh-oh that would be good but yeah
you know it's really interesting how with lego mind storms you can do just about anything um you
know it's uh i believe lego mind storms it's its own language, right? Yeah, now I haven't, but I know that they have, in typical over-the-top nerd fashion,
I think people do a lot with it, but I think originally it came out,
and I remember it being a visual language,
so you actually had little parts that you would drop on for an if statement or a loop,
and you could drop those little blocks down and then it would
go to the little brain the controller brick or i'm not sure what their term is for it and and
it would control the other legos but now i think they even have the ability and then they had a
language you could write in but i think people even have where you can write and see now yeah
according to wikipedia you can write in java and see nowstorms, yeah. And so this is really interesting that...
So if you listen to our first podcast,
then you'll have the language C under your belt.
You'll know what you're doing,
and then you can go program a Lego factory to replicate itself.
Yeah, if you do that, definitely let us know.
We will have you on the show
if you can build a self-replicating Lego factory.
That would be epic.
Especially if you learn about C from us. Oh, yeah factory that would be epic especially if you learn about c
from us oh yeah that would be even better yeah yeah or tell your friends and maybe they'll learn
about c and then go do this yeah and maybe a year or two or three or four so yeah i mean a lot of
these robotics problems are problems that actually you'll encounter like you guys who are in computer
science at university or at high school uh you know, something like path planning.
You know, when you do path planning,
you might look at just a little, you know, circle in a maze trying to get through this maze.
And you might not be thinking about real applications.
You might think, well, when in real life am I ever going to be in a maze?
There was that one time.
A minute time?
Oh, man, that was rough.
I really wish we had a laptop there
to run for our lives but i should have studied better that a star algorithm yeah that's right
but um you know robotics the way the robot arm moves is actually path planning so you have the
robot arm sort of the positions that it wants to be in as sort of the goal the exit of the maze
and where it is now as the start of the maze and sometimes you know it has to be in as sort of the goal the exit of the maze and where it is now
as the start of the maze and sometimes you know it has to move to the right so that it can swing
to the left without hitting a wall with a different joint yeah exactly kind of like an octopus arm you
know so um uh there's an example of where you know algorithms that you see in computer science
school that you think you know who's ever going to use this?
And then you find out later in life, oh, everyone uses this, you know.
Plus, let's admit it.
Robots are awesome.
Yep.
Robots make anything cooler.
I think every comp sci class should have a Lego Mindstorm.
And lasers.
That's right.
And, well, I was going to give a Portal 2 spoiler.
No, stop.
Stop, stop, stop.
We'll just stop with robots and lasers.
And portals.
Okay.
I haven't played it, so if I give out any spoilers, it's completely accidental.
That's right.
So what is your tool of the buy week? So on robots and
building things and
atoms as opposed to bits,
my tool of the week goes a little
bit different with
the Texas Instruments MSP
430.
Don't you love it when companies name things
cleverly? Yeah, I was going to say
now I know exactly what that is.
Yeah, don't you? I'm so glad. That's just the mind meld that's going on here between ti and us um so so this is kind of
interesting um i've used before another product that's kind of in the same vein as this called
the arduino and the arduino is an at mega chip with a bootloader and a little board that comes
with it and for i think it's like 20 and an awesome
interface and they made it all open hardware and it's pretty cool and you can use it to do all
sorts of interesting things and there's a great community that was built up around and i really
like arduino people used to do a lot of things um but kind of similar to the lego mind storms
where people use stuff for more than it's intended to and kind of do a lot of work instead of picking
the right tool for the job or learning the next thing they use what they have and do really creative but if
all you have is a hammer everything becomes a nail right so um people use arduino to do a lot
of things that um are really clever and cool but it could probably be done easily more easily or
cheaper because one of the things is even though arduino is cheap at twenty dollars or so depending on what version you get um it's not something you
want to leave in a project or leave in something or you know because it's twenty dollars i mean
that's kind of you know i don't want to just go wasting twenty dollars all the time and so the
texas instruments response to that is to try to build up a community around some of their products
and and they do you know they're like you know dominant in the dsp market um for industry and so they say how do we get to these consumers because
these consumers these people in college they will eventually work in companies and they'll be able
to do stuff like you know themselves and plus these you know chips a lot of times are very
cheap for them to make so they can sell a kit for it, you know, more power to them, it's awesome.
And so this MSP430 thing that they have now, the launch pad,
oh, I guess this will actually be my tool that we use, the MSP430 launch pad,
is kind of an Arduino competitor that sells for $4.30 shipped to your door,
you know, everything included.
That's awesome.
So I can't recall when
i bought mine but i think it even had a usb connector in it so pretty much you have one of
these yeah so i have i have one of these um i've not done too much with it but it is pretty cool
oh it says 430 plus shipping maybe that's changed but i don't i don't think shipping's very much
it's pretty small but it's a pretty nice kit. And it's interesting because at only $4.30, a little easier to leave that in a project now.
And it's not exactly the same as Arduino, but it's kind of similar. And, you know, we do a lot
of open source tools for the free things for the tool of the week. But this is something that's
really cheap and really cool because I remember being in, you know, high school and being
interested in electronics
and making things out of magazines.
There's not a lot of that today at that level, but there's a lot of stuff on the internet
today that we didn't have when we were growing up.
And so something like this, when you're younger, your parents don't necessarily mind giving
you $5 for something or whatever.
And then use their permission and then maybe they'll let you, they can put in their credit card information for you so that you can get one of these.
But that's pretty cool for $4.30.
There's a lot of stuff you can learn with this.
Writing code in C, actually, it might do C++,
but they give you a version of their Code Composer,
which is their product that you use for like the higher end dsps that that
you know people use that there are jobs and stuff and they provide that and you're able to use it
to write c code to do stuff like you know play with instead of just making a loop that prints
hello world that's kind of cool but yeah i don't know there's something different about writing
instead of print hello word turn le toggle led like it's just cool it's just
nice to see something in the real world other than your screen you know doing awesome things
um hooking up a servo and making watching it move or you know affecting things it's it's fun it's i
don't know i'm kind of into hardware i know you're a little bit more uh high level software than i am
but yeah i wish you know it's something I want to get more into I just I'm
kind of ignorant on it right now but I am really interested how does it so I might show the
ignorance here but let's say you have a servo that you want to communicate with yep do you have to
buy a TI servo or I mean is there a library or how does this work so um on the MSP430 there probably
is example code out there if not not, it's not that hard.
But no, so what happens is servos are controlled by something called pulse width modulation,
which this is a programming show, so maybe this is out of context.
But oh, wow, we're going to learn something new today.
Yeah.
So pulse width modulation, which is given a set,
and I'm going to flub this up for any electrical engineers listening,
so tune out now, please, andume this in about three to four minutes.
This is like an anti-spoiler.
It's like we know we're not going to spoil anything good on electrical engineering.
Yes.
So the idea is you've got a set rate.
So let's say, you know, every one hertz you're going to have a cycle.
Once per second, just to make it easy.
It would never be that long because that would be too much delay between signals.
But so you have one second cycle rate so
the servo will say for instance center position it will be a 50 on 50 off so if 50 of the pulse
width so that time of one second if for 500 milliseconds the pulse is high and the rest is
low it's going to be centered in the center position of the servo
because the servo goes from a plus degrees to a minus degrees.
It normally doesn't do continuous rotation.
If you make the signal less than 50%, you normally have it centered in your window,
so it's a little hump in the middle.
So if you have it for 250 milliseconds, that, depending on the servo, could be full over left.
And if you have it for 750 milliseconds, that could be full over right.
And so varying that width of the pulse allows you to control the position of the servo.
And then the servo holds its position once it's there by itself.
It knows if you keep sending that pulse, it knows how to stay there.
And if somebody tries to go move it or push against it,
it'll try to move back to the right place.
So it's a closed loop thing in itself.
And that pulse width is a way of communicating to it.
So in that way, you can buy any Pulse Width modulated servo, and it'll work.
Now, there are newer servos which communicate, for instance, like on I2C or something,
which is another protocol, so it wouldn't have to be specific.
But you just kind of got to know.
And other people are out there doing this stuff.
And you can buy servos really cheap online.
We're talking like $1, $2, $3, $4 five dollars you know i see a lot of servos for five dollars they're not great servos
but you can make a move and do little things and um yeah so a lot of times you can find sample
code to do it i don't know if the msp430 has but a lot of the dsp chips have a library set up to do
pulse width modulation where you basically just say my cycle length is this time and my current
pulse width should be this and then it handles all the rest of it for you oh so it's got its
own like wild true kind of thing going on there and it's in hardware so that you don't have to
waste cpu cycles sitting there because if it was using a cpu you kind of spent a lot of time trying
to sit there managing making sure it's right this way you can kind of tell the hardware go do this
and then it just sits there and does it for you cool that's awesome yeah i want to make i want to just just get started
making really simple things like something that would like unscrew a bottle you know bottle cap
or something like that and uh get started so maybe i'll pick up one of these launch pads yeah so um
launch pad is my tool of the bi-week and yours nice so my tool of the bye week. And yours?
Nice. So my tool of the bye week is along similar lines, along the lines of getting into hardware.
And so the tool is SketchUp, Google SketchUp, which SketchUp by itself is just a 3D modeling tool,
but it doesn't do texturing. And it's not focused on texturing as most tools are and on authoring, you know, 3D content for, you know, video games or for movies. SketchUp is about
drafting and it's about sort of designing something at a high level. So that's why if you
see SketchUp, you know, models, they'll often look very flat.
And that's because what you're seeing is what's the focus is really on the geometry of the model and not so much on how it actually looks.
You're not going to find a ray tracer.
You're not going to find lighting and mirrors and all these fancy things that you might in RenderMan,
which makes Shrek in those movies.
But if you want to just rapidly prototype, it has
an extremely slick user interface
and it knows
that because it's a
design tool, that the geometry is
not going to be very complex. You're not going to try
to model someone's face in SketchUp.
So
it lets you
mess with the different vertices
and different geometry at a low level,
knowing that you're not going to be dealing with millions of these objects.
And because of that, it gives you a lot of flexibility.
So SketchUp actually integrates with something called the Thingamatic,
which is done by MakerBot.
And you can buy this Thingamatic kit,
and it'll actually work in tandem with SketchUp to produce 3D, I guess, lithographs. Is that the right word?
Printed.
Yeah, basically 3D, like real 3D models.
Yeah, it extrudes little bits of plastic.
Yeah, so you can, in SketchUp, you can make a model of uh you know a sphere or
try and like grow your you know make them design a model of your hand or or a model of a little
spaceship and uh you can export your sketchup model to maker bot and it will actually construct
it in 3d out of a plastic resin yeah so i I wasn't paying attention that this was your tool of the week.
So when earlier I was talking about the RepRap, that this is kind of the same idea.
RepRap is similar to the MakerBot.
It's not the open source version of the MakerBot, but an earlier version of the MakerBot, something
that...
How do you spell it?
RepRap.
R-E-P-R-A-P.
Okay.
And so this is one that is, you know,
with kind of the intention of bootstrapping itself
that I was talking about.
It does kind of something similar to the MakerBot, though,
where it prints things out of what,
I guess it's rods of plastic string,
goes into a little extruder,
and it puts little dots at a single layer.
Then it moves the platform down or moves the extruder up and then places another set of
little dots.
And slowly, you know, layer by layer, it builds up.
So, kind of like an inkjet printer.
But instead of, you know, the paper moving out, the head moves around and then the platform
and head separate and then it prints again, slowly building up the structure.
Nice.
So, interesting. I don't know if you've seen this before, but, you know, the Thing-O-Matic is a 3D printer. head separate and then it prints again slowly building up the structure nice um so interesting
i don't know if you've seen this before but you know the thing-o-matic is a 3d printer and then
the thingiverse which is thingiverse.com is a collection of 3d models a lot of which have been
done in google sketchup yep and people put these things up here, open source, you know, repository of them.
And then they have it so you can print it with your MakerBot or with your RepRap
or sometimes with a laser cutter and make these things that other people have made
and make them yourself.
So the idea that, you know, one day in the future, I want a coffee mug.
I don't have a coffee mug.
You just go over to your printer and you go to, you know, Amazon.com
or maybe you go to one of these Thingiverse, a free one, and you download a free coffee mug and then it just prints
it on your printer. And then five minutes later you come and there's your coffee mug ready to use.
Yeah, I think this is a really exciting time for us, you know, computer nerds because,
you know, for example, I wanted to make a PDA that was completely open source. And it was a really big pain. I had to get the
circuit board. I had to get a little LCD display. I had to make those two talk to each other. I had
to write my own driver for the LCD display. I had to get a version of Linux, blah, blah, blah,
so on and so forth. But then once I had done all that, you know, software engineering work,
I ended up using Lego. I had to build a case for my PDA and not knowing anything about hardware or woodworking or anything at the time, I used Lego and made this giant PDA that barely fits
in my pocket, but plays Dwarf Fortress out of Lego and gumsticks board and lcd so but now the technology has come so far that
for you know it's still it's still a little expensive the thingamatic is thirteen hundred
dollars and the other one is uh the rep wrap is what around 800 yeah i mean it just depends on
what level of kit you get but i think yeah all up once you pay for everything, it's going to be about that. But, yeah, for about $1,500, you could have something which constructs the shell of whatever you want.
The electrical component, you can get that for $4, as Patrick showed,
and the different servos and motors and sensors that make up, you know, that part of your design.
But we're in a position where you can prototype just about anything as a hobbyist.
I mean, if you need it to be stainless steel and you do arc welding,
well, you might still be out of luck.
But, you know, you could do just about anything nowadays,
and I think that's really exciting.
Yeah, and I've tried my hand at things like SketchUp and others and found I'm pretty terrible at it.
Yeah, me too.
But what's cool is some of the people doing this printing are writing computer programs to make the files to print.
So I saw one guy the other day ran Conway's Game of Life and let it play out over a whole bunch of iterations
and then kind of kept a history of everywhere where it went and printed out a 3d model of like a representation of a run of game of life
and um that was kind of cool or you know procedurally generating a 3d model and then
printing that out so you know like a fractal generator or um like a what is it sarah
impitsky's gasket right in 3d and then that out. So if you're really nerdy but are terrible at drawing stuff and making stuff on SketchUp,
then you can write programs to make the models that then your printer can print.
Yeah, and Patrick made another good point earlier, which is both SketchUp and MakerBot
and probably the RepRap, too, have a library of existing models.
In fact, SketchUp has a massive, massive database.
And you can get everything from buildings, famous buildings, you know, completely modeled in SketchUp,
all the way down to, like, you know, a model of a hand.
You can get different, like, I don't know, tools.
You get those scissors that, you know, you can download just the model instead of having to make it yourself yeah can i print a house to live in maybe i don't think you could
print a duplicate of your house though because your house has the printer in it and you would
have to print the print of my house i think this was an xkcd. That's right. Uh-oh.
The model would have to be in the model.
Would you have to be in the model?
No!
Uh-oh.
So don't model perfectly every detail of your house.
That's right.
And then try to print it.
Yeah, that would fail.
Or model it.
Yeah, bad idea.
Yeah.
So I'm going to give a shameless plug here to Endless Forms,
which is close enough to what we were talking about but
endlessforms.com is a website that's run from a couple of colleagues of mine out of cornell and
this is a evolutionary computation program for generating three-dimensional art so uh i don't
really know how to describe this but basically you start on there and it just has
these random geometries of different circles and patterns and you can kind of see what they look
excuse me what they look like in 3d and then uh you kind of you have you you pick from this
population like oh i like okay okay so i'm here now and i see one that says mushroom so what do i
do so what you're looking at when you go on Endless Forms,
these are the top-rated forms that other people have made.
So they've evolved them, or they've made them?
That's right.
So you click on Start Anew.
It's going to give you a set of individuals.
You pick some parents, and you can mate them and see what their baby would look like.
Interesting.
Oh, okay.
So it's giving me a bunch of random ones.
Right. look like interesting oh okay so these are just giving me a bunch of random ones right and so the
hope is that in the same way as you know the fast line catches the prey and natural evolution
survival of the fittest propagates in the same way you know that the shapes that you find the
most pleasing or the most amiable for this session will start to propagate and you'll end up you know with your own species of 3d shape
so these guys are going to be at the gecko conference this year showing off their their
forms so if you have some time go to endlessforms.com and generate some cool things and
they will add them to the to the display section at the conference.
Interesting.
Yeah.
Although it's kind of interesting that all the popular ones are ones that resemble real-life objects.
Yeah, it is. It's sort of...
As opposed to things that are...
You know, you would have thought people would have been interested in things
that are like, oh, that's clever, but new or different.
Yeah, yeah, it's surprising that...
You know, I think people are, at this point, yeah it's surprising that you know i think people are at this point
since it's so early people are just happy that it can generate things that look like other things
well cool that's cool all right and you know you could uh in theory if they give you the model
which i think they do you can uh import that into sketchup and then export that into the Thingamatic format,
and then print it on a 3D printer.
Ooh, that's cool.
Yeah, good stuff. We better be careful, because if you print something sentient, we could all be in trouble.
Yeah, bad news.
Bad news.
Or if you print a Klein bottle, it might just be stuck in an infinite loop.
Ah, no, that would be terrible.
Yeah.
All right, so I think that ties us up for our tools of the bye week.
Cool.
So I think we're going to be talking about MATLAB slash Octave this week.
So why don't we start off talking about MATLAB, since that's the first of our pair here.
What does MATLAB stand for?
Yeah, so MATLAB stands for Matrix Laboratory.
And so MATLAB is an interpreted language,
and it's meant to be sort of a laboratory or a playground for nerds like us
to sort of go in and do matrix operations.
So a lot of linear algebra, a lot of analysis of data, which is quite
often stored in matrices. If you've ever used Excel, and Excel has a grid of cells, and
a matrix also is a 2D grid of cells. So if you've ever used Excel, you've worked with
something sort of analogous to a matrix, and it turns out that matrices are just very popular and almost
ubiquitous in mathematics. And so this is sort of a place where you can go in and try different
functions and do analysis at a high level. So MATLAB refers both to the language and to the
product? That's right. So, you know, the scripting language that comes with MATLAB shares its name.
And so often it can be a little bit confusing because you could say I'm talking about MATLAB, but you're talking about the code.
Or you could say I'm talking about MATLAB the product.
Oh, okay. So people use this? It's pretty popular? Yeah, so MATLAB is hugely popular, especially in the market of people who are sort of analyzing data.
So linear control systems, guys who are doing servos, as Patrick was talking about earlier,
and trying to create systems, robotics, tend to use a lot of MATLAB.
People who are analyzing data, trying to generate statistics and regression and things like that, are definitely using MATLAB.
Interesting. It's also really popular in school.
I remember in university that everybody seemed to be using it. All the
professors at some point, just like all of a sudden, all the professors assumed you knew MATLAB.
And I was like, no, wait, what? MATLAB? What's that? Yeah, I got burned by that, too. I went into
image processing. It was a master's class. And yeah, he said that everyone will program their
assignments in MATLAB. And I'd never seen MATLAB before.
And, yeah, everyone has to kind of go through those moments.
You know, in our case, it was MATLAB.
Maybe some other people had the same situation with C.
But everyone goes to that moment where it's like, you know, you walk into either a job or a classroom,
and someone says, everyone's doing everything in blah, MATLAB, Erlang, whatever.
Oh, I would love it if I walked in and somebody said, we're going to do everything in Erlang.
That would be pretty intense.
Yeah, it would be a challenge.
But one of the cool things about, you know, programming throwdown is that, you know, we're going to keep throwing down these languages.
And at the end, we can get to the point where if you walk into a job interview and they say, here, we only use Haskell, you can step up to the plate and swing a home run by saying, oh, yeah, no problem.
That would be pretty cool.
So, yeah, so I remember when the first time my professor said, we got to use MATLAB.
And I went online and like, all right, well, let me download MATLAB.
And then I was like, oh, wait, hang on.
Where's the download link
and i went to the math works the company that makes matlab their website and like
where do i get this and then i finally found a link and it said oh student version i'm like oh
yeah let me get that one and it said a hundred dollars and i went what a hundred dollars for
what what is this for my class oh Oh man. And then I quickly scrambled
to find out that, you know, oh yeah, some, the university has an agreement to have it on their
computers. And so I could go to the lab and use it there and avoid having to pay the a hundred
dollars. But I know a lot of people who had to buy to have it on their computer.
Yeah, definitely. So this is, this is Not so much in programming languages, thankfully, but it's common in the workplace and academia where you'll end up with vendor lock-in.
Vendor lock-in.
Yeah, vendor lock-in is the idea where...
That sounds like a German word, vendor lock-in.
It's happiness at the discomfort of others. Oh no, that's Scheidenfreude. But vendor lock-in is where, you know, you've started to use a product, say MATLAB.
Let's say you've used a free version of MATLAB at your university.
All right.
And so you become very acquainted with MATLAB.
And I write awesome programs.
That's right.
You write a ton of MATLAB, and then you and some guys get together and say,
you know what, we're awesome at MATLAB. We're going going to start a company and we're going to do linear systems consultation boring
yeah worst company ever so so uh just kidding if that's your company we love you okay
programming throwdown at five stars so um so so your company now is has had in its history an ingrenation of MATLAB.
And so you're sort of, you know, for you to switch to another tool set,
let's say you want to switch to Java or something,
you'd have to rewrite everything.
All of this code that's been built up over the years.
I think I had that job when I was an intern.
Converting MATLAB to C or Java?
No, converting one language to another
that was really old something new oh rough uh yeah so this is vendor lock-in in other words
matlab sort of has you in a position where you have to keep continuing to use matlab and to pay
mathworks um to you know to stay successful as a business the cost of changing is worse than the cost of continuing to pay math
works yeah exactly so so matlab is really powerful i mean where where i work that they use it all the
time you know just tons of people use matlab it's really powerful they really love it they use it
for doing prototyping stuff yeah um we'll get to some of the slowness problems later and why that people like you and I continue to be employed if everybody else could just use MATLAB.
But so what is a person to do if they don't have a lot of money, if they don't want to be locked in?
I mean, are there alternatives?
Yeah.
So MATLAB, the language, has actually been re-implemented by another group,
and it goes under the term Octave, or specifically GNU Octave.
And so Octave is an open source, completely free and open source,
implementation of the MATLAB language.
And they advertise that any MATLAB program, any.m file, you should be able to run in Octave.
Interesting.
Yeah, so the one thing that Octave, they're starting to come up to speed on
but haven't quite fully flushed out yet is all of these toolkits that MATLAB has.
I get one of those in my garage.
Yeah, so this is sort of the bread and butter of MathWorks.
They actually generate most of their business from selling these custom toolkits.
And if you remember when we talked about Python and Erlang,
we talked about their standard libraries.
Batteries included, I remember.
That's right.
So what did Erlang do?
It was OTP, right?
Yep.
Yeah, and then Python has...
Open Telecom Platform.
Yeah, and Python has a standard template or the standard Python library. But, you know, in the case of MATLAB, MATLAB relies on toolkits and they actually sell each toolkit or the majority of them. They sell, you know, one toolkit.
So what is something that would be a toolkit?
Yeah. So image processing, for example, might be a toolkit.
Oh, yeah.
Sometimes people do like to use images, use matrix to represent them.
That's right, yeah.
Yeah, so if you think an image is a 2D grid of pixels of different colors,
and a matrix, as we mentioned, is similar to Excel.
It's a grid of values.
So they both can kind of, so a matrix can easily represent an image.
And Matrix MATLAB's image processing toolkit comes with a bunch of functions that let you do different things like histogramming and blurring of images, doing convolutions.
So these are all things that you could write yourself though right right so just like the standard library in python and erlang all of these like these toolkits are implemented in matlab
now i'm talking about the programming language so you could easily write these toolkits yourself
but this just saves you the hassle of having to write this and then ensuring that the code is
sound and things like that interesting but so So the difference, though, is to reiterate, I guess, what you're saying is
Python is free and the library is free.
Right.
Erlang can be had free and OTP is free.
MATLAB is not free and does not include the toolkits,
which extend the functionality because you have to pay for those separately as well.
Right.
Now, Octave is working on, I think it's called OctaveForge, which is a repository of open source toolkits.
And they've tried to mirror as best as possible a lot of the MATLAB toolkits.
So there is an image processing toolkit for Octave.
And actually, when I did the image processing class, I used Octave and the image processing toolkit for Octave. And my
professor didn't even know that I was using Octave because he was still getting the.m files
as my homework assignments and running them in MATLAB. You're a brave soul, sir. I know. I always
wondered. It was sort of a risk I took, you know, when I submitted the homework, if there was a
compatibility issue and I'd get a zero but uh but i can say a sample size
of one but uh you know i did use octave and uh trusted it and it worked so good awesome awesome
so these toolboxes you said are written in matlab files are they all written in matlab do they
are all these dot m files are there other things that aren't written in matlab
is matlab bootstrapped?
Can you write a MATLAB interpreter in MATLAB?
Is that how it's done?
That's interesting.
I think you could do that, right? But most of these MATLAB toolkits are written in C or C++,
and there's something called a MEX file.
And this is actually something that we didn't talk about too much in the past,
but it merits some discussion which is the idea of extending the language or binding um um you know
c and c plus plus code to the language is that like handcuffs yeah it's kind of it's a lot like
going to prison sometimes it can feel like feel like you're in prison when you're writing extensions. Oh, okay, okay, all right. But no, for example,
let's say you use the Zlib compression library
and you want to do Zlib compression inside of MATLAB.
So what you want to do is get at the Zlib C code
from inside MATLAB.
And that involves writing what's called a MEX file,
which sort of lets you
call C functions using the MATLAB virtual machine and so Python has the
Python C API that lets you create PYD files which do the same thing so you can
write C code and as long as you follow the Python API you can get to those C
functions and variables from the Python API, you can get to those C functions and
variables from the Python interpreter.
Interesting.
And the same way with Erlang.
I don't know the specifics on that, but you can do the same thing there, and in MATLAB
you can do the same thing with MEX files.
So the majority of these toolkits are written in C or C++ with just the MEX wrapper around
them.
That's pretty cool.
Pretty cool.
So MATLAB is an instance where they do write it in something else instead of writing it in itself.
Right.
So, you know, MATLAB...
And it says here that GNU Octave is written in C and C++ for sure.
Right.
Yeah, so most of MATLAB is written in other languages, in lower-level languages.
But there are parts which are written in just MATLAB.
Yeah, so is MATLAB, here's a question, I'm going to put you on the hot seat.
Oh, here we go.
So is MATLAB a compiled or an interpreted or a semi-compiled language?
Well, okay, so let's use what we've learned on the podcast so far so sounded like i heard that
it it did some sort of pre-looking at it almost like the python files so it doesn't completely
just interpreted so i'm and i'm pretty sure it's not completely compiled so i'm gonna go with the
hybrid between the two yeah definitely, definitely. You got it.
Oh, I need a buzzer sound on my ringer.
Bing!
Yay! What do I win?
You win another question.
Is MATLAB statically or
dynamically typed?
Ooh, good question. Yeah. Have we even
talked about this? I don't think we have talked about this.
This is a first. Maybe you should introduce
typing. Okay, so oh, I don't know. Here we go. We'll try. So, static versus dynamic
typing. Well, let's try to give it short and sweet. Okay. Because we could go on a long time
about this. And there's all sorts of variations in between and all sorts of which one's better
than the other. And as I think our stand is on this podcast, we're all about right tool for the
right problem, you know, expanding your
toolbox so you'll be able to solve the problem with the best tool possible. And I think dynamic
and static typing fall into that, something that is appropriate for different situations.
So dynamic typing, and you correct me if I'm wrong, basically means the first time that you
have a variable. So I have the variable letter X and I say X equals 3
the compiler at it or the thing that has to run the program if I don't tell it
what X is has to look and say oh you're sticking the number 3 and X that must be
and then at runtime dynamically has to decide oh that must be an integer or if
I said 3.1 it has to say that's a float or a double.
And then later, being dynamic makes the thing that's running
at the interpreter have to work a little harder.
But then later, it allows me to do things like
then I could set x equal to the string hello world.
And it can change it for me and say, oh, look, now x is a string.
And x doesn't even have to really be a
string as long as it knows what's stored there and what currently is there. Versus static means,
and this is something that's common to like C and Java and C++, means you have to actually say
what type of variable is when you declare it the first time you kind of use it. And so instead of
just saying X equals three, I need to say
int x equals 3.
And telling the compiler, the interpreter,
this variable is,
shall be, and shall remain
an integer. And that gives
it some opportunity to do
enhancements, but means that later on I can't
decide, oh, I want to reuse x
in the same scope and make it a string
now. Because I go, whoa, whoa, whoa, whoa, whoa, whoa, whoa.
You told me that was an int.
Can't make it a string now, buddy.
That's right.
Yeah, so one of the things about dynamic typing is that it can create a lot of runtime errors
because you can do things that you didn't expect, things that would be caught at compile
time.
So, for example, going on to what Patrick was saying, if you say, let's say later on in your code, you have, you know, z equals x plus y.
If x is three and y is four, then, you know, that's fine. It can do that addition. But if
in between there, you say x equals hello world, and then you try and add hello world and four,
that's going to cause a
runtime error. Now, you know, in a language with static typing, it knows before it even runs the
code that x is a string or an integer. And so it knows that when you've done x plus y, that
combination is not valid. You can't add hello world and for. It doesn't make sense. So a dynamically typed language gives you more freedom,
but at the same time allows you to make a mistake at runtime,
which can crash your program.
Oh, okay, interesting.
So back to the original question, MATLAB, having done a little bit of it,
I think it's dynamic.
That's right.
Yeah, MATLAB's definitely dynamically typed.
Because I've definitely said, you know, A equals X transpose and not had to tell it what it was.
In fact, I don't even know what it was.
Some matrix.
I don't even know what the type was.
So it must be dynamic.
Yeah.
Yeah, definitely.
MATLAB's dynamically typed.
And that gets to a topic that's a little interesting on virtual machine latency.
That sounds bad.
Yeah, this is sort of the Achilles heel of MATLAB.
As Patrick was alluding to, this is how we see in C++ and Java guys have jobs still.
And, you know, let's look at dynamic typing, for example.
MATLAB does x plus y.
So let's just look at that function.
It has to know what x and y are.
And then based on that, it has to call a different addition.
So if x is an integer, if x is a matrix of integers and y is a matrix of integers,
it has a certain function that adds those two.
If x is a matrix of floating point, x and y are floating point matrices, it has a different
function that operates on floating point. And so for every instruction that you execute in MATLAB,
it has to do a lot of thinking, as opposed to C, where every instruction corresponds to one or at most a handful of machine code, of assembly code instructions.
And the compiler only has to do a lot of thinking still, but it knows a lot and it only has to do it once.
And then it generates an executable which can run many, many times.
Right, exactly.
So, you know, in the case of C, for example, or let's look at C++.
C++ has a function called find where you can give it the beginning and the end of an array and a value to look for. And it'll return if it found that value or not.
That calling the find function is about the same, will take about the same time as looping through the array yourself and looking
for the value.
Okay.
But in MATLAB, calling the find function is much, much faster than looping through the
array and looking for the value.
So if you're looking for five and you just call find my matrix comma five, that will
return instantly.
But if you loop through your matrix...
Literally instantly?
It'll return in nanoseconds.
Or let's say...
A short amount of time.
A handful of microseconds.
But if you do, you know,
if you have a gigantic array
and you write a for loop in MATLAB
that just loops through the array and checks for five,
that will take on the order of seconds.
So it will take, you know, a million times longer for you to loop through. And that's because
you're executing a million times as many instructions. And each instruction has this
VM, virtual machine latency, has this overhead associated with it.
So that's because each time when you do the find, you just have to look up the applicable
function to call once.
But when you're looping it over, every time it gets there, it has to try and figure out
what it's doing because because it's dynamic, it could have changed.
That's right.
So that, you know, if you're doing it yourself, you loop through the array and you say, you
know, does the matrix at this index equal five?
And the matrix might have changed, like the variable might not be a matrix anymore.
The matrix index might have changed.
Maybe that's not an int or maybe something weird has happened to that.
What it means to index a matrix, it has to, you know, look that up.
Versus in C, the compiler has done all that.
And it's just coming down to is this address
equal to five and that's a single instruction on the CPU. The value stored at this address equal
to five. Right that's right so yeah so you know the VM the virtual machine overhead in MATLAB is
extremely extremely high and that's why a lot of things that are prototyped in MATLAB, but are meant for
like a production environment, are then recoded in C or C++ or Java or some other language that
doesn't have this overhead. So from what you tell me, you know, I'd be kind of bummed about MATLAB.
Sounds kind of like, why would I pay this Math math works company money to have it or go to the effort of using gnu octave instead of just using cr python but i've had a lot of people at work tell
me how awesome matlab is and then they tell me that they are using like like you got to do a huge
sparse matrix computation and i my eyes cringe thinking i'd have to go write code and see to be able to do that.
Or they're doing some Fourier transform. And I don't even know. It's so complicated. I had to
look at my textbook to figure out what it was. So why are these guys saying that MATLAB is really
powerful and they're able to do those operations fast? Yeah. So MATLAB is extremely optimized. So the way this works is, let's say in MATLAB
you want to add two matrices together. You don't have to use a for loop like you would in C
and loop through all of these matrices and add all of the different values at each index together.
You can just say, you know, if you have matrices A and B,
you could just say C equals A plus B. And what MATLAB does under the hood is it recognizes that they're matrices and it has a very optimized C version. So in other words, someone maybe that
was their full-time job was just to write this function that adds, you know, and does arithmetic
on matrices. So they might use SSE instructions.
That's right.
So it'll check and see what the capabilities of your computer are.
If your computer supports SSE instructions, which stands for, what is it, SIMD extensions,
standard SIMD extensions.
And maybe we'll talk about that when we talk about C++ or something.
Yeah, that could be a whole topic in itself probably.
Yeah, yeah, definitely.
If your computer has any of these extensions, it'll try and use them.
If your computer has a GPU, which is something maybe we'll talk about later,
it can use the graphics processing unit to do some of these matrix operations.
And so MATLAB will sort of query your hardware and say, you know, based on your
configuration, I can add these two matrices even faster using X, Y, and Z. Versus, you know, if
you're writing in C, you're probably just going to write the addition code in for loops and that
it won't use any of these optimized hardware. I see, I see. So if you're using their functions and using them in a way,
so Fourier transform, they've gone in and made that thing awesome.
Right.
If I go code one, mine will work and probably beat by far the one that you write yourself in MATLAB.
But they've already taken time to go write one that's kick butt,
and it'll sure kick the butt of my code.
Right.
I mean, those guys make a living just figuring out how to do matrix arithmetic and Fourier transform and cosine transform and things like that.
There's people who that's their job. they're naturally, they're going to do it and test it and optimize it much better than someone whose job is to do image processing.
And they're just having to do Fourier transform as a consequence of that.
So they are, you know, the positives of it is they have the expertise of the low-level, you know, architects that design MATLAB.
They have that going behind them, even though they don't necessarily know how that stuff works under the hood.
So what about Octave?
So MathWorks has a number of employees.
I don't know how many.
I'm sure a lot.
And they sit here and do all this awesome stuff.
And you said earlier something that I thought was interesting.
Octave is a re-implementation of the MATLAB language or an implementation of it.
It's not MathWorks one because they obviously can't use MathWorks code.
That's protected.
And they probably can't even look at it because then some of it might accidentally end up in there
and they could get in all sorts of trouble.
So they recreate all
of that stuff. So how does
Octave speed compare to MATLAB?
So
Octave, from my limited
experience, Octave is a little slower
than MATLAB. There was
a time where I did take some of my code
and
run it on MATLAB,
code that I developed in Octave.
I noticed it was slightly faster.
But a lot of the limitations that we've talked about, I mean, a lot of the,
especially people who are novices like myself at MATLAB,
the slowness or the speed will be a result of using too many lines of code and just hitting the
virtual machine too often. So for example, you might want to do something that you think is very
complex. Like, for example, if you want to loop through the matrix and if the value is greater
than 0.5, you want to do something. So you might think, how am I going to do this without a for loop?
Because there's logic here and I have different branches. And MATLAB will actually do those
things. There's single commands that can sort of return all the locations that are greater than
0.5 or greater than some threshold. And if you're clever in MATLAB, you can reduce the number of
instructions you're giving it and still do really complicated things. And if you're clever in MATLAB, you can reduce the number of instructions you're giving it and still do really complicated things.
And if you're doing that, your code's going to be very fast, whether you're using Octave or MATLAB.
But yeah, overall, MATLAB, because they've spent so much time optimizing for different computers,
is going to be a little bit faster.
Well, I think that's a pretty good overview of the two languages.
Do you have any other comments?
You know, we kind of talk about learning sometimes,
but MATLAB, Octave, I mean, there's tons of stuff out there,
lots of good stuff, a lot of books written, a lot of professors use this.
There's a lot of tutorials on university websites.
Yeah, that's a good point.
If you're in university, chances are one of your you know
electrical engineering computer engineering classes is going to have a you know intro on MATLAB
often they won't teach it to you you'll have to you know they'll leave it up to you to read it
but at least they'll have the material there and I know that at UCF and probably even at UF
that stuff's public so you could even get on the the UCF website and read their tutorial on MATLAB without being a student.
Awesome. Well, you want to close it out there?
Yeah, unless you have anything to say about MATLAB.
What about applications?
Like what kind of stuff?
Did you use MATLAB on your Arduino?
Probably not, right?
No, no.
Yeah, so, you know, we talked a little bit about projects using Erlang last week.
That might be a good segment.
But then for MATLAB, it's a little hard to use.
People don't – there are some GUIs and stuff written.
But because of the nature of most people using MATLAB from MathWorks that, you know, people don't want –
they can't give you a program to run necessarily
without you having to buy your own license.
That's expensive propositions.
There aren't a lot of applications written in it.
But yeah, I mean, I've used it in school,
especially in some at work for doing,
like you said, a lot of image processing.
That was a use for it.
Also doing some linear algebra type stuff
like optimizations and stuff there
and some controls stuff was was there as
well so yeah i used it for a number of those kind of projects i never had to write anything that was
a substantial line count or a big complicated project because it's just not really one time
i tried to make a gui but it's just not i didn't find it well suited for that right yeah i've
noticed the same thing that matlab doesn't really sort of play well with others
in the sense that, you know,
you can write, as we talked about, those MEX files,
but the interface is very cumbersome.
And MathWorks, you know,
they're in the business of sort of writing extensions for MATLAB.
And if they make it really easy for you to interface MATLAB
with other aspects of your system,
then they're sort of working against themselves there to some extent. But with that said,
MATLAB is a phenomenal tool for prototyping, for doing data analysis. One thing we didn't
talk about, but MATLAB comes with a graphing tool built in. So you can actually go into MATLAB or Octave.
You can download Octave right now, type in sine of x,
and it'll actually display a graph of the sine wave on your computer.
And so that is just all of this extra visualization tools
that you don't get in many languages.
It makes it great for doing a quick prototype
before jumping into C or C++.
Yeah, definitely.
Yeah. All right. Well, if you haven't checked out our blog at programmingthrowdown.blogspot.com,
make sure to check that out. Also, if you haven't left a review for us or given us a star rating,
please go ahead and do that. If you us make sure to tell us if you hate us
well you can tell us that
too rate us five stars because we're so
hate inducing
so yeah go ahead and leave your and those of you who have
thank you a bunch it's really encouraging
helps us keep our spirits up and wanting
to keep doing this and hopefully
we'll continue to hear back from some of you about
what you like or what you don't like what you'd like to see in the
future what you'd prefer for us to stop doing,
how much you love Jason or how much you love me.
Either one will work.
And, yeah, check it out.
Yeah, if you don't give us any love on iTunes, we might have to start Lacrimology,
which is a religion that this is off Wikipedia here, a religion that supposedly
embraces pain, and
it's released through crying as a means
to move to a higher state of being.
This is... Okay,
with that, I think we're
going to be done. Until next time!
Alright, have a good one, guys.
Keep on programming.
The intro music is Axo by Binar Pilot.
Programming Throwdown is distributed under a creative commons attribution share alike 2.0 license you're free to share copy distribute
transmit the work to remix adapt the work but you must provide attribution to patrick and i
and share alike in kind
