Logarithmic scale

Discussion in 'Javascript' started by Sunny, Sep 25, 2008.

  1. Sunny

    Sunny Guest

    Hi Is there a way to find a proper distance between large numbers.

    For example, if i have a set of numbers like:
    10, 40, 80, 100, 500, 10000
    Now if I have to create a break points between these no.
    I have to take an average & add that average to the starting number
    like.
    (10000 -10)/6 = 1665.
    Now if I create a break point using this no. the break points will be:
    10 - 1675, 1675 - 3340, 3340 - 5005, 5005 - 6670 ....
    But the problem is that I can't use them as they are far apart like
    all the first 5 no.'s will be in the first breakpoint, so its no help.

    Can I use a formula like logarithmic scale in javascript to calculate
    the breakpoint that are based on logarithmic scale.
    Sunny, Sep 25, 2008
    #1
    1. Advertising

  2. Sunny <> writes:

    > Hi Is there a way to find a proper distance between large numbers.
    >
    > For example, if i have a set of numbers like:
    > 10, 40, 80, 100, 500, 10000
    > Now if I have to create a break points between these no.
    > I have to take an average & add that average to the starting number
    > like.
    > (10000 -10)/6 = 1665.
    > Now if I create a break point using this no. the break points will be:
    > 10 - 1675, 1675 - 3340, 3340 - 5005, 5005 - 6670 ....
    > But the problem is that I can't use them as they are far apart like
    > all the first 5 no.'s will be in the first breakpoint, so its no help.
    >
    > Can I use a formula like logarithmic scale in javascript to calculate
    > the breakpoint that are based on logarithmic scale.


    You can use logarithms in javascript. See Math.log:

    http://developer.mozilla.org/En/Core_JavaScript_1.5_Reference:Global_Objects:Math:log

    I have no idea what you mean by break points or what you're trying to
    do. It looks like you just want to split an ordered list in two, sort of:

    x = Math.ceil(list.length / 2)
    break_point = (list[x] - list[x+1]) / 2

    If that doesn't help, please explain further.

    --
    Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
    Joost Diepenmaat, Sep 25, 2008
    #2
    1. Advertising

  3. Joost Diepenmaat <> writes:

    > x = Math.ceil(list.length / 2)
    > break_point = (list[x] - list[x+1]) / 2


    I meant Math.floor()

    --
    Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
    Joost Diepenmaat, Sep 25, 2008
    #3
  4. Sunny

    Sunny Guest

    On Sep 25, 3:47 pm, Joost Diepenmaat <> wrote:
    > Joost Diepenmaat <> writes:
    > > x = Math.ceil(list.length / 2)
    > > break_point = (list[x] - list[x+1]) / 2

    >
    > I meant Math.floor()
    >
    > --
    > Joost Diepenmaat | blog:http://joost.zeekat.nl/| work:http://zeekat.nl/


    I have a series of numbers that i want to display on graph.
    Numbers are like 10, 40, 80, 100, 500, 10000, 100000. there are 50
    numbers
    Like the last column has value that is really higher.
    Here users can break this numbers into groups.
    But when I take the average using the no. of groups they want (100000
    -10)/6 = 16665.
    so the groups come out 10 - 16665.
    Now if i have to display this data on chart.
    all the 30 points come under group 10 - 16665 & couple of groups
    remain empty like 1ike no value exists in them because the difference
    between the lowest & highest element is too big(10,100000). So I want
    a method that computes an average or create groups based on logic.
    Sunny, Sep 25, 2008
    #4
  5. Sunny

    Tom de Neef Guest

    "Sunny" <>
    > I have a series of numbers that i want to display on graph.
    > Numbers are like 10, 40, 80, 100, 500, 10000, 100000. there are 50
    > numbers
    > Like the last column has value that is really higher.
    > Here users can break this numbers into groups.
    > But when I take the average using the no. of groups they want (100000
    > -10)/6 = 16665.
    > so the groups come out 10 - 16665.
    > Now if i have to display this data on chart.
    > all the 30 points come under group 10 - 16665 & couple of groups
    > remain empty like 1ike no value exists in them because the difference
    > between the lowest & highest element is too big(10,100000). So I want
    > a method that computes an average or create groups based on logic.


    First take the log (as said by JD, see Math; remember that 10-base log(x) =
    ln(x)/ln(10) ) of all points into a new series.
    Do your groupings with this new series and display.
    The y-axis will now run from say -0.3 to 4.2. Round these min and max values
    down resp up to -1 and 5.
    Display the axis where you transform the values y to 10^y (e.g. 0.1, 1, 10,
    100, 1000, 10000).

    Tom
    Tom de Neef, Sep 25, 2008
    #5
  6. Sunny

    RobG Guest

    On Sep 26, 6:14 am, Sunny <> wrote:
    > On Sep 25, 3:47 pm, Joost Diepenmaat <> wrote:
    >
    > > Joost Diepenmaat <> writes:
    > > > x = Math.ceil(list.length / 2)
    > > > break_point = (list[x] - list[x+1]) / 2

    >
    > > I meant Math.floor()

    >
    > > --
    > > Joost Diepenmaat | blog:http://joost.zeekat.nl/|work:http://zeekat.nl/

    >
    > I have a series of numbers that i want to display on graph.
    > Numbers are like  10, 40, 80, 100, 500, 10000, 100000. there are 50
    > numbers
    > Like the last column has value that is really higher.
    > Here users can break this numbers into groups.
    > But when I take the average using the no. of groups they want (100000
    > -10)/6 = 16665.
    > so the groups come out 10 - 16665.
    > Now if i have to display this data on chart.
    > all the 30 points come under group 10 - 16665 & couple of groups
    > remain empty like 1ike no value exists in them because the difference
    > between the lowest & highest element is too big(10,100000). So I want
    > a method that computes an average or create groups based on logic.


    I think what you want to do is sort the numbers, then group them based
    on their order index (1 to 50) rather than their value (10 to
    100,000).


    --
    Rob
    RobG, Sep 25, 2008
    #6
  7. Sunny

    Sunny Guest

    On Sep 25, 6:08 pm, RobG <> wrote:
    > On Sep 26, 6:14 am, Sunny <> wrote:
    >
    >
    >
    > > On Sep 25, 3:47 pm, Joost Diepenmaat <> wrote:

    >
    > > > Joost Diepenmaat <> writes:
    > > > > x = Math.ceil(list.length / 2)
    > > > > break_point = (list[x] - list[x+1]) / 2

    >
    > > > I meant Math.floor()

    >
    > > > --
    > > > Joost Diepenmaat | blog:http://joost.zeekat.nl/|work:http://zeekat.nl/

    >
    > > I have a series of numbers that i want to display on graph.
    > > Numbers are like 10, 40, 80, 100, 500, 10000, 100000. there are 50
    > > numbers
    > > Like the last column has value that is really higher.
    > > Here users can break this numbers into groups.
    > > But when I take the average using the no. of groups they want (100000
    > > -10)/6 = 16665.
    > > so the groups come out 10 - 16665.
    > > Now if i have to display this data on chart.
    > > all the 30 points come under group 10 - 16665 & couple of groups
    > > remain empty like 1ike no value exists in them because the difference
    > > between the lowest & highest element is too big(10,100000). So I want
    > > a method that computes an average or create groups based on logic.

    >
    > I think what you want to do is sort the numbers, then group them based
    > on their order index (1 to 50) rather than their value (10 to
    > 100,000).
    >
    > --
    > Rob


    Hi Tom, I am really new at javascript , can you give me some example
    or function that can do that.
    Thanks anyway.
    Sunny, Sep 26, 2008
    #7
  8. Sunny wrote:
    > Hi Is there a way to find a proper distance between large numbers.


    alt.homework is elsewhere. You do yourself no favor at all by not doing
    your homework by yourself. Trust me.


    PointedEars
    --
    Prototype.js was written by people who don't know javascript for people
    who don't know javascript. People who don't know javascript are not
    the best source of advice on designing systems that use javascript.
    -- Richard Cornford, cljs, <f806at$ail$1$>
    Thomas 'PointedEars' Lahn, Sep 26, 2008
    #8
  9. On 25 sep, 21:15, Sunny <> wrote:
    > Hi Is there a way to find a proper distance between large numbers.
    >
    > For example, if i have a set of numbers like:
    > 10, 40, 80, 100, 500, 10000
    > Now if I have to create a break points between these no.
    > I have to take an average & add that average to the starting number
    > like.
    > (10000 -10)/6 = 1665.
    > Now if I create a break point using this no. the break points will be:
    > 10 - 1675, 1675 - 3340, 3340 - 5005, 5005 - 6670 ....


    I do see all these evaluate to -1665, but I don't understand what you
    further mean. I really think you should rephrase the problem in a
    clearer way. Anyway, I think your algorithm would go like this:

    var nrs = [10, 40, 80, 100, 500, 10000];
    var breakpoints = new Array();
    var f = (nrs[nrs.length-1] - nrs[0]) / nrs.length;
    for (var i=0; i<nrs.length; i++)
    breakpoints = i * f - ((i+1) * f);
    document.write(breakpoints); // -1665 for every entry

    > [...]
    > Now if i have to display this data on chart.


    Line chart:
    http://code.google.com/apis/chart/#line_charts

    var nrs = [10, 40, 80, 100, 500, 10000];
    document.write('<img src="http://chart.apis.google.com/chart?'
    + 'chxt=y'
    + '&chxl=0:|0|'
    + nrs[nrs.length-1]/2 + '|' + nrs[nrs.length-1]
    + '&chs=400x400'
    + '&cht=lc'
    + '&chds=0,' + nrs[nrs.length-1]
    + '&chd=t:' + nrs
    + '">');

    Pie chart:
    http://code.google.com/apis/chart/#pie_charts

    var nrs = [10, 40, 80, 100, 500, 10000];
    var perc = new Array();
    var sum = 0;
    for (var i=0; i<nrs.length; i++)
    sum += nrs;
    for (var j=0; j<nrs.length; j++)
    perc[j] = nrs[j] / sum;
    document.write('<img src="http://chart.apis.google.com/chart?'
    +'chs=750x300'
    + '&chd=t:' + perc
    + '&cht=p3'
    + '&chl=' + nrs.join('|')
    + '">');

    Hope this helps,

    --
    Bart
    Bart Van der Donck, Sep 28, 2008
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andre

    Drawing a logarithmic histogram

    Andre, Jul 16, 2003, in forum: C Programming
    Replies:
    1
    Views:
    431
    Glen Herrmannsfeldt
    Jul 17, 2003
  2. Derek Basch

    Matplotlib logarithmic scatter plot

    Derek Basch, Feb 27, 2006, in forum: Python
    Replies:
    9
    Views:
    4,890
    evander21
    Nov 3, 2010
  3. Derek Basch
    Replies:
    8
    Views:
    413
    Fredrik Lundh
    Feb 28, 2006
  4. different

    logarithmic interpolation

    different, Jan 18, 2007, in forum: C Programming
    Replies:
    6
    Views:
    934
    Zbigniew Karno
    Jan 19, 2007
  5. different

    logarithmic interpolation

    different, Jan 18, 2007, in forum: C++
    Replies:
    5
    Views:
    3,800
    Zbigniew Karno
    Jan 19, 2007
Loading...

Share This Page