I am bit under pressure cause our exams are banging at the door...lolz...However I thought of showing how to plot graphs.
1.ezplot('f(x)',[min max])
plots the given function within the range [min,max]
2.plot(x,f(x)) plots the given function y=f(x)
However in this case you need to use discrete values to define the range of x.
eg.,
n=0:0.1:2*pi;
plot(n,sin(n))
you can also write plot(f(x)) and produce the same result.In the above example matlab plots a sinusoidal graph by evaluating sin n for each value of n.n here is a range of discrete values with difference of 0.1.Hence in order to get a more continuous graph decrease the difference of n.Try It!
Now if you want to plot more than one graphs on one figure then use hold function.And if you want to get a better view of the graph use grid function.
Labels:
When you want to label the axes and the graph then use xlabel('name1'),ylabel('name2'),title('Title') functions.
Here's an example:
n=0:0.01:1;
grid on;
plot(5*n);
hold on;
plot(exp(n),'red')
hold off;
grid off;
xlabel('x->');ylabel('Amplitude');title('Overlapping graphs');
3.stem(n,y(n))
Sometimes we want to plot discrete values.This function plots the discrete values n points and their corresponding values.
PLEASE LEAVE A COMMENT :)
1.ezplot('f(x)',[min max])
plots the given function within the range [min,max]
2.plot(x,f(x)) plots the given function y=f(x)
However in this case you need to use discrete values to define the range of x.
eg.,
n=0:0.1:2*pi;
plot(n,sin(n))
you can also write plot(f(x)) and produce the same result.In the above example matlab plots a sinusoidal graph by evaluating sin n for each value of n.n here is a range of discrete values with difference of 0.1.Hence in order to get a more continuous graph decrease the difference of n.Try It!
Now if you want to plot more than one graphs on one figure then use hold function.And if you want to get a better view of the graph use grid function.
Labels:
When you want to label the axes and the graph then use xlabel('name1'),ylabel('name2'),title('Title') functions.
Here's an example:
n=0:0.01:1;
grid on;
plot(5*n);
hold on;
plot(exp(n),'red')
hold off;
grid off;
xlabel('x->');ylabel('Amplitude');title('Overlapping graphs');
3.stem(n,y(n))
Sometimes we want to plot discrete values.This function plots the discrete values n points and their corresponding values.
PLEASE LEAVE A COMMENT :)
0 comments:
Post a Comment