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

坚强是说给别人听的谎言 提交于 2020-01-02 08:39:28

问题


I am working on a graphing calculator (you know, one where you type in a formula, let's say x^2 and you get the graph of that function). The problem I am having is how to offset and scale the view of graph as to show the interesting section of the function.

I have exhausted all the 'simple' ideas I have had. Let me show some example: - sin(x) => interesting section is between y = [-1,1] and offset (0,0) - x^2 => interesting section is between y = [0, 100] and offset is (0,0). (100 has been picked arbitrarily) - 100x^2 - 10000 => y = [-10000, 100*] and offset is (-10000, 0)

I figured I could assign a 'range' and 'offset' for each type of function and create some math to add/multiply/etc these range together the same way a result would be calculated. However, that requires 'creating' some math and the potential for well hidden logical flaws is way too high.

There must be a non-too-difficult way to do this, but I just can't find it. Are there some specific terms to search for? Any pointers to an algorithm?


回答1:


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.




回答2:


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.




回答3:


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)


来源:https://stackoverflow.com/questions/6132764/graphing-calculator-how-to-find-the-appropriate-part-of-the-graph-to-show

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!