fplot behavior at breakpoints

3 次查看(过去 30 天)
When using fplot to draw a function that has breakpoint, sometimes two sides of it are connected, but sometimes they are not. Why? Can I control them to be connected or not?
For example, run the following code:
syms x
fplot(tan(x), 'ShowPoles', 'off')
There's a line connecting and , but no line connecting and .

采纳的回答

Umar
Umar 2024-10-20

Hi @Xiaobo Dong,

I do agree with @Walter Roberson’s comments,”fplot does not assume continuity. “ Let me address your query, A breakpoint in a function is a point where the function is not continuous. For example, the tangent function, tan(x), has vertical asymptotes at odd multiples of π/2. When fplot encounters these points, it must decide how to represent the function on either side of the discontinuity. So, when you run the command:

syms x
fplot(tan(x), 'ShowPoles', 'off')

you may observe that the plot connects points on either side of certain breakpoints. This occurs because fplot evaluates the function at various points and, if the values are close enough, it will draw a line segment between them. The algorithm attempts to create a smooth curve, but it can sometimes connect points across a discontinuity if the evaluation points are not sufficiently spaced apart. Conversely, if the evaluation points around a discontinuity are spaced such that the function values diverge significantly (for instance, approaching infinity), fplot will not connect these points. This behavior is designed to prevent misleading representations of the function. To control whether the segments are connected or not, you can adjust the MeshDensity property of the fplot function. By increasing the mesh density, you can ensure that fplot evaluates the function at more points, which can help it better identify discontinuities and avoid connecting points across them. Here is an updated version of your code that increases the mesh density to better handle the discontinuities in the tangent function:

syms x
% Increase the mesh density to improve the handling of discontinuities
fplot(tan(x), 'ShowPoles', 'off', 'MeshDensity', 100)
title('Plot of tan(x) with Increased Mesh Density')
xlabel('x')
ylabel('tan(x)')
grid on

Please see attached.

For more information on MeshDensity, please refer to

https://www.mathworks.com/help/matlab/ref/matlab.graphics.function.functionline-properties.html#bvfwdco_sep_shared-MeshDensity

Hope this helps.

Please let me know if you have any further questions.

更多回答(2 个)

Walter Roberson
Walter Roberson 2024-10-20
You can increase the likelyhood of the line being shown if you increase the MeshDensity . However, you should expect it to miss the poles if the equation is steep enough.

埃博拉酱
埃博拉酱 2024-10-20
fplot假设函数是连续的,所以你不能指望它正确作出有间断点的函数图像。
推荐尝试我专门为这种情况编写的二维函数作图工具
  3 个评论
Walter Roberson
Walter Roberson 2024-10-20
fplot does not assume continuity.
If you look at the Tips section of fplot (symbolic) then you see
  • If fplot detects a finite number of discontinuities in f, then fplot expands the range to show them.
which is an explicit statement that discontunities will (attempt) to be detected.
埃博拉酱
埃博拉酱 2024-10-21
Oh, I didn't look at sym's fplot, just the generic fplot documentation.

请先登录,再进行评论。

标签

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by