math

Summation notation in Haskell

On the Wikipedia page about summation it says that the equivalent operation in Haskell is to use foldl. My question is: Is there any reason why it says to use this instead of sum? Is one more 'purist' than the other, or is there no real difference? ...

Calculating area enclosed by arbitrary polygon on Earth's surface

Say I have an arbitrary set of latitude and longitude pairs representing points on some simple, closed curve. In Cartesian space I could easily calculate the area enclosed by such a curve using Green's Theorem. What is the analogous approach to calculating the area on the surface of a sphere? I guess what I am after is (even some appr...

How would one implement an FPS camera?

So I'm currently working on some FPS game programming in OpenGL (JOGL, more specifically) just for fun and I wanted to know what would be the recommended way to create an FPS-like camera? At the moment I basically have a vector for the direction the player is facing, which will be added to the current player position upon pressing the "...

Calculate a vector from the center of a square to edge based on radius

Given a square (described by x, y, width, height) and an angle (in radians) I need to calculate a vector that originates at the squares centre and terminates at the point that collides with the edge of the square at the given angle. I'm really most interested in the point it collides at so if that would make calculation more efficient l...

Combinatorics with repeated chars on initial group

I know that if I have the following group of numbers { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 } I can have 5040 different 4-digit numbers, using 10! / (10 - 4)! But if I repeat one number on the initial group, like { 1, 1, 2, 3, 4, 5, 6, 7, 8, 9 } How many different 4-digit numbers can we build ? I know the answer is 3360, just don't know h...

Mathematics textbook for program analysis

Im going to do a course on program analyis (dataflow analysis, abstract interpretation etc). What mathematics textbook will cover all the prerequisite math for this topic? ...

Multiple Linear Regression

I am trying to use GLSMultipleLinearRegression (from apache commons-math package) for multiple linear regression. It is expecting a covariance matrix as input -- I am not sure how to compute them. I have one array of dependent variables and 3 arrays of independent variables. Any idea how to compute the covariance matrix? Note: I have 2...

Is there any way to find arithmetic mean "better" than sum()/N?

Suppose we have N numbers(integers, floats, whatever you want) and want to find their arithmetic mean. Simplest method is to sum all values and divide by number of values: def simple_mean(array[N]): # pseudocode sum = 0 for i = 1 to N sum += array[i] return sum / N It works fine, but requires big integers. If we don...

Why does C++ define the norm as the euclidean norm squared

This may sound like a bit of a rhetorical question, but I ask it here for two reasons: It took me a while to figure out what C++ std::norm() was doing differently from Matlab/Octave, so others may stumble upon it here. I find it odd to define the norm() function as being something different (though closely related) to what is generally...

Why does Math.Floor(Double) return a value of type Double?

Hi All, I need to get the left hand side integer value from a decimal or double. For Ex: I need to get the value 4 from 4.6. I tried using Math.Floor function but it's returning a double value, for ex: It's returning 4.0 from 4.6. The MSDN documentation says that it returns an integer value. Am I missing something here? Or is there a dif...

Connecting two planes in 3d

Hi, Given two planes positioned and rotated arbitrary to each other, I'm trying to determine which vertices should be connected. The image below (planes in black, connecting edges in red) illustrates two examples on how the planes might look: Comparing the distances between vertices won't work as the planes are not (necessarily) posi...

Find a tangent point on circle?

Given a line with first end point P(x1,y1) another end point is unknown, intersect with a circle that located at origin with radius R at only one point(tangent) T(x2,y2). Anyone know how to get the point T? Thanks in advance! ...

Complex Calculations

What are the best tools (most efficient) available in .NET (C#) for calculating: integrals partial derivatives other non-trivial math Can people please comment on Mathematica and Matlab and their integration into C#? ...

Can someone abuse LINQ and solve this money problem?

For the fun of it, I would like to see someone use and abuse LINQ to solve this money problem. I really have no idea how you would do it - I suppose Populating some set and then selecting off of it. If given a total number of coins and give the total amount of all coins added together: Show every possible combination of coins. Coins are...

mapping from normalized device coordinates to view space

Hey there! I'd like to map from normalized device coordinates back to viewspace. The other way arround works like this: viewspace -> clip space : multiply the homogeneous coordinates by the projection matrix clip space -> normalized device coordinates: divide the (x,y,z,w) by w now in normalized device coordinates all coordinates wh...

Express mathematical infinity in C#

Is it possible to express (mathematical) infinity, positive or negative, in C#? If so, how? ...

The possible number of binary search trees that can be created with N keys is given by the Nth catalan number. Why?

This has been bothering me for a while. I know that given N keys to arrange in the form of a binary search tree, the possible number of trees that can be created correspond to the Nth number from the Catalan sequence. I have been trying to determine why this is; unable to find anything that might even attempt to explain it intuitively ...

Generating ids for a set of integers

Background: I'm working with permutations of the sequence of integers {0, 1, 2 ... , n}. I have a local search algorithm that transforms a permutation in some systematic way into another permutation. The point of the algorithm is to produce a permutation that minimises a cost function. I'd like to work with a wide range of problems, fro...

Compressing big number (or string) to small value

Friends, Here is the situation: An ASP.NET page has following query string parameter. MyServer.com/ShowSomething.aspx?IDs=1000000012,1000000021,1000000013,1000000022&... Here IDs parameter will always have numbers separated by something, in this case ",". Currently there are 4 numbers but normally they would be in between 3-7. Now, I...

PHP: What's the mathematically efficient way to find a 'subgrid' of a larger grid?

Hi, i'm trying to find an efficient way to find a subportion of a large grid. Currently I'm looping through rows to define a FROM-TO selection of ids in that row, but this doesn't feel right... Let's say I have a grid of 200x200 fields (x between 1 and 200, y between 1 and 200). Every field also has it's unique ID, starting at X1,Y1 (f...