fplot behavior at breakpoints

조회 수: 3 (최근 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 CenterFile Exchange에서 Numeric Solvers에 대해 자세히 알아보기

태그

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by