math

On the formulation of the linear assignment problem

I'm looking at the standard definition of the assignment problem as defined here My question is to do with the two constraints (latex notation follows): \sum_{j=1}^n(x_{ij}) = 1 for all i = 1, ... , n \sum_{i=1}^n(x_{ij}) = 1 for all j = 1, ... , n Specifically, why the second constraint required? Doesn't the first already cover all ...

converting R code snippet to use the Matrix package?

Hello, I am not sure there are any R users out there, but just in case: I am a novice at R and was kindly "handed down" the following R code snippet: Beta <- exp(as.matrix(read.table('beta.transpose'))) WordFreq <- read.table('freq-matrix') WordProbs <- WordFreq$V1 / sum(WordFreq) infile <- file('freq-matrix') outfile <- file('doc_to...

Finding a minimum bounding sphere for a frustum

I have a frustum (truncated pyramid) and I need to compute a bounding sphere for this frustum that's as small as possible. I can choose the centre to be right in the centre of the frustum and the radius be the distance to one of the "far" corners, but that usually leaves quite a lot of slack around the narrow end of the frustum This see...

C# XNA: Looking for a function like MathHelper.Clamp

I have a function that will take a range of values, which need to be normalized to the range [-1, 1]. MathHelper.Clamp() just takes values that are outside the range and sets them to be whichever bound it exceeds. Does XNA or C# have anything that does what I'm looking for? (I'm looking through the documentation but can't find it.) This...

Improving Numpy Performance

I'd like to improve the performance of convolution using python, and was hoping for some insight on how to best go about improving performance. I am currently using scipy to perform the convolution, using code somewhat like the snippet below: import numpy import scipy import scipy.signal import timeit a=numpy.array ( [ range(1000000)...

Create grid out of number of elements

Ok here's what I'm trying to accomplish. Say I have 100 items. I want to create a "grid"(each Item consisting of an x, y point). I want the grid to be as close to a square as possible. Is there any kind of math to determine the grid width, and grid height i'd need by just a single number?(By grid width and height I mean the number of x i...

Least Squares Regression in C/C++

How would one go about implementing least squares regression for factor analysis in C/C++? ...

What are the pros and cons of using Matrices, Euler Angles, and or Quaternions for rotation representation?

Matrices and Euler angles can suffer from Gimbal lock but what are some other arguments for using one over the other? What do you think DirectX favors? What do you use in daily C++/C/DirectX programming? ...

Project Euler #15

Hey everyone, Last night I was trying to solve challenge #15 from Project Euler: Starting in the top left corner of a 2×2 grid, there are 6 routes (without backtracking) to the bottom right corner. How many routes are there through a 20×20 grid? I figured this shouldn't be so hard, so I wrote a basic recursive f...

Combinatoric 'N choose R' in java math?

Is there a built in method in a java library that can compute 'N choose R' for any N, R? ...

Financial formula for calculating an Adjustable Rate Mortgage?

Need this for a c# app, can't find the formula anywhere nor can I wrap my head around it. Any Algebra gurus out there in overflow land? Basically, I need to calculate a fixed payment amount for a loan term that has two different interest rates based on how long the loan has been open. ...

What is the definition for the height of a tree?

I can't seem to find a definitive answer for this, I'm trying to do some elementary proofs on heaps but here's what's throwing me off a little bit: Is an empty tree valid? If so, what is its height? I would think this would be 0. What is the height of a tree with a single node? I would think this would be 1 but I have seen definitions...

Closest point on a path to a point, or: Dear target, sorry I missed you.

For a 2D game I'm working on, I'd like to figure out when a projectile reaches its closest to point to its target. A projectile is a point that moves by a constant dx,dy per frame. A target is another point whose speed relative to the projectile is slow enough as to be considered stationary. I want to have the projectile explode when it...

Finding intersect in triangle from a vector originating from a particular side

I know the coordinates of A, B and C.. I also know of a vector V originating from C.. I know that the vector intersects A and B, I just don't know how to find i. Can anyone explain the steps involved in solving this problem? Thanks alot. http://img34.imageshack.us/img34/941/triangleprob.png ...

print beautiful value with error

I want to display in a HTML page some datas with errors, for example: (value, error) -> string (123, 12) -> (12 +- 1) x 10^1 (4234.3, 2) -> (4234 +- 2) (0.02312, 0.003) -> (23 +- 3) x 10^-3 I've produced this: from math import log10 def format_value_error(value,error): E = int(log10(abs(error))) val = float(value) / 10**E ...

Bitwise operation on floating point numbers (for graphics)?

Possible Duplicate: how to perform bitwise operation on floating point numbers Hello, everyone! Background: I know that it is possible to apply bitwise operation on graphics (for example XOR). I also know, that in graphic programs, graphic data is often stored in floating point data types (to be able for example to "multiply"...

Python module matrix class that implements Modulo 2 arithmetic?

Hi, I'm looking for a pure Python module that implements a matrix class where the underlying matrix operations are computed in modulo 2 arithmetic as in (x+y)%2 I need to do a lot of basic matrix manipulations ( transpose, multiplication, etc. ). Any help appreciated. Thanks in advance ...

Do the math sum of a text variable? (E.g 5865/100 )

I have a variable that is... $whatever = "5865/100"; This is a text variable. I want it to calculate 5865/100 , so that I can add it to other numbers and do a calculation. Number_format doesn't work, as it just returns "5,865". Whereas I want it to return 58.65 I could do... $explode=explode("/",$whatever); if(count($explode)=="2")...

Actionscript 3 Math inconsistencies

Hello, I'm trying to build a calculator in Flex / actionscript 3 but have some weird results using the class Math : trace(1.4 - .4); //should be 1 but it is 0.9999999999999999 trace(1.5 - .5); //should be 1 and it is 1 trace(1.444 - .444); //should be 1 and it is 1 trace(1.555 - .555); //should be 1 but it is 0.9999999999999999 I kno...

why 48 bit seed in util Random class?

Why this class uses 48 bit seed in its linear congruence formula? I would have expected 32 or 64... I know it takes higher order bits when asked for 32 bit values. But why only 16 more additional bits? Was it a "random" choice? ...