In this video we will make two graph.
So these are graphs of these functions functions of x so you can say that our y is x^2 +2x+1
is first function and this is our second function.
And in this graph, we will learn a couple of things.
first of all how to define x variable, how to define these functions how to get the function
values then how to plot then how to change these colors and how to change these line
styles and also as you might have noticed that Scilab graphs dont have font izes this
big, so we will also be changing the font size of x-axis label, y-axis label and also
font sizes of the figures it self.
so then we will put a title to this graph as well so these are some of the things which
we will be learning in the class without further ado lets start so first of all we have to
declare the variable x and as you can see here that our x is changing from minus 10
to plus 10 so this is the range of x we define x first of all so in Scilab, we can define
x as x= -10 with an increment of 0.1 we go up to 10 so this is our x variable you can
also write this in a function if you want but I am just using the command prompt so
that I can explain the thing step-by-step so the first function we have as you can see
that our first function is f of x equals x^2 + 2x+1 we can say that our f1 any variable
is equal to x^2 + 2 multiplied by x + 1 so now this f will get all the values now our
second function is we can say f2 = x^2-2x-1 so x^2 x raise to the power 2 minus 2 multiplied
by x minus 1.
so this is our second function now we plot the first function so plot we are using the
plot command and the plot command is similar or you can say close to the MATLAB plot command
so if you are coming from MATLAB background you will find this very similar otherwise
there are other commands available in Scilab.
So we plot x vs f1.
So as you can see that we got this plot of our first function so similarly we can plot
the second function first and then we will change the attributes of this plot.
So, let us plot x vs f2.
So now we have our both plots here so now we want to change the color of one to red
and also the line style as you can see that our line style is x we are putting x at all
the values which we are plotting first we finish with the plotting and then at th end
I'll show you what line styles we have so you can easily change the line style to which
you want So, in order to plot this x in this blue color, so what we have to do? we will
use the simple plot command again if you want you can just close this window so we can close
this window so that we get the new window so we use the plot command x,f1 now we give
a third variable here and which is a string type so we have to start the ' and then x
then # and the color is red.
So let me see whether which color we have in our example so our plus function has blue
color so we can put blue color with b and I'll show you all the codes for these colors
at the end and ' close here and if I plot now as you can see our first function has
been plotted in blue so similarly we can plot the second one plot x,f2,x-red 'and now we
have our both functions plotted one in blue and one in red now we want to put our x-label
here which is x value of x so that can be done in couple of ways you can plot your x-label,
y-label and the title separately but there is a command which can do this together for
you and we can use that command as well so lets first we do with the separate commands
we say x-label and we just want to put x we dont want anything else in xlabel so x is
our xlabel so now e have this x written here similarly we can ylabel and at y on y-a we
want to put f(x) so we start a string and then f(x). and then we close this string and
now we have our y rotated automatically so this rotation is automatic now if we compare
with this we still have to write this title but title you can write simply title and then
you can again in the similar fashion graph of functions close the string and now we have
this title and now we have to put this legend in this legend as you can see that we have
statements like x^2 +2x + 1 so for this we have to write some mathematical equations
and this we will be doing in our legend statement so you dont have to actually store this in
any variable but I will just store in h1 so that we might need his h1=legend legend is
the command and inside this command we have to put a matrix here we are having two legends
so it will be a matrix which will have two entries or two elements so this is a matrix
a row matrix or a row vector, these are two entries so this is the first string then comma
and then this is a second pair of apostrophes so you can write first legend here for example
f1 and f2, I can just put a comma here better you put a semicolon here both ways are fine
you can put you can put a semicolon if I run this now these are axis properties here but
there is no error now if you look here we have this legend f1 and f2 so if you had no
equations you can straight away write legends like this and by default the legends will
be placed at the top right corner and I'll show you how to change this position.
to any other corner and now we will write these three equations and to write equations
this is the same statement we have to put two dollar signs so I put two dollar signs
for both of the entries so in this way you dont do any mistake because this is a similar
thing you are doing so you do it to both parts so in the first you want to write x^2 so x
and hat then 2 x here you dont have to put the multiplication sign because you are not
actually multiplying you are just writing so you just write 2x no asterisk here and
plus one is the first function, it will show you as you can see that at the bottom it is
showing you everything and now in the second we write again x^2 -2x-1 you put dollar signs
and in the dollar signs you can write the equation as you write in Latex if you are
familiar with Latex so now if I enter this it will again show you axis properties and
we will talk about this later and now as you can see that we have equations written here
so now we want this to change from this to this position or probably this position so
for that what you need to do you can put a third argument in this legend function, you
can say that pos position equals and lets say 3 so there are couple of positions available
so I think the 3 is bottom left or top left so we will see what position is this just
enter this and now you can see that the position 3 is bottom left so position 2 could be this
one so you can try with this but the best way which I like to do is by using a position
5 because position 5 gives you the option to put it wherever you like because sometimes
in graph there is no appropriate position in the corner so you want to put in the middle
or at the top of the figure for example so in that case you can use position 5 so let
us use position 5 now when I open the graph, it is waiting for me to click somewhere because
now I have this attached with my mouse the legend box so wherever you want so now the
last thing as you can see that we have to increase the fond size to increase the font
size, we have to use a handle variable so handle means identifier of any figure so any
figure has an identifier so that identifier is called handle so we will store that handle
in a variable and then we will access the properties using that variable so let us say
that a is the variable in which you want to store the handle of this figure so to access
the handle I can say gca is the command get current axis and now we have handle so now
we have access to all the axis properties so now you have to know what property what
is the name of the variable defined in Scilab for that particular property so there is a
list of properties available so you have to check in documentation for example for font
size let me show you how to check that font sizes are available from 1 to 10 so 1 is the
smallest 10 is the largest so by default I think it is 2.
So I want to make it 4 so how I 'will do that I'll just say a.font_size and font then underscore
size this is the way you will write you cannot change this because this is defined in Scilab
like this so you have to change a.font_size=4 for example and now if I look at the figure
you can see that the font size of the figure has changed now I want font size of this title
to be changed and also the x and y labels to be changed so to change the xlabel font
size you will say a.x_label and then you will put dot and then font size just like before
so you have to put font_size so let us change the y in the similar fashion let me clear
this so that we can change the y in the similar fashion instead of xlabel we put ylabel you
can again say a.title.font_size and lets say 6 and as you can see that our font size has
changed now the legends are not looking good here we can use position 5 to put in the middle
and now as you can see that this is busy sign so that it means it is waiting for us to go
to the figure and place the legend so we go to the figure and we place it here so now
as you can see that now it is done it is exactly the same which we wanted.
These are some of the line styles and colors available in Scilab so we have used this one
cross but you can use any o these for sold line you have this dash similarly colon for
dotted line and so on so all these options are available so in the next plotting lecture
we will see how can we modify these distances these are called xticks so we will learn how
to modify and how to put other values here and we will be using trigonometric functions
to do that.