math

Given a vector of maximum 10 000 natural and distinct numbers, find 4 numbers(a, b, c, d) such that a + b + c = d.

Hi, I solved this problem by following a straightforward but not optimal algorithm. I sorted the vector in descending order and after that substracted numbers from max to min to see if I get a + b + c = d. Notice that I haven't used anywhere the fact that elements are natural, distinct and 10 000 at most. I suppose these details are the...

Roots of a Quartic Function

Hey guys, I came across a situation doing some advanced collision detection, where I needed to calculate the roots of a quartic function. I wrote a function that seems to work fine using Ferrari's general solution as seen here: http://en.wikipedia.org/wiki/Quartic_function#Ferrari.27s_solution. Here's my function: private functi...

Haskell math performance

I'm in the middle of porting David Blei's original C implementation of Latent Dirichlet Allocation to Haskell, and I'm trying to decide whether to leave some of the low-level stuff in C. The following function is one example—it's an approximation of the second derivative of lgamma: double trigamma(double x) { double p; int i; ...

Static Typing and Writing a Simple Matrix Library

Aye it's been done a million times before, but damnit I want to do it again. I'm writing a simple Matrix Library for C++ with the intention of doing it right. I've come across something that's fairly obvious in mathematics, but not so obvious to a strongly typed system -- the fact that a 1x1 matrix is just a number. To avoid this, I s...

Is OOP based on any branch of mathematics?

I know relational databases are based on set-theory, functional programming is based on lambda calculus, logic programming is based on logic (of course :)), and now that I think of it; I'm not sure if imperative and generic programming is based on any particular branch of mathematics either. ...

Algorithm possible amounts (over)paid for a specific price, based on denominations

In a current project, people can order goods delivered to their door and choose 'pay on delivery' as a payment option. To make sure the delivery guy has enough change customers are asked to input the amount they will pay (e.g. delivery is 48,13, they will pay with 60,- (3*20,-)). Now, if it were up to me I'd make it a free field, but app...

Integration (math) in C++

Hi all, I'm looking for a library to find the integral of a given set of random data (rather than a function) in C++ (or C, but preferably C++). There is another question asking about integration in C but the answers discuss more how to integrate a function (I think...). I understand that this can be done simply by calculating the ar...

Python program for NIST randomness equation

There is a recurrence equation on page 1789 of this paper and I need some help making a python program to calculate pi_i. I have no idea what is going on here. Other references:original paper, pages (according to adobe, not the physical pages) 43 and 86 edit and i had already deleted what i wrote because all the answers i got were 0, ...

Power function fit to data set

I have a set of data (in ArrayCollection) and I need to fit a power function { f(x)= B + x^alpha } to it, before display in LineChart. As result I need the alpha and B paremeter. How to do this with Flex? ...

Real life usage of the projective plane theory

I'm learning about the theory of the projective plane. Very generally speaking, it is an extension of the plane, which includes additional points which are defined as the intersection points of two parallel lines. In the projective plane, every two lines have an interesection point. Whether they're parallel or not. Every point in the pro...

Algorithm for optimally choosing actions to perform a task

There are two data types: tasks and actions. An action costs a certain time to complete, and a set of tasks this actions consists of. A task has a set of actions, and our job is to choose one of them. So: class Task { Set<Action> choices; } class Action { float time; Set<Task> dependencies; } For example the primary task could be "Get...

Android-Java: Constructing a triangle based on Coordinates on a map and your bearing

Thanks, EDIT/// Converting the outcome to radians gives me a lat of 5.6xxxxxxxxxxxxxx .I have a feeling this bug has something to do with conversions but its not THAT simple. The equation is correct, it just.. outputs wrong.. ...

How to know coordinates in a real image from a scaled image.

Hi folks, First of all thanks for your time reading my question :-) I have an original image (w': 2124, h': 3204) and the same image scaled (w: 512, h: 768). The ratio for width is 4.14 (rw) and the ratio for height is 4.17 (rh). I'm trying to know the coordinates (x', y') in the original image when I receive the coordinates in the s...

OverflowError: math range error

>>> import math >>> math.pow(2, 3000) Traceback (most recent call last): File "<stdin>", line 1, in <module> OverflowError: math range error How can I fix it? thanx. ...

Calculating the null space of a matrix

I'm attempting to solve a set of equations of the form Ax = 0. A is known 6x6 matrix and I've written the below code using SVD to get the vector x which works to a certain extent. The answer is approximately correct but not good enough to be useful to me, how can I improve the precision of the calculation? Lowering eps below 1.e-4 causes...

adding two variables together

I have been trying for... about 4 hours now lmao. currentCalc returns 50 currentSum returns 0 when i alert them. Yet I cannot add them together with parseInt???? what am i doing wrong :'( var identRow = $('tr.identRow'); identRow.each(function () { var getIdentClass = $(this).attr('class').split(' ').slice(1); $('tr.ohp' + get...

log2 in python math module

why doesn't it exist? import math [x for x in dir(math) if 'log' in x] ['log', 'log10', 'log1p'] I know I can do log(x,2), but log2 is really common, so I'm kind of baffled. Oh, it looks like it's only defined in C99, not C90, I guess that answers my question. Still seems kind of silly. ...

How do I calculate arc angle between two points on a circle?

Given a circle with a known center point and two points on the circle (thus known radius), how do I determine the angle of the minimum arc between the two points on the circle? ...

Uniform distance between points

Hello, How could I, having a path defined by several points that are not in a uniform distance from each other, redefine along the same path the same number of points but with a uniform distance. I'm trying to do this in Objective-C with NSArrays of CGPoints but so far I haven't had any luck with this. Thank you for any help. EDIT I wa...

Algorithm for Determining Variations of Differing Lengths

I have four objects - for the sake of arguments, let say that they are the following letters: A B C D I need to calculate the number of variations that can be made for these under the following two conditions: No repetition Objects are position agnostic Taking the above, this means that with a four object sequence, I can have only o...