Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matlab. Difference between plot and fplot?

Tags:

plot

matlab

Why use 'fplot' to plot functions when we can use 'plot'? I can't understand

like image 938
user3415893 Avatar asked Jun 10 '26 02:06

user3415893


1 Answers

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,'.-')

enter image description here

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.

enter image description here

like image 170
Luis Mendo Avatar answered Jun 13 '26 06:06

Luis Mendo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!