fplot behavior at breakpoints

5 ビュー (過去 30 日間)
Xiaobo Dong
Xiaobo Dong 2024 年 10 月 20 日
コメント済み: 埃博拉酱 2024 年 10 月 21 日
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.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeNumeric Solvers についてさらに検索

タグ

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by