Archive for the 'Math' Category
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 »
October 16th, 2009 | Posted in Java, Math | No Comments
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 »
October 16th, 2009 | Posted in Java, Math | 1 Comment
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 »
October 16th, 2009 | Posted in Java, Math | No Comments
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 »
July 8th, 2009 | Posted in Math, Python | No Comments
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 »
March 11th, 2009 | Posted in Java, Math | 2 Comments
<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 »
January 3rd, 2009 | Posted in Java, Math | 1 Comment
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 »
January 2nd, 2009 | Posted in Math, Python, Statistics | 5 Comments
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 »
December 28th, 2008 | Posted in C#, Math, Tip | 1 Comment
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 »
December 28th, 2008 | Posted in C#, Math, Tip | No Comments
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 »
December 27th, 2008 | Posted in C#, Math, Tip | No Comments