Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

This question pertains to programing but is really a math question.

I am building an application that draws a line graph, similar to a stock line graph. The problem is I am not starting with a known set of numbers. The values will come in based on an altitude value. So, when I start the graph I have no idea what the max and min values of my data set will be, because they max might not come along for some time.

enter image description here

Like I mentioned, these values will be added to the graph when I receive and elevation value but I don't know these until they are received from my device (iPhone).

Is there a formula used to calculate a line graph for unknown values? How can I know what x and y values to use for each new value received? And how can I calculate the min and max of the graph?

share|improve this question
    
The usual approach is to choose some default scale for your graph and rescale if the data goes out of range. Maybe you start with 0-1mi on x and current altitude (rounded) +-200 ft on y. Then when somebody goes past 1 mi, change the horizontal (which requires updating all the points) to 0-2 mi. –  Ross Millikan Oct 27 '11 at 17:17
    
@RossMillikan Yes, it is a good idea as you mentioned to set a default scale, this is something that I will implement. Right now I want to get y working because that is really the "unknown" at this point. So are you suggesting that I takes random samples of max and min then adjust my graph scale throughout the duration? –  Nic Hubbard Oct 27 '11 at 17:23
    
sometimes people just cover the range of the current graph. So if somebody starts out on very flat ground, y could be only +-15 feet more or less. The bad news is it jumps around a lot. Otherwise you can just start with the idea that "everybody" will change in elevation by 100 feet and set that as a minimum scale, increasing it as required. Really x and y work the same way in this regard. –  Ross Millikan Oct 27 '11 at 17:42
    
Do you want to post this as an answer? –  Nic Hubbard Oct 27 '11 at 19:16

2 Answers 2

up vote 1 down vote accepted

The usual approach is to choose some default scale for your graph and rescale if the data goes out of range. Maybe you start with 0-1mi on x and current altitude (rounded) +-200 ft on y. Then when somebody goes past 1 mi, change the horizontal (which requires updating all the points) to 0-2 mi

ometimes people just cover the range of the current graph. So if somebody starts out on very flat ground, y could be only +-15 feet more or less. The bad news is it jumps around a lot. Otherwise you can just start with the idea that "everybody" will change in elevation by 100 feet and set that as a minimum scale, increasing it as required. Really x and y work the same way in this regard. – Ross Millikan 1 hour ago

share|improve this answer

You are receiving a sequence $(x_k,y_k)_{k\geq1}$ of data points in real time. Initialize $$a_1:=b_1:=x_1,\quad c_1:=d_1:=y_1$$ and update these boundaries by means of $$\left.\eqalign{a_n&:=\min\{a_{n-1}, x_n\},\quad b_n:=\max\{b_{n-1}, x_n\},\cr c_n&:=\min\{c_{n-1}, y_n\},\quad d_n:=\max\{d_{n-1}, y_n\}\cr}\right\}\qquad(n\geq2)\ .$$ Assuming $a_2\ne b_2$ and $c_2\ne d_2$ you can plot the $n\geq2$ data points received so far in the unit square $[0,1]^2$ as follows: $$\eqalign{\xi_k:={x_k-a_n\over b_n-a_n} \cr \eta_k:={y_k-c_n\over d_n-c_n}\cr}\qquad (1\leq k\leq n)\ .$$

share|improve this answer
    
Christian, you lost me. I don't know math well enough to understand what you just posted. –  Nic Hubbard Oct 28 '11 at 5:32
    
@Nic Hubbard: It's just putting into formulas what Ross Millikan suggested. If you want to implement his advice you will have to use formulas of this kind. –  Christian Blatter Oct 28 '11 at 7:43

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.