Graphing calculator: how to find the appropriate part of the graph to show

有些话、适合烂在心里 提交于 2019-12-05 18:52:08

What an interesting problem. I've never thought about this, but I'd start by finding:

  1. The two roots of the equation nearest the origin (you can use the Newton-Raphson algorithm).
  2. The maxima and minima. For this you need to find the the places where the derivative of the function is 0. You could do numerical differentiation and find, roughly, the spots where the derivative crosses 0, or if you're feeling ambitious you could use automatic differentiation. Once you've found the 0-crossings of the derivative, go back and evaluate the original equation at those spots.
  3. The value of the function at each of these x-axis points.

Then take the furthest apart points on each axis, add 10% to them, and use them as the bounding box coordinates.

There are obvious edge cases: the function may have no, one, or infinitely many roots. The function may have no maximum or minimum. I'm not really sure how you can detect these cases, but you might want to build in limits to steps (1) and (2), like find the first N roots or the first N extrema, counting out from 0. Another limit might be making sure your excursion on one axis is never more than N times the excursion on the other axis.

Two interesting points of most common graphs are the origin of the coordinate system (for orientation) and the y-intercept of the function, which is easy to compute. Hence, I'd choose the scale such that both the origin (0,0) and the y-intercept (0,y0) are visible, plus some padding, i.e. the interval [-y0 - y0/5; y0 + y0/5]. If origin and y-intercept happen to be close or even the same, I'd choose a visible interval of, say, [-5; 5].

The rationale behind this is that a well-formulated function is supposed to have its interesting part somewhere near the origin, or at least near the y-intercept. If it doesn't, you simply can't tell what the user wants to see, so he shall take care of that himself.

One of possible definitions of interesting zone is density of the following points:

  1. f(x)=0 (crossing x-zxis)
  2. f'(x)=0 (min/max)
  3. f''(x)=0 (changing direction of curvature)
  4. f'''(x)=0 (max. curvature, probably min. curvature may not be very interesting)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!