Transcripts
1. Introduction: Hello everyone and welcome to Introduction
to MATLAB course. This is engineered,
done and I will be your guide
through this course. Matlab, as a word stands
for Matrix Laboratory. However, it as a program, it is a programming language
developed by Mathworks. Started out as a matrix
programming language where linear algebra
programming was simple. It can be at on both under interactive sessions
and as a batch job. This tutorial, it gives you a aggressively
agenda introduction of MATLAB programming language. It is designed to give students fluency in MATLAB
programming language. Problem-based MATLAB
examples have been given in simple and easy way to make your learning fast
and effective. As if do requisite,
you have to check your computer
specifications first, your computer should
have a graphic God, greater than OpenGL 3.3 and minimum processor
of X86 dash 64. In case you don't know these specifications from your laptop, you can just go
to PC details and you will see your
graphic card and your processor where
you can compare their addition with the
OpenGL three points three, and know whether MATLAB is
downloadable at your computer. Now you can go to
the MATLAB software downloaded and also have a license for short
as a prerequisite, you need 90 minutes of the time, because this course needs no more than 90 minutes
to be learned as an introduction for
you to be able to run MATLAB as the beginning
of the audience. This tutorial has been prepared for the
beginners to have them understand basic to advanced
functionality of MATLAB. After completing this tutorial, you will find yourself at a moderate level
of expertise and using MATLAB from where you can take yourself to the next 11th. This is really essential. This course was
designed in order to give you the main basics. Where do you will be able to
investigate in each topic of MATLAB and study
it all by yourself. This is really essential
because you can see dividend MATLAB courses that are narrowed to a certain topic. This course gives
you the basics of everybody think in
MATLAB and gives you the skill of understanding how MATLAB thinks and
work accordingly. Why learning MATLAB? Matlab allows you to implement
and test your algorithms internally developed the computational codes
also easily debug, easily use a large database
of guilt and algorithms, but assess still images and creeds, simulation
videos easily. So I'm going to make it
simply a simple quotation. Matlab is simply the best. And always at each update
is getting better. It makes your life easier. As someone who needs MATLAB, this course is really
essential for you. Additional advantages
of MATLAB is symbolic. Symbolic computation
can be easily done. Call external libraries, again, import any other library
needs related to different areas of MATLAB before extensive data analysis
and visualization, such as simply
stating that you will learn inserting any
equation and it will plot your graph developed application with the
graphics user interface. As an agenda, we will use
MATLAB as a calculator. We will write, we
learn how to override the variable appearance of floating point numbers
managing the workday. So you again know what are
the main sections of Matlab, where to go in case I need help, in case I'm searching for a certain command
where I can find this command and during multiple statements, also
mathematical functions, basic plotting which I previously talked about
the visualization, matrix generation
at a properties and solving linear
equation with MATLAB, you will learn how to solve
linear equation over 68910, the non-bird you want or
variables not being limited to the it that limits you to
three or four variables only. As a contact, I am
putting in your hands, my email, my phone number, and my LinkedIn
account in case you face any problem
through the course, in case you have any
question through the project that I inserted
at the end of the course, you can just contact
me at anytime. I'm ready to help. I wish you enjoy this course and wish you the best of luck. Thank you.
2. MATLAB AS CALCULATOR: Hello everyone, Welcome to
MATLAB as a calculator. Matlab, as we know,
is Matrix Laboratory. However, this doesn't mean
that it is not a calculated. It cannot compute and run basic arithmetic
commands such as plus, minus times and division
and a lot more. So let's prove this by just starting to plus
three, for example, just keeping the two plus three without any semi-colons
or any columns, just keeping it as a
formula with nothing. And running this section, the MATLAB understands
that I'm just trying to run something
without writing a true script. So I'm just using
it as a calculator. So two plus three
is very simple. It gives me five as an answer. Now, five minus two and run
this section, we got three. So the plus is similar to
the calculator and the plus, the minus is also similar. However, when it comes
to the multiplication, we use this star symbol, so two times three and run
this section, we got six. So we reflect the multiplication of two numbers with
the star symbol. Now, what about the division? The division is simple by
the right division slash, the right slash, and we run it, excuse me, I'm running
it as a script. Run this section, I get 0.667. So this is the main
arithmetic operations of a calculator, the plus, minus multiplication
and the division. However, matlab also considers the hierarchy of operations
or the preference. In case I'm pressing one
plus two times three, I get one plus two times three. So one, it stops. Plus two times three, it has a greater preference. The multiplication
and the division have higher preferences
in the hierarchy of operations over the addition, the plus, he enters two plus
two times three equals six. Then plus one, I get a seven. This is not the case. If, if I haven't the
hierarchy of operations, then I have one plus two is
33 times three equals nine. However, it will
show me the seventh. So I have the hierarchy
of operations. It's not dumped. It's
a true calculator. It has all arithmetic
rules and procedures. Let's take it to another level. What about 13 times two minus three plus
four divided by two? So we previously know that the multiplication start
first from the left. It goes to the division. So 13 plus two, I got it 26, then four divided by two, I get a 226 minus three. I get it 23 plus two,
I get it one-to-five. Let's run this section. I got it. However, there is
something that over or dominate own preferences
is the parenthesis. If I insert any parenthesis
in my operation, what is inside my
paranthesis or the main or the first operations
to build on. So times two minus
three plus four. Matlab will start directly
inside the parenthesis. Two minus three, minus one
plus four equals three. So he starts by inside
the parenthesis. Then he runs the normal
arithmetic operations from left to the right. Let's run this
section. I get 19.5. That's everything about
MATLAB as the calculator. Let's move on to
overwriting a variable and start with the beginner
phases of MATLAB.
3. Overwriting a variable: Now starting with overwriting evaluated, writing a variable, Let's start with finding, let's say D, B in the
lowercase, deep equal five. Then ending this slide
with a semicolon for MATLAB to understand that I
finished t equal five only. I'm not displaying t
equals five in case I kept it like this, it will form at t equal five. However, just d equal
five semicolon. Stopping this, I'm
overwriting a variable. Matlab understands that in case I had a valuable
and I want to change it if I am able to do so in case I did, dv equals six. Now, running this section, I won't have to equal five. I would have to
equal six because in the work space of
MATLAB, d equals 5. Second line, the following line, teeth with sex, it overwriting. There is a professional
way to overwrite, used as an increment
in for loops. This is a little bit
advanced in programming, so I would just
give it as an idea. I won't use it in this class. However, just keep it in mind. D equal, which means
five plus one. This refers that deep equal
five plus one equals six. So between Give me the
same answer, d equals six. By this, we've finished
OCO writing about it. It's a small section. It's not advanced, just giving you an idea
in case you were trying to write the script and you are stuck to
override the body. But just don't panic. Use the increment function
t equal t plus one. And the problem is solved.
4. APPEARANCE OF FLOATING POINT NUMBER: That MATLAB in the same
value of the same variable, the same input, everything, the same gun, show it in
different formats because floating point numbers or variables can be,
for example, 1.3353. How many numbers after the comma or after the
point I should include, I have 24 months, the format short and
the format long. We can use it simply. However, in the
advanced sections, when we will use the parent
and the percentage of, we will use another technique
in order to control the number of commas after
a float point number. Let's start by defining a float number x
equal minus 163.667. That's everything to know. What should I include? I have two formats, the format short and
the format long. Let's keep it in the format
short, then press X. Let's run this section. I get just minus 163.667
zeros added is 0. Even if it is short, he is programmed in a way that the short format includes
four numbers after the point. The, This is everything
in the short section. I can't control using
the formats anymore. However, in case I pressed it as format long and
I run this section, I get minus 1.636670 e plus 0. This is a scientific calculation
using a format long. In this case, it is just three
points after the variable. If you want, I can change it 7894 and then run this section. I got it in short format. In the long format
and the short format, I got it as just four points or four numbers after the point with rounding
the final one. So 667, the third, the fourth seven, is followed
by a number above five. So it rounds upwards
to minus 163.6678. This is when it comes to appearance of
floating-point number. Let's move on to managing
the workplace in order to understand where to work and how to manage working on market.
5. Managing the workplace: Arriving to the managing
of the work place session. Now I'm just showing you
what are the main features of MATLAB in terms
of visual where you can work where and
you got the answer, etc.. Let's start
with the basic. Here in the home, you
can create a new script. You can create a
live script where a programmers or
engineers mainly, if they are working
on a group project and they are working together, so they just save it on an online cloud where
they can adjust, adjust and have a
permission to edit, etc. You can create different
sections system, object, project figures,
applications, even. You can open a file
or similar file that was already registered
on your computer. You can import data. This is the workspace
where we have the main variables and here you can create
a new variable. However, without just
pressing this button, you can just say X equals five. Here I created a new variable, so this is not very useful. However, you can conducted in certain programming
issues and you can use also an open variable
when it comes to coding. This is a little bit
advanced and we will not interpret that now. And the Simulink
is also advanced. When you give an equation that runs over a period of time, MATLAB is able to conduct this equation and chose
and ends up with a graph or that a final result that
shows how this variable is changing with time corresponding
to other variables. When it comes to the
environment and the resources, you can just ask help. If you have the
license for MATLAB, you can learn MATLAB
from a resources that MATLAB group has suggested. Also, you can request
a support and certain definition
and certain commands. You are not comfortable. You are not succeeding
with something. You can just ask MATLAB about
the main technical problem. And also we have
a community that access MathWorks
online community. This is when it comes to home. The Blots are another section where I will and interpret it. So in the second
level of this class, after three or four sections, we will start
plotting some graphs. And here you can see that
we can change the area, we can turn it into a board or scatter or a pie histogram. We have different types, a lot of MATLAB types that we can use when
it comes to the apps. Also, we have different apps that are integrated
using MATLAB. If you have a good and you are studying numerical analysis, this is a little bit
advanced in math. You just use the code
fitting and it will generate a fit for the good according to
different studies. So you can choose a
optimization be idea. Junior This is oriented to some mathematical
operations, not in our case. Just learn how to run
MATLAB and the editor. This is where our
main workplace is. Here you can create a new
script, you can save it. You can run it as a final
script where you can save it. Also here we can run a section. This added part or a
section is also important. For example, here
I use the command, you can use the uncomment and I can run it
as a command here. You can wrap the
commands, you can indent. The indentation is in the
loops and advanced levels, not at this level. You can insert the section, you can insert the
function or even a file. When it comes to the publishing, the publishing returns to when you are finishing
your final script, if it is 1000 or 2000 lines, not in our level, as simple as that, you can just create some board
or italic or more spaced, insert a line markup or
you can just publish it to your you can generate a formatted output such as
file from editor document. This is not our case. I'm not interested in that. And this is a little
bit more advanced. The U.S. is just simple. You can break your
editor, for example. I will go to custom and break my editor
into four sections. This can be used in case you
are working on different. Sections at the same time. You want to see your valuables and then the same time you want to work on a workplace order, on a function so you
can use it as it is. This is very simple, but
this is when it comes to managing the
workplace from outside. However, what is the inside? The editor. Here I
write my script. Let's say two plus
three and stop. This is my script and
hit the command window. When I run this section, I get I will get five. However, let's say I
finished two plus three, two minus one, and then
I run the section. I will see that the
five was not deleted. It's always present
on my command window. What should I do? What should I? How can I clear to my command window by
its simple function? Returns to C LC,
which means clear. Or you can just
press it here and clear command window from this button. This
is very simple. However, I have another command
that give more details, which include the size, the space allocation,
the class of variables. Let's say two minus
one and I run. Excuse me. And I
run this section. Then I press W.H.O. and it. I got that a a. Answer b c t x y. So he defined that I
have no variables. Your variables are
a answer b, c, t, x and y. I have no variables, so I'm not benefiting
from anything. However, if I press as
x equal to then uh, t equal x minus one, then I run this section. I will get t equal one
if I press w h all. And until I get that my variables are the same
where I have no answer. This is everything when it comes to managing the workplace. Let's move on to
another section.
6. ENTERING MULTIPLE STATEMENTS: In studying multiple statements, what does it mean getting
multiple statements? We can see that if I
set a equal to seven, I run this section, I get eight equals seven. However, if I put the semicolon and
breastfeed exclusively, the section, I get
nothing because MATLAB understand that
the semicolon stops. I'm not wanting anything. I'm just I deemed to some data. This is the case
of the semicolon. However, this does not apply to the normal column that we have. In case I want to say. And then I can just add or keep a colon between them and drawn
dissection in a very simple way. This section, I will got to be equal to two
and c equals three because he understood that
I defined a, B, and C. However, I won't
done on my dominant. I did not add any semicolon. If I press this semicolon
here and I run this section, It's clear the window
before the section, I get just the because
he understood Okay. Anc are defined. However, I won't be on the top. That's perfect. But if it was not a shown
of the command window, does it mean that they are not present in mind
MATLAB and memory? Let's see, let the window
in the first case. Let's return to the US semicolon and saying a times b minus c. And let's, let's
run this section. I will get 118
times b equal to 14 minus three equals
0 and solve one. Just entering the variable
does not mean if it wasn't shown on
the commandment go that it is not in the
memory of my MATLAB. Matlab understand that,
okay, 87, however, my user doesn't want it to be shown on the terminal
because he simply, for us the semicolon. So this is a benefit
when it comes to entering multiple statements.
Thank you for listening. Let's move on to a very
interesting topic.
7. MATHEMATICAL FUNCTIONS: No arriving to the
mathematical functions. But before getting deep
into this section, I want to go to
PowerPoint and show you the mean elementary
functions that MATLAB have as a
pre-defined functions. In case I want to
define the cosine, I have to use that
COS acts the sign S-I-G-N acts dangerous TA
and acts the arc cosine, arc sine the arc
tangent are the same just by adding an a
before the main function. What about the exponential? If I want to use an exponential, I have to use EXP. And the x, the square
root is referred to as SQRT and the natural logarithm and the common logarithm or
log us and blocked on x. This is when it comes
to the first section, we have a second
section concerning the absolute value of a
variable, the signum function. In case you have a row
of different numbers. For example, a having A123. We'll give an
example about that. I want to ask MATLAB, what is your maximum value
inside this section, he tells me the minimum. The seal on the floor
are rounding functions. For example, if I have 2.3 and I want to use it as a seed, I will have to either three and the floor
will give it to me as to we will see it now
also using examples. You can use the round to round
it to the nearest integer. The remainder after division
is referred to as REM AKS. You can use phase angle
and complex conjugate. These are advanced
mathematical functions or elementary functions
that you can use a directly without implementing the main
function of cosine. Now what about the
predefined constant values? We know that in math we have different values that already they are defined, for example, the main and the main obvious and well-known constant
value is the pipe, which refers to 3.141591, etc. So it is referred
in MATLAB as PI. However, what about the
imaginary unit or the radical of minus one or square
root of minus one, you just refer to it as I and j. He understand that, okay? This is an imaginary unit. J equal is an imaginary unit. What about the infinity? The infinity is
referred to I and f, and this is sometimes used
when you are rounding. For example, you ask
MATLAB to round this, round this value to the
infinity or the plus infinity, you just use the INR and NaN, not a number in case I'm
defining in an advanced section, my number 76, etc. I just tell him that
this is not a number, NaN this is my phone number, not a value that you can use. You have to use it as a basic
statement such as name, for example, Alex are drawn. Let's go about, Let's go deep into the main
mathematical functions. Let's define three variables. Let's say a equal to
five and x equal to two. Y equals to eight.
Anybody is simply way. Let's start conducting.
Let's say Y, this Y is equal to exponent or exponential of minus a
times the sine of x, sine x sine of two plus ten times
square root of y. That's a very complex
application formula. Let's, let's run it. I get 28.2904 in a
very simple way, just defining some variables
and adding complex one, I got a value in a
very simple way. Let's clear the command
window and use another one. For example, if I want
just simply log of 142, dissection, I get 4.9558. This is simply, I
don't have to define so a equal to 142
then log of a. I can use it in a very simple
and fast way without any interventions
or any added lines. Let's use the lockdown. I got to 0.1523. This is the common lot. Let's see some other stuff. Let's, for example, dry. It's clear the command window, Let's try the sine of pi. We said that pi is a
predefined constant value, so I have to refer
to it as byte here. Understand that pi
equals 3.1459, etc. So sine pi divided by four. Let's see the value. I get 0.7071. This is totally correct. Let's run it as cosine. I get the same value. Let's say as tangent
of Pi minus four, I should have one. What about the arc tangent? Let's say a cosine around the section 0.6675 arc sine. I got it Also 0.903040. I got 0.6658. However, if you can
see that, for example, if I press cotton, cotton and drawn
dissection, I get that. This is an undefined
function codon for input arguments of type W. This is another in my file that it is well-known
as untitled. And the third line that refers to cota and
pi equals four. I know this is wrong
because the cotton is well-known in
month one over time. What should I do? I
should stand of pi over 41 divided by turn
of pi over four. Run the section I got the one. This is the proton because
the ton of one over four, pi over four equals one. This is not the case here. If I change the boy, let's say pi equal
to, excuse me. Let's run this section. I get one plus 63, et cetera. In case this is the
first to infinity. If I wanted to divide
it to get the code, I should almost get a 0 because tan Pi over
two is really large. So I got a very small
number which refers to getting the 0 value for the
cotangent of Pi over two. So I know that MATLAB
has a lot of functions. However, some functions can
be replaced with others, such as the cota that
it is barely used. Let's remove or clear the command window
and run other stuff. Let's start by the
exponential of ten. For example, under Section
I got exponent of ten e to the power of 2.2 to the times ten to
the power of four. Let's change the
variables that I have or let's modify it
a little bit dumb. Let's say I have a
equals to minus 5.5, and then a b equals to 2.3, c equals to 4.9. And then ending that, let's move to the other
section of the table. What about the absolute? Let's clear another type. What about the absolute of a? I just press abs of a and he gets me to running
this section and give me 5.5. What is the sign of a section? He tells me it is negative one. So sine of a equals
a times minus one. Let's talk about the
scene of b of b. And then run this section, I get three because the
scene shows me or round the number that I inserted
to the plus infinity. Let's press it on a and C. Answered it is minus
five. Minus five. It is between minus five on the plus infinity and minus
six on the minus infinity. And that's why he
showed me minus five. Let's use the floor
section would shrouds the variable or the number to the minus
infinity floor of B, let's say undrawn this
section I will have to float of B is two
because it is between 23. The flow shows me two and
the sealed shows me three. Let's try some stuff. Let's move on to
the round function. And the round function, there is an automatic
rounding of the variables. Let's say round off to
0.3 and see what I get. I will get to because let's clear window to make it clear. Don't run this section
I will get to because 0.33 is lower than five, so it takes me to
the minus infinity, and so rounding to 0.3 is two. What about the rounding? See, drawn this section, I will get five because
4.99 is greater than five. The same answer. What about a? A is five, I have
five then the zeros. Let's see what is the
defiled rounding of five. When it comes to MATLAB, I will get minus six and
always take it to the, to the lower functions
because 5.55 is a middle number that I
cannot act according to it. So I go to the next number here. 5.5 is referred to 00
is lower than five. I got rounding a is minus
six, about 5.55556. He goes to the first 15. This is middle. I can't decide. Second five is all submitted. I cannot decide. He goes to the third 16, okay, greater than five. So I'm going to the
plus infinity and now we'll get it
to the minus six. Clear. Now, run the section I get
minus six, that's perfect. Now and round a, let's clear it. My maximum because they are very important and they are well used when giving some
advanced operations. So you can get the minimum and the maximum value and
work accordingly. And in case you were
sorting, for example, if you have a Ford
or five values, 12367 and you are asking
MATLAB to sort it. He goes by an inner function
to the maximum value. He enters maximum value, he got the seven Dan, he remove it and then enter six, then enters four,
understood, etc. So let's say eight equal
number of matrix a 2345. That's perfect. The done, I say minimum of a run, I will get the
minimum value is one. Now what about the maximum of a? I got five. So in case I changed them like
six here, here minus 551. I run this section, I get
the maximum as six and the minimum is minus 51. That, That's everything for
the mathematical functions. Let's move on to
the basic plotting. This is also a very
interesting topic.
8. BASIC PLOTTING: No arriving to basic plotting, MATLAB has an excellent
set of graphic tools. Plotting a given data. Or the results of computation is possibility with
very few commands, without complex features and complex
programming commands, you are highly
encouraged to plot the mathematical functions and results of analysis
as often as possible. Because sometimes when you
get the results as in values, you cannot detect the trends. You cannot detect some
respective points through your equation. For example, if
you are computing this y equals sine x function, you can see that it is elaborating between
02 Pi the results, the plotting of your
results through graphs makes it easier for you to
analyze your final results. Trying to understand
mathematical equations, as I previously said
with the graphics, is an enjoyable and
very efficient way of learning mathematics. Being able to plot mathematical functions
and data freely is the most important step and
this section is written to assist you to do just that. Lets remove this
one and start by basic plotting how you
create simple plots. By creating simple plots, you just define some coordinates having different acts
and different twice. So let's say x equal 12345, then ending ed y equal minus one to
four, let's say five. By this I defined
five coordinates, 13, having x equal one and y
equals three minus 1324455. Let's make it as minus one to
make it just like monster. Okay, That's perfect. We ask MATLAB to plot it by just asking plot x and y and
running the section. It takes a little bit
of time and get me to figure with the
first coordinate. Have been x equal one
and y equals three, then x equal two, and y equals minus one, then x equals three, and y equal to the fourth one is the same and also the fifth. However, this is very simple. What about when we
want to ask Pi, ask MATLAB to plot something that it is referred
between two areas. For example, the sine or the cosine x functions are just limited between two endpoints, the 0 and the two pipe. How we do that? We just need to specify vectors. What interests me
and why it should work on the integer
between 02 Pi. So we create vector Ax. So I started by
creating vector x. Vector Ax is x equal what, 02 pi, two times pi. So it is in the
range between 02 Pi. However, I should add
the instrumentation. I should add something that
takes step on between 02 Pi. So I say 0 between two pi, then I have to increment
with pi divided by 100. So we can see this function. It yields a vector
that starts at 0, takes steps or increments
of Pi divided by 100 and stops when
to buy is reached. So x equals 0 pi
over 100 to pop. Now I just ask y equal sine
of x and then plot x and y. That's perfect two. Now let's drag this section
and see what we will have. From 0 to one, then goes back to minus
one and it returns, this is between 02 Pi. This is the sine x.
In a very simple way. I can change it to
cosine for example. And let's draw this section. I get the different code with
the inverse of the sine. Good, That's perfect
than now, however, if I want to export this photo, I chose just a graph or plot, not seeing any labels. How should I include
labels inside MATLAB? Stuff is easy. The
problem is also easy. I should just ask x label
is between parenthesis. I should include a single
quotation between it. I should ask or tell
him the xlabel. So I will say it
AX equal 02 times. That's perfect. What about the y label? It is in the same manner. Y label is between sine of x. That's perfect. Let's
run the section. I will get sine of x
and x between 0.2. And this is the labels. However, this is a graph. However, it doesn't
have a title. In a very simple way. I add title, title, parenthesis, the same
manner, the same pattern. Pattern is present. And between the single
quotation marks, I say plot the sine function. Let's run this
section now and see. Plot the sine
function as a title. I get the sine of x, x between 0.2 and Pi, and then it can be returned. However, if you can see
that this graph is blue, how should I do to, in order to change it? In a very simple
way, I got to plot x and y and add a valuable, which is by a comma, and insert the color, let's say, Gee, and run this
section again it as green. G refers to green. What about ADH,
which refers to red? We have diffident stop for
it in case I remove it. I just got the blue one, the random definitely one. That's perfect to know. What about multiple
data sets in one plot? What should I do if I have
different y's on the same max? Let's say x is between 02 pi on an increment
level of pi over 100. That's perfect. Didn't know, Let's name y as y, y1 and see it as
two times cosine x. It can be. Let's define y2 for example. And Y2 is the simple cosine
x semicolon to end it. Now, why three equals
0.5 times cosine x? Let's see what should
I have generated? However, plotting x and y
would return with an error because it will just show the simple acts that we
had, the first white. This is not the case
that we are plotting. So I go to say X and whom? Y1. Okay, That's perfect. Then I say X and Y
to X and Y free. Then I will end it. Let's remove the labels. Now. Let's just remove
the labels now. Drawn this section. I will have graphs, one referring to two
times x x cosine x. The second is cosine x and
the 3.5th one cosine x. This is the plot. However, what about some
specifications and the blood? What about specifying
line styles and colors? It is possible to specify line styles, colors,
and markets. For example, circles
plus signs, et cetera, using the plot
command plus plot IX, y-prime, than the
style color market. We have different colors, black, red, blue, green, cyan, and yellow than solid
dashed, dotted, dashed dots. And that no line. Also we have symbol
market, the plus sign, so it'd good asterisk, point cross square
diamond asset. So let's go back to the
plot between X and Y, Y1. What should I
include after them? I should include
after the comma, the style that I want between
two single quotation marks, I wanted as a double dash. Between x and y, y2, I will add double or
single quotation mark, and let's say one dash. Then after X and Y three, Let's make it as
dotted single marks, single quotation
marks, excuse me, excuse me, and double points. Let's run this section. I have now different types. X, y, y1 is double dash, x y2 is a single dash
and y three is pointed. That's perfect. No, let's
just add some labels. So the y-label parenthesis done single quotations and
between them cosine functions. That's perfect. What
about the legend? Let's add the legend
is two times sine x. This is the first one. Then comma. The second one is cosine x
with a single quotation. Then the third one is
0.5 times cosine x. That's perfect. Till now. Let's add also a title. So title refers to typical example of
multiple plots. That's perfect to know. Let's add some axis. Axis equals between
02 pi minus 33. So access is 0 to
times by minus three. The three added and
run this section. I will have first typical
example of multiple plots, not appealing because of
this cosine functions. I did not add any x-axis
because I have the legend, the legend one, it shows
me two times cosine x, cosine x and 0.5 times cosine x. That's everything when it
comes to basic plotting. Let's move on to what it is main important and specification
of MATLAB, the matrices.
9. MATRIX GENERATION: Welcome everyone to
matrix generation. This section is
really important. As I previously said, MATLAB means Matrix Laboratory. Matlab is one of the unique tools that
acts with matrices in a very simple and professional and complex
way where it can compute different types of matrices in a very
simple and few commands. Before entering deep
into the matrix, this section will be large. I'm going to define the vector. How should I include
a vector into MATLAB? If vector, a row vector
starts by brackets, done 12345, let's say, and ending with brackets, what is between done as an
either or either space, space, either semicolon
when it comes to space and column adjust at all. Now if I want to
run this section, I will go just in case
I put it as space. I will have the same
because space refers also, excuse me, the column
refers to a row. Now instead of row
pressing semi-colons, what we will have is a vector v, that it is a column. So V 12345. This is when it
comes to the vector. However, there is a very
simple and easy way to transpose the row into a vector. The transpose function or the transpose operator
is denoted denote, denoted by a single code. So what should be done as you convert a column into
arrow or arrow into a column just by pressing
V and a single quotation, you get it and run it. You will have it as a rope. Now, in case if it was a column, if it was at all. And I transposed it, Let's clear my command window
and run it as section. I will get it as a column. So this is very simple. Now let's go back to Dr.
indexing, vector, indexing. The first to checking the
index of each parameter. In case you work with other programming
computers or softwares, you will see that always
the index starts with 0, so one refers to index 0. However, in MATLAB, life is
more simple. It's simpler. Index1 refers to
the first number. No need to start it with
0 and the other stops. So let's clear the command
and start by indexing. So let's ask MATLAB what is on the first index
of the run this section, you will tell me what,
what about the third one? He would tell me three. Even if I changed here as seven, for example, I'm drawing this
section, I will get seven. So the third number, the number that I inserted. So what about asking
him what is in-between off the first index and the
third index I started by one. Differentiate the two points. I'm saying to him from one
from one to 40, I have 127. Let's wrap this section. I will have 127. What about from city
two to 53 to five? Let's try this section.
I will have 745. However, there is another way, if you didn't know the number of indexes that it is
present in the MATLAB. You just have to press it as from 32 and there's
no need to just ask or just start calculating
or measuring time. So 745, Let's return this to three because we ended
the index matrix. Now I will start with
entering a matrix, a matrix or a vector or
very similar matrix. Let's say a equals. It should start with a bracket. And then we separate
what is inside a row with columns or spaces
similar to the vector. And when you stop and you want to separate
between the columns, if you just have to insert
the semicolon sections. So let's say 123, semicolon 456, semicolon 789. Then we ended or we finish it with the matrix with
the brackets exclude. This is 123456789. It refers that on
the first row I have three columns in which
the first one is one, the second one is two, and the third one
is a three word in the second row I have 456, etc. Let's run this section. I will get a as I have it. Now. What about the matrix indexing? Changing what is
inside a matrix. Let's start just by
matrix indexing. In case I pressed the
semicolon and I want to ask MATLAB to tell me what is
inside a and the second row. Then on the first column, he would directly
tell me for brand, I would get bored
because this is a, I have on the second
row, the first column. This is for, let's
say for example, let's run this section. I will get eight, Let's 33, I will get nine. Even if I own 150, I will have three. That's perfect. Let's clear it. This is when it
comes to indexing. What about when I want to change what is inside my matrix, what is inside the matrix that
I injected or I inputted? One-off, let's say
three of three, this is dynein one. I want to change it into 0. What should I put? I press a three of three. So inside the third row, the third column, this number, I want to change it into 0. Let's run this section. I will have 123456780. This is, this can be done in a different way where you
can change the number. For example, if I wanted as a 0, let's run this section.
I will have it as a 0. I want to make it as one. I can do endless stuff using it. Now. Just keep it in mind that MATLAB understands the
matrix as the first letter, the variable that I inserted my matrix and that it
is in my case the a, then the eye, then
the number of j here, it changes this sector into the value that I
told him to do so. Now what about colon operator? Colon operator is another
section into matrix generation, but it is not a matrix, it is a vector. However, this technique
can be used in matrix. You can see or you will see how. Let's start by coordinate
operator, colon operator. I'm asking MATLAB that
I am defining UX. I want the values between 05. However, I don't want
it to be just randomly. I wanted add an addition
or a step size of 0.5. So he will tell me that, okay, I will generate for
you the numbers between 05 at a rate of 0.5. Let's try this section. I will have 11 numbers
from 0 till five. I will have each
difference, the 0.5. However, we have defined variables are defined commands such as the linear spacing. This is very similar to
the garden operator, but it gives control over
the number of points. For example, if I
said y equal to learn space from 0 till five, however, at a rate of 0.5. So he tells million
space x1 is, x2 is five. What is the what is the
tenth time step size is 0.5. Let's clear it before and
press the Run Section. I will have one times
0 empty WO vector. Excuse me. What's that? Okay, That's
perfect. Line space. Let's say it is like
that and run it again. One times 0 and a
double row factor, there is a problem that he is taking it in another section. Clear, let's say
linspace between 05 without inventing
the number of human no, directly that I should insert
100 number as a deaf child, he will tell me between
05 there is 100 number. I'm telling you them at
a rate of 0.05 or five. That's when it comes
to linear spacing. Linear spacing is used
when, for example, you are creating a router in a game or in an
operation that you want the equidistance
between 0 and then you just use the linspace and you indicate the number of
intersections or steps, the step sizes that you want to enter these values
in programming. Matlab also, now,
we talked about the colon operator,
the linear spacing. Now, what are those used for? I will tell you what
are those in matrix, because this section
is matrix generation. What happens is called
an operator in a matrix is used to extract
certain row or column. For example, if I
want to extract something from inside my matrix, Let's return a equal. You will understand
everything in a bit. 123, semicolon 456,
so we call them 789, and then the matrix
and the semicolon. Okay, going back to Matrix
generation and colon operator, colon operator in the matrix, I said before that it
is used to extract. A certain row of column. So the formula that it
follows is a between rows is between k and
excuse me, columns. So this is it, I want
to extract from a as it is a from row to row. And I specify these numbers
column till column. And let's say from column one, column two, and from, from row one to row two. From this six numbers, I want the first column,
the second column. Let's try the extraction. I say I have 12451245, the first two rows. From these first two rows, I just want the
first two columns. Now what about if
I want a full row? For example, I want the
second row all by itself. So I just directly put R2D2. I wanted from, I
want all the column. Instead of putting 123456, I just removed the 13. It just needed to be simple. So a2 comma. So in the second row, I want from which column
to which column or columns because I
kept them as void. Run section I would have
four or 56. That's clear. It in order to make
sure Run Section 456. The same is about the columns in case I want all the rows. And then I went from
column two, column three, he would take all the
rows than just the first, the second, third column. I run this section, I
will have to 35689. It is the same if I
inserted 123 Iran, the assumption section,
nothing differed. So clearing it now. Now moving to the
same matrix however, now I want to delete
a row or column. To do so, we use the same as matrix indexing that I use
in order to change a value. However, I have to insert
the anti operator, which refers as the opening and break, adding the brackets. So I say that I want a from the third row, from the first column,
the third column. So all the columns equal void. Now I run this section, I will have just 123456. Now it is, the dated is
no mode inside the a. In case I pressed of third
row and second column. I will have, let's
say run this section. I will have an error because
index position one exceeds ADA bonds because
must not exceed two. That's correct. The third row is normal
present I deleted it. It is no more than the
machinery of MATLAB. Matlab does not understand that. Okay, Now we want me back
to a, this is not correct. It drones according to
a flow of sections. So I remove this. Let's clear the command window. Now we deleted this row. What about restoring
this drug store the straw using
the same technique as creating the matrix. If you remember, first one
I said you have to start the matrix by first specifying
the vertebral not equal. Now, opening the
brackets, That's perfect. A equal, something. I open the brackets. What is my first true? My first row is
instantly the first row. All columns. This 1, first row,
all the columns. This is my first drop. How we separate between arrow and another row by a semicolon, the same as for the second row. The second row,
comma and thirst. Okay, That's perfect. This is the second door. I didn't change anything in it. Now, this is my third row that I separated
with a semicolon. I say, I opened the matrix 78, Let's say nine or 0. No, let's say night. Okay, that's perfect. If I want 78 unknown, now I close the brackets and run this section and
we'll have 123456789. Now in case I asked
for 33, for example, in a very easy way, I will close this section before we run this
session, I will have nine. Now it is back. I re-inserted in the
third row that I deleted. Before we finish the one comes to the matrix
deleting the story. What about transposing a matrix? Transposing a matrix
is very similar to the one that we used when
we transpose the column. If you remember the V
12345, that V prime. Using the single code, it turns it into a
column and vice versa. This is similar to a matrix. So I'm gonna clear, let's say, let's delete all that and a prime just running
this section, I will have that each
row became a column. So 123 became one
column, and 456, which is the second draw, became the second column, 789, this third rule
became the third column. And in case now I use a
semicolon and ask for a 50. For example. One, the first draw, then the third column. I will have three because a transpose does not
change the value of a. I didn't say that a
equal a transpose. This is not my case. I just asked MATLAB
to transpose a prime. However, I didn't
change my main body, but that we used before. However, if I said
a equal to a prime, now I'm Dy run this session, I will have it seven because
I defined a as a brand. Now there is like
that and 13 is seven. That's very important
to know what odd the sessions or what is the workflow that MATLAB use or understand one
creating your script? Let's move on to the
matrix generators. Matrix generators. We have different
matrix generators. Matlab provides functions, degenerates elementary matrices, the matrix of zeros, the matrix of ones
and the identity matrix are determined
by functions zeros, ones and what I respectively, for example, the eye. And it returns an m by n matrix with one
on the main diagonal, where i and returns an n by
n squared identity matrix. The zeros, it returns an
m by n matrix of zeros, the ones that are similar
to the zeros and m by n matrix of
one's, the diagonal. It extracts the diagonal
of matrix a and the red. I'm an iterator is an m by
n matrix of random numbers. I will show you that. For example, this is a, this is a, let's print it, Let's say display it on
the main command window. I have 123456789. What about if I want to
ask for the diagonal? The diagonal is 159, semicolon here, semicolon here, and ask diagonal of a split on determinant,
I would have 159. Now, what about at ended? Let's say we have it as referred rand a because
I did not define random, the random a pulsar. Now let's clear this
function and ask, for example, to create a
function g that it returns once. Returns one of 30 rows. How many columns? One column, so it is 111. Let's run it. I would have 111. This is the ones. So now what about C
equal i, i of three? If three, it returns, I previously said it returns an m by n squared
identity matrix, n by n, three by three when
it is identity matrix, so the diagonal is equal to one. Let's try this
section, 100010001. Now what about the zeros? So let's say d equal
to zeros of two. So two rows and three columns. So I'd have six zeros. Let's run this
section, but before, let's put a semicolon here. I will have six zeros, two rows of zeros, and the three columns of zeros. This one, it comes to
matrix generators. This is very essential
and it is a well-used and usually used when it comes
to numerical simulation, numerical methods
when you are trying to multiply a matrix with another MATLAB makes your
life easier because if you are trying to solve it
using gestured hand, you have to follow different steps and
different indentation. And do you have to check the adder and according
to the other, you have to change
your technique. This is not the
case using mockup. This software makes the life of a mathematician or a
scientist's way much easier, and it is unique in MATLAB. Let's move on to the
special matrices as we was, as we were talking about
mathematics and algorithms, matlab provides a number
of a special matrices. These matrices have interesting
properties that make them useful for constructing examples and
forecasting algorithms. We have different
MATLAB documentation. You can check them. The most
used ones by, let's say, mathematicians on
the Hilbert and the inverse Hilbert matrix
and the pascal matrix. These three are well used. This is everything when it
comes to matrix generation. Let's move on to another session on directly hope
that you understand, understood what matrix are, how we generate them, how we act with them, how we interfered, add, delete, we transpose it, how we check the index. This is really important
and really essential. And even the matrix generators
are also a very important, especially the diagonal,
the eye and the ones. Thank you for listening. Let's move on to
another section.
10. ARRAY PROPERTIES: Arriving to the ADA
properties in matrix, you should understand that even matrix have
arithmetic operations. Let's say for example, if I have a and B,
I want to add them. I can add a plus B or B plus a. It should be valid if the a
and B are of the same size. For example, if a was three by three and b
is three by three, it should be the same. However, if I want
to multiply a by B, it should be taken
into consideration that if A's that should be A's number of columns should be equal that B's number of rows. However, even this
is the same what I want a to the power of two. However, power of two, multiplication in matrices
have a specific command, so I won't interfere it now. Next in this video, let's start by the simple
arithmetic to plus and minus. Let's define a equals to 123 semicolon 4567
in column 6789, ending the bracket
semicolon be equal to done. 102030, semicolon, 405060, semicolon
7080, and then 90. Then I close the
brackets and ending it. If I say a plus b and display
it on their own section, I will have 1110 plus ten, plus 23, plus 34 plus 40. This is the same. If I
said Example b minus a, I will have it as
91827 different areas. I can do so because
as you can see, a and B are of the same size. In case I say, let's clear this window and show you that it makes an error. If I change 90, for example,
and drag this section, I will have another
dimensions of arrays being contaminated
or not consistent. There is another and the B, it should be 98. That's perfect when it comes to the arithmetic operations. Now what about the times,
division and multiplication? This stuff are similar to the vectors are used by a times, let's say C equals a times b. However, there is a
problem or there is something that
indicates for MATLAB, no pay attention MATLAB, this, these are matrices is
not simple variables. Actually just press the
point section point or the dot stars B, I will have under
display tan 409160, etcetera multiplied
each index of a by the similar or corresponding
index of this is the same. If I want, for example, p divided by a, this won't work unless I
should insert the dot. Cheap all its time because it's dividing by their relative. Now what about if C equals
a to the power of two? Should I include? Should I included?
Yes, for sure, you should include
the dot even if there were no matrices. And the same section, this is when it comes to the addie arithmetic
operations of matrices. Now, we have different
matrix functions. Let's start by, let's go to the PowerPoint and
see diesem, see them. Okay, I have this determinant. It is defined by DET. So the determinant
of a lead score, determinant, excuse me. Determinant of
mathematicians will know that this state unless numbered in order to
get the determinant. Now, the determinant of B, this is minus 1.5. Let's see clearly now and
go see another function. The diagonal March. She's a diagonals of a matrix. So let's say diagonal of I previously implemented
that in a different way. Not date, okay. Diagonal DIA on this
section, I would have 159. What about B? I will get a section
101519. Pay attention. If B, you press it
and the lowercase, you will understand
that there is another diagonal of the, it's made it another function. So please don't, I
just keep it as it is. Now we go to the eigenvalues
or eigenvectors. This is not our case. Let's talk about the
inverse matrix because avert matrix will be used in the next session
when we are talking about solving linear equations. So simply inverse of a. Run this section,
I will have it. This is really hard. When you see it on Matlab. You just make your life easy. All this very simple. Our other in life, this takes up to 2030 minutes
in conducting on hands. And there is a huge
probability of equation of adders and the huge
probability of confirmation, for example, 0.3153,
you just take 0.31, you won't take it as exact. So MATLAB make life in this
matrix as easy as possible. I pressed particularly
a command here. This everything went comes
to the array properties. Let's apply what we learned
an array properties and in matrix generation into solving real problems and to
solving linear equations.
11. Solving Linear Equations: Now solving linear equations, I know a lot of students and
a lot of people that use, that don't use MATLAB or
don't know how to use MATLAB, just conduct solving linear equations
using the calculator. However, in case that
the variable is, number of variables
increases above three or 44 or five, excuse me. Calculator is no
more a helpful tool and you just have
to conduct it on your hand just by
trial and error using numerical simulations
and linear equations. In MATLAB, you just have a
very nice tool using matrices and using other operations in order to solve such equations. What should be done is
let's assume that I have x, x plus two, y plus
z equals to one. And plus three is four, x plus five plus six, that equals to 17 plus
eight equals storm. So these are a comment, let's say to let MATLAB
and tell him No, this is just a command. Don't take it into
consideration. So what I have to
do is I have to create two matrices, a and B. Let's say a equals to what? The first row is, one index of acts
done than three. Semicolon, 456, semicolon
78, and then 0. Because index of Z in
the third row is 0. This is when it comes to a. Now we create the b
equals to one semicolon, semicolon one, which refers to the values of the
three equations. What we have to
do now is to say, or we assume that
AX equals to B. This is recumbent
AX equilibrium. What is the value of x? X equals to the borrower? The poet of minus one times B. This is inside parenthesis. We have two ways
in order to solve. The first one is we say a equal etcetera be
equal to etcetera. X equals the inverse
of a times B. Let's try it on the display. We got minus 111, so x equal to minus one, y equals one, and z equal to 0. This is the same if I said
x equal to a divided by b. Let's try section. Let's clear it in order
to let you see it. Let's try it. Now. I have minus 11
minus 0, which is 0. So by this, we can
solve linear equations. Let's say if I
changed those feet, four minus one, Let's see what will be the value to
be one minus 0.6667. In case I want to
add it plus four z. Let's say plus k. Here, a plus k, plus k, I have to change. So now it is City. Here it is two, and now we have 41. The values are 30
minus 34, minus one. However, now we have four
variables and three equations. I have to add another equation. Let's say two, x plus four, y minus set minus two K. I got it as equals to eight. I change 12334567841 semicolon to four, minus one and minus two. We changed here also to eight. Let's run it. I will have minus
5.94.61.21 minus 1.3. By this, you can add
as much as you want variables and you
will find a solution. Let's assume here minus plus two, plus two here, minus for odd, I have to add the value, let's say also a
command, x plus two, y minus one, minus one, k plus two odd equals
to minus five. I should change it now. So the first row should
include also minus1. The second row should include also to the third
row should include also to the fourth row
should include minus four. Also I have to add a new row, city two minus one, minus one. And then to afford I
have to change also the B and also in minus five. Let's run it. I
will have an urge because matrix
dimensions must agree. Let's close this one. I have, the minus five is here, then I close the brackets. Let's run this section. I will have four minus 4.13.5, minus 2.35, and minus 3.85. I can add as much as I want, I valuables using
equations and I can solve linear equations and just
a period of seconds.
12. Project Proposal: Welcome back everyone. I wish you enjoyed
all the materials of introduction to matlab course. I wish it was beneficial. And you acquired the
required knowledge in terms of MATLAB and matrices. At the end of each class, I suggest doing a
small assessment for yourself where you can see
what are your weak points. You can go back to the video. Reward should see
what is the problem. You can contact me
directly in case you face any problem or you had a big question or critical question concerning
MATLAB and the project. I can help you to overcome it. When it comes to the project, it will be question is small question relying of
two matrices where you have to perform
different commands that we learned all over the course. It will start very easy. The basics, it will go a more complex in the following slides, however, it will
stay as an easy too. Assume hardness project. It is not hard at all. It's not challenging at all. When it comes to the project, I am suggesting u and
v of five numbers. You have to perform the
following commands on MATLAB. First you have to add u and v, then multiply u
by v, then reads, raise each element of
u to the power of two, then divide each element of view by the corresponding
element of V, also the same from
V towards you. However, pay attention that when it comes to the matrices, this case the operational
and mathematical operations. I'm not similar to
the just numbers. Using MATLAB as the calculator. You have to remember
what we are, what symbol we add an ordered
for MATLAB to understand. Pay attention. I'm working with matrices not normal numbers in case
student remembers that. That's perfect in case not
go back to the videos. Remind yourself about it. It's really simple. And in case you didn't
remind that you will do all these five
questions wrong. It is essential. The sixth question you
have to sort you in this slide or this
bunch of questions, we will go to the
formatting of the matrix. So I'm sorting you
certain view as a sort. It is in the ascending form, however, sorted now in
the descending fall, now create a row vector w consisting of the
elements of u and v. The majority of students
just freeze at this level. There's nothing hard at it. Just act with the u
and v as numbers. Just add to create a
matrix that is called W, where you are defining
it as a two numbers. These two numbers are u and v. Now create a column vector W, in which the first row is, you add the second row is V. Find the minimum
value in new and find the maximum value of u. You have to create
a vector u that consists the elements of you. And you have to add a sixth
element equals to 120. Now we automate
imaging with you from the index seven to the
index nine that are not present because you
have five numbers. And the 120 that we
added, a sixth number, now, seven till nine, you have to add 8410. Now, delete all the
indexes between 35. I helped you in this question. I added the equal vote. However, some students
just forgot that deleting is just creating an equal operation
would avoid space. Now find you of three to check what will happen to
the index three, it is really important. Now find the sum of you, find the product of you. I wish you are able
to enjoy the course one more time and you will be
able to solve this project. In the next video, I will add a solution
for this project for you in case you did a
mistake to correct yourself, in case you are stuck on any
question to be easy for you. Thank you so much and I
wish you the best of luck.
13. Project Solution: I really wish you
enjoyed the project. Now let's move on to
solving this project. Let's go here to
project if you equal 12345 and V equals
6789, Let's go. U equals to 12345 semicolon, v equals to 678910. Semicolon. Perform the
following commands on MATLAB. Add u and v as you can, no, you can't this easy. U plus v under display I
got the answer 79111315. Let's clear the command. Now. Multiply each element of U by the corresponding
element in V. Also at this simple, You point times V. Run the section I got at 614. Twenty four, thirty six fifty. Raise each element
of u to the power of 2 or dot power of two. Let's run this section. I get 1491625. This is totally correct. Let's divide each
element of U by the corresponding element of v, u divided by V. And let's clear the command
in order to make the solution easier
around section I have it. Now the inverse V
dot divided by u. Let's run this section. I get 63.52.67 AD setting. Now I'm clearing the command
to now everything's easy. Let's move on to
the second section. Let's sort you how
we sort you, Press, Sort you the section 12345. Now sort2 in the
descending form, we sort u comma. We say these centered around
this section, we got 54321. Create a row vector
w consisting of the elements of u and
v. How do we do that? So we just say w equals u, then we all the rows
of you than space, which means we are
in the same row. Let's run this section. I have from one delta1, the column vector W, in which the first row is
u and the second row is V, create a column vector u, in which the first short is
u and the second row is v. So I have to separate
them with a semicolon. Let's clear it and run the section 123456789.
That's simple. Find the minimum value in new. We go to MATLAB and
brass, minimum of u. Let's run this section. I would have the answer as one. Minimum of V is six. Maximum of v should be done. The maximum of you
should be five. That's totally correct. Now create a bacteria
consists of the elements of U and the sixth
element equals 120. What we should do
in order to create this vector u equals
to what do you, this we are on the same row. I want to add 120. So MATLAB understand
that u is not equal to 123456 elements 120. Let's run this section. We got it. Creates
you of seven to nine. So that's correct. I'm asking that selection
from seventh to the ninth. Let's run this section. I will have it as
drunk because I don't have index
seven till night. He's asking me to
create a U from seven to nine equals to 84 to1. Let's copy it from here. Go to MATLAB Control V, you from seven to nine
equal to eight for ten. What does it mean? You know, is equal to
12345120 is the sixth, the seventh is eight, the eighth is four, and the ninth is that. This has now created. If you want to display you,
Let's run this section. I will have it 12345128410, create you of three to
five equals to void. So I'm deleting it. Now. You off from three to five. I'm deleting it as
a void display. Let's run the section now I
have one to the third and the fourth and the fifth
are deleted than 120. And we can continue
then find U of three. Now and say find or
just you of three. The third index is 120th. Let's run the selection. I have 120, find the sum of u, which is very easy. Some of you and run
the section I got 145. What about the product of u? Just product of you. I wish that you enjoyed this course in case
you need any help, just contact me through
the context that I displayed in the
introduction video. Thank you so much for attending
you in other courses.