Results 1 to 12 of 12

Thread: [RESOLVED] Calculate 'Maximum' value

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Resolved [RESOLVED] Calculate 'Maximum' value

    I'm playing around with a 'general purpose' plotting routine. I have about 20 different sets of data, each with it's own maximum possible value. The data is added to every 2 weeks.

    For instance, one set could range from 0 to 600 whilst another could be 0 to 20.

    What I would like to do is find the maximum value in a given set and then round it up to, say, in the case of the 0 to 600 series, the nearest 50/100. So if the largest value in week n is 575 I'd like to round it to 600. in the case of a series from 0 to 20, if the largest value is 15.5 I'd like to round it up to 20.

    The rounded value will be used to set the maximum Y value on the chart.

    I can think of a method, involving repeatedly diving by 10 to find the magnitude but was wondering if anyone has a more elegant solution.

    The language is fairly unimportant, although a 'basic' type would be helpful. The implementation will be in Mobile Basic for iPad.

  2. #2

    Thread Starter
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Calculate 'Maximum' value

    Thought it may help if you saw a screen shot. Looking at the Platelets plot the largest value is 552 and I would like then 'ymax' to be 600. I also will need to annotate the y axis with appropriate values. The largest Neuts is 11.4 and I would like to sent 'ymax' to 20 on that graph.
    Attached Images Attached Images  

  3. #3
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: Calculate 'Maximum' value

    Since I know PHP best, I wrote the following code in PHP. The theory could easily be implemented in any language.

    PHP Code:

    $number 
    65;

    if (
    $number 100) {
         
    $round 10;
    } elseif (
    $number 100 && $number 1000) {
         
    $round 100;
    } elseif (
    $number 1000 && $number 10000) {
         
    $round 1000;
    }

    echo 
    ceil($number$round) * $round

    You can see it in action here... Change the Number variable to see different numbers.
    http://sandbox.onlinephpfunctions.co...fa06866fac6cf2

  4. #4
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Calculate 'Maximum' value

    I had a go at converting the php code into VB.NET.

    VB.NET Code:
    1. Public Class Form1
    2.  
    3.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    4.         Dim number As Integer, round As Integer
    5.         number = 100
    6.         If number < 100 Then
    7.             round = 10
    8.         ElseIf number >= 100 & number < 1000 Then
    9.             round = 100
    10.         ElseIf number >= 1000 & number <= 10000 Then
    11.             round = 1000
    12.         End If
    13.         MessageBox.Show(Math.Ceiling(number / round) * round)
    14.     End Sub
    15. End Class
    Last edited by Nightwalker83; May 18th, 2014 at 06:19 AM. Reason: Fixed errors!
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  5. #5
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: Calculate 'Maximum' value

    Addition to the above code. It should be greater than equal to and lessthan equal to... I got errors if the number was 100, 1000, etc

  6. #6
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Calculate 'Maximum' value

    Quote Originally Posted by dclamp View Post
    Addition to the above code. It should be greater than equal to and lessthan equal to... I got errors if the number was 100, 1000, etc
    Ah ok thanks! That is what I had originally but deleted it since you didn't have it in your code.
    Last edited by Nightwalker83; May 18th, 2014 at 06:20 AM. Reason: Fixed grammar!
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  7. #7
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: Calculate 'Maximum' value

    Quote Originally Posted by Nightwalker83 View Post
    Ah ok thanks! That is what I had originally but deleted it since you didn't have it in your code.
    Yeah I didnt update the code, But updated in the sandbox thing I was playing with. Also, on the last condition you have <= 1000, should be 10000

  8. #8
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Calculate 'Maximum' value

    Quote Originally Posted by dclamp View Post
    Yeah I didnt update the code, But updated in the sandbox thing I was playing with. Also, on the last condition you have <= 1000, should be 10000
    Fixed!

    Code:
         ElseIf number >= 1000 & number <= 10000 Then
    Edit:

    I originally tried to convert it to VB6 but none of codes for ceil (that I found) worked correctly.
    Last edited by Nightwalker83; May 18th, 2014 at 06:29 AM. Reason: Adding more!
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  9. #9
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: Calculate 'Maximum' value

    How about something like (VB6):

    Code:
    Private Sub FindScaleMax()
        Dim OrderMag As Single
        Dim Mag As Single
    
        OrderMag = Int(Log(Largest) / Log(10)) 'Integer part of Log10(Largest).
    
        Mag = 10 ^ OrderMag
    
        ScaleMax = (Int(Largest / Mag) + 1#) * Mag
    End Sub
    Name:  sshot.jpg
Views: 201
Size:  23.6 KB
    Attached Files Attached Files

  10. #10

    Thread Starter
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Calculate 'Maximum' value

    Perfect. Thanks Dilettante.

  11. #11
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: [RESOLVED] Calculate 'Maximum' value

    I was a little surprised you didn't get an answer earlier.

    This is an example of a class of small problems often used for the performance section of programming job interviews in scientific and engineering companies. They send you to the whiteboard to watch you solve a few such problems. Even if the problem isn't completed, and it generally isn't, attempted solutions using logarithms are "pass" and anything based on iteration is a "fail."

    Some say this skews in favor of "conventionality" while the defenders says it evaluates problem solving skills.

  12. #12

    Thread Starter
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: [RESOLVED] Calculate 'Maximum' value

    I might have come up with the Log solution given enough time. The next interesting problem is using the scale max to create tick marks and labels for the y-axis. When I get stuck no doubt I'll be posting here again.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width