Hi guys, I'm gonna give you a quick crash course tutorial on MathLab for
first timers or approximately first timers.
When you first open MathLab you're gonna see stuff like these,
get rid of these as soon as you can, that's just getting in the way.
You can still use them, they're still there, you just have to hover.
This is the command window.
You can use it like a calculator.
Do all of your code immediately, and get response back.
I like to open up a script, and open up the editor so I can write a script.
And it's really clean in here.
And then you can evaluate, over in the command line.
Notice, they're right next to each other.
You can see.
All the code heightwise.
You can actually do this as well, minimize the tool strip if you wanted to.
I've already got a file here that we're gonna run through.
And then go through all of this as quickly as possible.
So just pause, rewind if you have to.
When you start evaluating code in the editor, you can set these break points
here to evaluate up to that point, and then you can continue stepping.
You can also set modify condition, so this is a Boolean condition here.
So to run, I like to use hotkeys.
This is function F5, to run.
Or you can just use one of the arrows, up here, when there's a run arrow.
Anyway, so now that it's running in debug mode,
I can continue stepping by clicking this or just use the hotkey.
So this first line, I stored a row vector,
an array in a row into x1.
And it goes from minus 2 pi to 2 pi.
Or at least it's supposed to go from minus 2 pi to 2 pi.
It defaults, when it's just one colon there,
it defaults to integer value increment.
So you see over here it went from -2 pi but it didn't quite
hit positive 2 pi because the incrementation didn't allow it.
So the next line here allows it to do that because I
enforced the conditions that it reaches a total range of 4 pi.
And it reaches that over 13 increments, so there was a total of 14 points.
And if you look at here, X2, it goes from minus 2 pi to 2 pi.
And he's our way to do this without having to think about how to increment,
is just to use the linspace command.
And you just tell it how many points you want.
This one, in this case, it's 14 points that it's identical to this, x2 and
x3 are identical, if you look over here, they're identical.
Just easier to use lens space sometimes.
There's also log space.
I created lens space again, and using these for later.
100 points for log spacing.
This log space gives me ten to the zero to ten to the six.
So it goes from one to a million over a hundred points.
So if you see, you look over here,
this is the very largest number,
it's a 1 times 10 to the sixth, it's a million.
Here's a matrix.
It's a this is the first row, second row, and they're separated,
rows are separated by a semi colon.
This a row vector B, this is a column vector C.
The same values just one is a transpose of the other.
It was three by four matrix of zeros, three rows, four columns.
Matrix of ones, three by three identity matrix.
Now, when we started doing matrix operations,
let's take a look at how to solve this, A times Y is equal to B.
If we know A and we know B, how do we solve for Y?
So we invert A, so I'm gonna grab this and put it down here.
This operator says, invert A and operate on B.
This is going to give me an error because the matrix dimensions must agree,
which means MathLab doesn't know how to operate a matrix on a row vector.
So this row vector for the least,
the less obscure mathematical operation, which is just matrix
multiplication that has to be a column vector, it has to be a column vector.
There's also a way to do a row vector here but it's a more
obscure operation, out of product of some sort.
MathLab doesn't know how to do it unless you massage it.
So you come over here and you put this transpose operator, this tick mark, and
that'll allow it to do the correct operation.
So that gives me a solution.
My solution Y for this linear system.
And then YY is gonna be the same thing because C is already the transpose of B.
[COUGH] This is to check to make sure that I get
B back, so there's B back.
When I got my solution Y.
Now here if I have an array of input values into this function,
then this function automatically loops through all those values, so
you don't have to write your own four loop.
So that's the output here is the sign of every one of those individually.
Now I'm gonna use these down below here.
So this dot here
doesn't mean dot product it means element wise multiplication or
in this case element wise multiplication, down here it's element wise division.
So it just takes the first element here multiply it with the first element here.
Second element here, multiply it by the second element here, and so forth.
And stores it in W.
So if you look at the size of w, compare it with the size of either Y1 or Y2,
it doesn't matter, they're both the same size.
And size returns all dimensions.
As compared to length which I have suppressed the output so
I have to actually bring it over.
Let's say for example, length of B, B if you look up here,
B is 3 by 4 and C is 4 by 3.
So the length of either of these
is the same because length finds the longest dimension.
So going into the plotting,
you can just call up the plot function and it brings up a figure.
Applies to that figure, you can come in here and insert labels, title, legend and
all the stuff right here if you wanted to but
I suggest since we're gonna be coding a lot just get used to writing your code
to do everything for you at least as much as possible.
So there we added a title to it, we added a label.
Now if I wanna add another plot to the same figure
I have to hold on to the figure.
[COUGH] So then I can throw in another plot under that same set of axis,
let go the figure.
Just because I've let go of it, you might assume that you can now
start another plot and it'll create a new figure for that plot, but it doesn't.
It overwrites on top of this, it writes to the same figure.
So that's an obvious problem, the way to get over that is by explicitly
calling the figure, this is just a quirkyness with MathLab,
there's probably a way around it, I just, I'm not aware of it.
So create a whole new figure, and then plot to that.
So it's the same thing with subplot.
If I just start subplotting, it's gonna write over the top of this figure.
Then it's gonna create a subplot axis or set of axis and
then it's gonna plot to that set of axis and it's gonna tie it all to that axis.
Now this X label, notice how I've done this, it's a carrot for
a super script and then an underscore for a subscript.
And the curly braces are if you have multiple characters that you need to
include in the scripts, in the subscripts, super script.
So then the subplot it says make me a 2 by 1 region
and here is populate in the first region and
now it's populating in the second region, these plots.
So there's the second region of the plot, title, label, okay?
So if I continue going now since I have called figure again,
this is going to override this and that's fine because I'm done looking at all this.
Well okay, so notice that it didn't override the whole thing,
it just overwrites the current axis.
So this is an exponential.
We have a linear set of points on the input and
then we have the exponential set of the output.
I want to get rid of, I want to look at this on,
let's call our new figure, whoops.
So now I can look at both of these if I choose to at the same time.
So notice how I have.
Just gone from plot to send their log Y.
So it suppress the exponential growth in the Y direction by scaling
it logarithmically.
Now, if I give inputs that are growing exponential and
then the output is exponential of the exponential input.
It wants to be a double exponential growth.
So let's see what that looks like.
Well, the problem here, you won't be able to see it, unless we plot it.
That's a straight line, notice the X-axis here
doesn't come any where near the largest X values of X log.
Remember this is, one million is the largest value.
So what's happened is it's gone to the maximum that this can possibly go to,
on the Y value.
That's the maximum it can go to, before it thinks that all the numbers are infinity.
So this actually goes infinitely higher, and this goes much further to the right.
So this is a totally garbage, a total garbage plot here.
It doesn't, it's meaningless.
So I'm gonna rescale, I'm gonna create
X log small enough that it'll actually plot those values.
So now you can see, I should probably get rid of these dots.
Let's replot this new set of points.
Just a default solid line.
So this is, this actually is the exponential growth
of the inputs and it goes over all possible values of the inputs.
So that's still not very appealing to look at so
let's create a new figure and suppress the logarithmic or
the exponential growth in the X-axis now.
So we we semi log X and notice that I don't have
to repause a million times, but let's do this.
So it is an exponential growth, it's doubled the exponential because the input
is, the inputs are growing exponentially and the output is growing exponentially.
It's tough to see it's exponential because there, it's doubled the exponential.
So if you have a doubly exponential growth,
the input and the output then do log log.
And that shows you the exponential characteristic.
All right, that's about it for this video.
The next one will go into more depth.