math

Why doesn't the Random.Next method in .NET support floats/double?

So maybe I want to have values between -1.0 and 1.0 as floats. It's clumsy having to write this and bolt it on top using extension methods IMO. ...

Ruby: Math functions for Time Values

How do I add/subtract/etc. time values in Ruby? For example, how would I add the following times? 00:00:59 + 00:01:43 + 00:20:15 = ? ...

Ellipse bounding a rectangle

Maths101 question - does anyone know how to calculate an ellipse (width/height) that will enclose a given rectangle. Obviously there is no single ellipse - I'm after an algorithm that will give me various width/height combinations - or perhaps the smallest area of ellipse? It's for a GUI, so an aesthetically pleasing ratio of height/widt...

Does the .NET framework provide any built in classes for performing geometric calculations?

What does the .NET framework provide, if anything, in the way of classes for performing geometric calculations? For example, calculating the distance between two points (represented as (x,y)) or solving a right triangle's unknown sides or internal angles? (I know that both of those are pretty easily solved; I'm just using those as exampl...

Essential Math for excelling as a Programmer?

Hi everyone, I was just wondering about math as a programmer. I DO use math a fair bit, mainly vector math and occasionally trigonometry when I do games programming. My question: Do you consider there to be any essential math that you as a programmer must know in order to be a successful (and awesome) programmer? Mainly I have found th...

how to do Hit testing in GDI+ ?

I have a canvas that contains many shapes and every shape has a location, size and rotation angle (size and location are in inches) and I want to check if mouse position is within which shape (the rotated shape) ?? can anyone help? ...

Algorithm for ProjectEuler Problem 99

From http://projecteuler.net/index.php?section=problems&id=99 Comparing two numbers written in index form like 211 and 37 is not difficult, as any calculator would confirm that 211 = 2048 37 = 2187. However, confirming that 632382518061 > 519432525806 would be much more difficult, as both numbers contain ...

How to do Unit Testing with Uncertainties?

We have several different optimization algorithms that produce a different result for each run. For example the goal of the optimization could be to find the minimum of a function, where 0 is the global minima. The optimization runs returns data like this: [0.1, 0.1321, 0.0921, 0.012, 0.4] Which is quite close to the global minima, so...

"Approximate" greatest common divisor

Suppose you have a list of floating point numbers that are approximately multiples of a common quantity, for example 2.468, 3.700, 6.1699 which are approximately all multiples of 1.234. How would you characterize this "approximate gcd", and how would you proceed to compute or estimate it? Strictly related to my answer to this questio...

Hexgit number?

if digit is the name for a number on base 10, what would be the name for a number on base 16? Hexgit? ...

probability interview question, random sampling

This is a good one because it's so counter-intuitive: Imagine an urn filled with balls, two-thirds of which are of one color and one-third of which are of another. One individual has drawn 5 balls from the urn and found that 4 are red and 1 is white. Another individual has drawn 20 balls and found that 12 are red and 8 are white. Whi...

Base 3 Combinatorics

I've never been much for math and I'm hoping that someone can help me out with the following. I have 5 boxes: 1 2 3 4 5 [ ] [ ] [ ] [ ] [ ] The boxes can either be white, gray, or black (or think of it as 0, 1, 2) How many possible states can the box set be in? What is the pseudocode (or in any language) to generate all t...

What's the highest-level math you've used in the real world?

What's the highest-level math you've used in the real world? What did you need it for? Where did you learn it (in school, by yourself)? (Incidentally, I do mean in a programming context, as this is a programming website.) Note: I'm not wondering if mathematics is necessary for programming or the relationship between math and programm...

How can I calculate the age of a person in year, month, days?

I want to calculate the age of a person given the date of birth and the current date in years, months and days relative to the current date. For example: >>> calculate_age(2008, 01, 01) 1 years, 0 months, 16 days Any pointer to an algorithm that does that will be appreciated. ...

How use NSDecimalNumber?

Hi, I'm building a app that needs to perform calculations on money. I wonder how to properly use NSDecimalNumber, especially how to initialize it from integers, floats & doubles? I only found it easy to use the -decimalNumberWithString: method. The -initWith... methods are discouraged so that only left the ones with mantissa, but never...

What is the best book on numerical methods?

I need to use some heavy-duty numerical methods - quadrature, interpolation, ODE solution with expensive derivative terms, etc. What's the best book on the subject? I will be using packages where I can, but I can already tell there will be times when I need to write my own routines... ...

Projecting a screen for a camera

I'm trying to learn a little more on vectormath through writing a simple ray tracer and I've been doing some reading on it, but what I haven't been able to find is how to determine the direction of the primary rays. This sounds like a simple problem and probably is, but with my current knowledge I haven't been able to figure it out. I ...

How can I do regression analysis in Sage?

I tried this unsuccessfully: find_fit(data, quadratic_residues) I am trying to find the best-fit for data about water flow rates: http://dl.getdropbox.com/u/175564/rate.png ---edit after the comment--- The new code: var('x') model(x) = x**2 find_fit((xlist, reqlist), model) The error message: Traceback (click to the left for tra...

Displaying fancy equations with Java

I'm working on a Java applet that needs to display "fancy" equations. Is there any Java renderer for MathML or LaTeX that's open source? Ideally it would be a pure Java solution that doesn't use JNI. Ideally it would also allow to animate the generated glyphs (e.g. animating adding a constant to both sides of a equation, lines going thr...

Math requirement to apply for course?

Hi I have been programming for a while now and I'm about to leave my job to study more. The course I want to study says it requires year 12 / sixth form mathematics or I can take an exam there when I apply. I never did any year 12 so I have no idea what to expect. My maths have been fine for what I need so far but I'm worried that I'll b...