Reputation: 69
Why use 'fplot' to plot functions when we can use 'plot'? I can't understand
Upvotes: 3
Views: 31351
Reputation: 112659
With plot
you have to manually define the x
values and compute the corresponding y
given by the function.
>> x = 0:.01:1;
>> y = sin(10*x);
>> plot(x,y,'.-')
With fplot
you define the function generically, for example as an anonymous function; pass a handle to that function; and let Matlab choose the x
values and compute the y
values. As an example, take a difficult function:
>> f = @(x) sin(1/x);
Assume we want to plot that between 0.01
and 1
:
>> lims = [.01 1];
>> fplot(f, lims, '.-')
See how Matlab does a pretty good job choosing closer x
values in the left area, where the function becomes wilder.
Upvotes: 7