Filter löschen
Filter löschen

how "fplot" works?

8 Ansichten (letzte 30 Tage)
Luigi Stragapede
Luigi Stragapede am 18 Mai 2020
Kommentiert: dpb am 18 Mai 2020
I have a function which depends on a particular variable, that is T(theta) where the variable is theta. Then, I plotted the function T(theta) with "fplot".
I want to know: which is the frequency of theta with which the fuction T is plotted? I suppose that Matlab consider a lot of theta and compute T for each of these theta.
  1 Kommentar
dpb
dpb am 18 Mai 2020
Just read the documentation...
fplot(f) plots the curve defined by the function y = f(x) over the default interval [-5 5] for x.
It sets the number of points internally; not sure the heuristics it uses but the difference in x-values over a default range isn't identical so it's not just linspace(x1,x2,N). But,it's not trivially obvious just where the algorithm is buried in a very quick look at the m-file.
A trivial plot returned 57 for the number of points in X|YData arrays....interesting choice...

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Ameer Hamza
Ameer Hamza am 18 Mai 2020
Bearbeitet: Ameer Hamza am 18 Mai 2020
fplot does not use fixed mesh spacing. It adaptively calculates the distance between mesh points (probably using derivates) of the function. See the parameter MeshDensity: https://www.mathworks.com/help/releases/R2020a/matlab/ref/fplot.html#bu6xntj-1_sep_shared-MeshDensity. By default, it is 23, but MATLAB usually uses a higher number of points for a smoother curve. The algorithm to adaptively calculate the mesh point is not provided, but you can find out the x-values and y-values of points using the following statements
syms x
y = x.^2*sin(x);
f = fplot(y)
f.XData
f.YData
  1 Kommentar
Walter Roberson
Walter Roberson am 18 Mai 2020
Furthermore, fplot has code to attempt to find discontinuities even if they are at a finer spacing than the adaptive mesh would suggest.

Melden Sie sich an, um zu kommentieren.

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by