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

3

3

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?

Lelea answered 26/5, 2011 at 1:25 Comment(1)
I think there is no "simple" approach. Identifying "interesting zones" needs detecting discontinuities, derivative and function zeroes, asymptotes, etcIntelligibility
C
3

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.

Costin answered 26/5, 2011 at 4:17 Comment(0)
B
1

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.

Blackberry answered 26/5, 2011 at 8:19 Comment(0)
D
0

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)
Darnel answered 26/5, 2011 at 10:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.