Transcript

The Symbolic toolbox, one can use ezplot to graph a function. It is a quick and easy way to visualise without having to make an array and without having to define a function m file. Recall that you needed to make an array if you use plot function, and you needed to make a function m-file if you use f-plot function. So ezplot is really easy. Just in 2 lines of code you can do the graph. However there are some disadvantages using ezplot. For example you can not change colour of the line in the graph.

 

For example, if I want to plot cos of 2x using ezplot. First thing I will need to type, sims x. And then ezplot. In the bracket, cos of 2 x. And it is plotted. As you can see there is automatically a title there - cos of 2x - and it is plotted from minus 2 pi to plus 2 pi, that is default. So by default it is always plotted from minus 2 pi to plus 2 pi.

 

And if you want to change from where to where you want your plot, you can specify it. So for example, if you want to plot from 0 to pi, you can say comma, in a square bracket 0 comma pi. And now it is plotted from 0 to pi.

 

You can plot more than one function in the same graph window using hold on, so - hold on - and then, suppose I want to plot sin x as well on the same graph. So it is sin x, 0 to pi and it is plotted.

 

There is a problem. As you can see there is a full picture of sin x but the graph of cos 2x is truncated here. What could be the reason? This happened because ezplot by default sets the y axis limits depending on the most recent function you typed for graphing. So our latest function was sin x, and we were plotting it between 0 and pi. And sin x has values between 0 and 1, if x belongs to the interval 0 pi. Therfore ezplot has plotted both functions using y-axis limits 0 to 1. To fix this problem, we need to override this feature.

 

We are going to use axis command - axis - in the bracket. Square bracket, x minimum value is 0, x maximum value is pi. And we want y values from minus 1 to plus 1. So y min is minus 1 and y max is plus 1. Square bracket and round bracket. Enter. And see what you got. Now it is a full picture of both of the functions.

 

But still - there is a wrong title on the top. With ezplot, by default, the title is always the most recent function we typed, which is sin x here. Therefore sin x is in the title. But we can change it using title command. Let's change it. So title and in the bracket we can type the string for the new title. I want it 'sin x and cos of 2x'. Bracket closed. Enter. And let's see the new figure. See now we have title changed here.

 

Unfortunately we can not change the line colours here, because ezplot doesn't allow us to change any of the line properties. But still we agree that ezplot is a quick and easy way to graph any function.

Last modified: Monday, 10 August 2015, 10:20 AM