# A easy way to plot a equation using MATLAB.’syms’

It is quite often required to plot a function like ” Gaussian distribution, a*exp(-(x-b)^2/2c) or f=x^2″

MATLAB has the function to plot and manipulate symbolic equations in a easy way.

For example, if I want to plot y=x^2+3.

```syms x;

f='x^2+3';

ezplot(f,[-10,10,-5,50]);``` If you face this error “Single input must be an existing figure handle or a scalar integerfrom 1 to 2147483646″, please check the definition function.

f=x^2+3 and f=’x^2+3′ are different.

Give a try to define your own function and plot it.

# Matlab multi line plot in the same window.

There are two common ways to plot more than 2 data on the same window.

The first method uses one line and is of the form plot(xfunction, style#1 ,x, function#2style#2, ). For example,

plot(x,x.^2,’-ro’,x,x.^3,':bo’)
The second method involves the use of the “hold on” and “hold off” commands. After creating the first graph, use the “hold on” command, forcing subsequent graphing commands to be placed in the same window. Now type in your second plot command. When you are through, type “hold off”. For example

plot(x,x.^2,’–ro’)
hold on
plot(x,x.^3,’-bd’)
plot(x,-x,’g+’)