Categories

# Matlab ezplots

MATLAB is also a great tool for visualization. It provides us with ability to create a wide variety of plots. In this article, we will focus on ezplot function for creating plots of functions and equations.

## Syntax:

Let us understand the Syntax of ezplot function in MATLAB

1. `ezplot (f)`
2. `ezplot (f, [minimum, maximum])`
3. `ezplot (x, y)`

## Description of ezplot function in Matlab

1. ezplot (f):
1. ezplot (f) will create a plot of an equation, symbolic expression or a function passed as an argument
2. Ezplot (f) by default will plot a function or an expression over [–2π to2π] or a subinterval of [–2π to 2π]
2. ezplot (f, [minimum, maximum]):
1. This function will plot the input function or equation over the range passed in the argument
3. ezplot (x, y):
1. This function will plot the planar defined curves xand y over 0 <= z <= 2π or over a subset of 0 <= z <= 2π

## Examples:

Let us understand ezplot (f) with a couple of examples:

## Example 1:

Let us take a simple example of sine function and try to plot it using ezplot.

``syms x[initializing variable x] ezplot(sin(x))[passing the input function]``

[Here notice that we have not passed any argument for the interval, so by default, ezplot function will plot the sine wave in the interval [–2π to 2π] ]

## Input:

``````syms x
ezplot(sin(x))``````

## Output:

As we can see in our output, the sin function is plotted between the range [–2π to 2π] ].

Next, we will pass an argument to define the interval for our output.

## Example 2:

Let us take a cos function and try to plot it using ezplot in the range 0 to 2π

``syms x[initializing variable x] ezplot(cos(x), [0, 2 * pi])[passing the input function and the required interval][Here notice that we have passed [0 to 2π] as an argument for the interval]``

## Input:

``````syms x
ezplot(cos(x), [0, 2 * pi])``````

## Output:

As we can see in our output, the cos function obtained is in the range 0 to 2 pi; as expected by us.

## Example 3:

In this example, we will use ezplot (x, y) to create plot of a straight line equation

``syms x y[initializing variables x& y] ezplot(x == 5 * y )[passing the input straight line equation]``

[Notice the double equal to sign for representing ‘=’ ]

## Input:

``````syms x y
ezplot(x == 5 * y )``````

## Output:

As we can see, we have obtained a graph for equation of a straight line.

## Example 4:

In this example, we will plot equation for a sphere using ezplot (x, y).

``syms x y[initializing variables x& y] ezplot(x ^ 2 + y ^ 2 == 25 )[passing the equation of a sphere with radius 5]``

[Notice the double ‘equal to’ sign for representing ‘=’ ]

## Input:

``````syms x y
ezplot(x ^ 2 + y ^ 2 == 25 )``````

## Output:

As we can see in our output, we have obtained a sphere of radius 5 sing ezplot function.