Archive for the 'Math' Category

How to Find Interquartile Range in Java

In this post, I explained how to find quartiles in a list of numbers. As a slight add-on to that functionality, you can easily get the interquartile range. This basically means that you are finding the difference between the first and third quartiles.
So I use the code to compute the quartiles and then use simple [...] Read more »

How to Get Quartiles in Java

For a brief overview of what quartiles are, you might read the Wikipedia page on this topic.
Basically, what it means is that if you were to break a list of numbers into four even parts, these would be the values that would separate them. But it gets a little complicated when your list doesn’t break [...] Read more »

Java: Is an Integer an Odd Number?

This is a pretty simple tip, but I still thought I would share it for anyone who is interested. To find out whether an integer is odd, you can use the modulo operator. This operator tells you the remainder after dividing the number by some other number. If you divide any integer by 2, you [...] Read more »

Minimum or Maximum Float Value in Python 2.5

In Python 2.5, there is a built-in function that tells you the maximum allowable int value:

import sys
print sys.maxint

But there is no corresponding function to do this for float values. Part of the reason may be that it can vary from system to system. But actually, I believe they added this in version 2.6. So this [...] Read more »

Simple Way to Compute Median in Java

There is no way that I know of to find the median of a list of numbers in the Java framework. The median is the middle value. If there is an even number of values, the median is the middle of these two numbers. Below is a method, along with a supporting method and some [...] Read more »

How to Round Numbers (double, float) in Java to Number of Decimal Places

<rant>For some strange reason, Java doesn’t have the ability to round numbers to a given number of decimals. This seems like such an obvious thing to include in any programming language.</rant> Anyway, you can round to the nearest integer, so you have to a little workaround to round to a given number of decimal places. [...] Read more »

Find the Mean/Average of a Number List in Python

To my knowledge, there is no built-in function in Python to find the mean of a list of numbers. You can use statistics packages to do this, such as statpy, but if you just want a lightweight solution to do the trick you can use the function below. Note that on the first line I [...] Read more »

Find the Mean of an Array of Numbers in C#

Let’s say you have an array of numbers and want to be able to find the mathematical mean of those numbers in C#. To my knowledge, the .NET Framework does not have a function to do this built in. (Please let me know if you know otherwise.) So I built a method that does this. [...] Read more »

Find the Sum of an Array of Numbers in C#

Let’s say you have an array of numbers (either doubles or integers) and want to be able to find the sum of these numbers. To my knowledge, there is not a built-in way to do this in the .NET Framework, so I created a little utility method that does this for doubles and for integers. [...] Read more »

Find the Mathematical Product of Double Array in C#

If you have an array of doubles (or floats) in C#, there is no built-in method (that I know of) to find the product of those numbers. The product is where you multiply all of the numbers together. I needed this, so I created a utility method that does this simple operation. See below.

public static [...] Read more »