math

Simplest way to solve mathematical equations in Python

Short Question: Lets say, I want to solve Project Euler problem 9 using python and some equation solving libraries. a + b + c = 1000. a2 + b2 = c2 How do you do it. Long Question: I want to solve a set of equations; linear, sometimes may be quadratic too. Not a specific problem; but often, I have been in situation I wanted to. I...

Getting Unique Number Combinations

Is it possible without using exponentiation to have a set of numbers that when added together, always give unique sum? I know it can be done with exponentiation (see first answer): http://stackoverflow.com/questions/1619379/the-right-way-to-manage-user-privileges-user-hierarchy But I'm wondering if it's possible without exponentiation....

Intel MKL vs. AMD Math Core Library

Does anybody have experience programming for both the Intel Math Kernel Library and the AMD Math Core Library? I'm building a personal computer for high performance statistical computations and am debating on the components to buy. An appeal of the AMD Math Core library is that it is free, but I am in academia so the MKL is not that ex...

Calculating Length Based on Sensor Data

I've got an IR sensor which writes its current information to a token which I then interpret in a C# application. That's all good -- no problems there, heres my code: SetLabelText(tokens [1],label_sensorValue); sensorreading = Int32.Parse(tokens[0]); sensordistance = (mathfunctionhere); Great. So the further away the IR sensor is from...

Why, when I'm adding two integers, does PHP return a bad result (6+7=1)?

I have two variables: $qty = 7; $_POST['qty'] = 6; var_dump($qty, $_POST['qty']); // both vars are integers $_SESSION['qty'] = $qty + $_POST['qty']; echo '='.$_SESSION['qty']; This returns: int(7) int(6) =1 (int)$qty, (int)$_POST['qty'] doesn't solve the problem. What am I doing wrong? Update: ... intval($qty) + intval($_POST['...

rotating multidimension matrix.

Given a 4x4 matrix, what formula could i apply to each (x,y) cell to yield an (x,y) if the matrix was rotated 90 degrees to the right? I tried iterating over each cell but different cells gave different formulas. Given the following matrix of values. 0| | | | | 1| | | | | 2| | | | | 3| | | | | ------------- ...

Technique for determining if an integer sequence can be generated without branches?

If you're optimizing for an architecture on which branching is expensive (say the PS3's cell processor), it can be important to be able to determine whether or not you can express a given algorithm without using branches or at least using fewer branches. One pattern that I see a lot in unoptimized code is a bunch of if's used to tweak a...

What programming language will enable me to enter a very long number without converting it to floating point?

What would be the best way to do the following. Enter a very long number, lets say 500,000 digits long without it going into scientific notation; and then am able to do math with it, like +2 etc.? Thank you in advance. EDIT: It is a 500,000 digit, positive integer. ...

Random.Next returns always the same values

This is really weird, and I cannot see why this is happening. In the foreach cycle, I am iterating through a class A collection, and for each class, I call the Count() method, where r1 and r2 numbers are generated from range [-1,1]. The problem is that Random.Next returns the same "random" numbers for each instance. When the results for...

How many possible URLs can you make with the following characters?

I want to make a short URL service for 2 million assets but I want to use the shortest number of possible characters. What is the math equation that I would need to use to figure it out? I know it has something to do with factorials, right? ...

How can I turn a floating point number into the closest fraction represented by a byte numerator and denominator?

How can I write an algorithm that given a floating point number, and attempts to represent is as accurately as possible using a numerator and a denominator, both restricted to the range of a Java byte? The reason for this is that an I2C device wants a numerator and denominator, while it would make sense to give it a float. For example,...

MySQL Order by math

Hello There, I want to order a result by fieldx * fieldy, for example: Row 1: fieldx = 10 fieldy = 10 Total: 100 Row 2: fieldx = 11 fieldy = 5 Total: 55 Row 1 has to appear first. Couldn't find anything about it. It's for a codeIgniter project, so if there is a solution with that I'm very happy. Thanks! ...

How should I throw a divide by zero exception in Java without actually dividing by zero?

I have an I2C device that wants two inputs: a denominator and a numerator. Both are written to separate addresses, so no actual calculation (numerator/denominator) is done. The problem with this is that a divide by zero could occur on the I2C device, so a divide by zero error needs to be checked for. Ideally, exactly the same thing would...

Generating a random winner and displaying the odds of winning - am I doing this right?

I'm running a contest on a website and I have 3215 entrants who are eligible for 5x Sony PSPs. I believe the formula to count the odds is totalEntrants - prizes / prizes: (3215-5)/5 = 642 so that's an odds of 642 to 1 of winning - is that right? ( I suck at math ) And in my table which contains 3215 rows in the database I would just s...

How to make sure if a polynomial curve is monotonic under interval [a,b]?

Hi, guys, If I got a polynomial curve, and I want to find all monotonic curve segments and corresponding intervals by programming. What's the best way to do this... I want to avoid solving equation like f'(x) = 0; Using some nice numerical ways to do this,like bi-section, is preferred. f'(x) expression is available. Thanks. Add addit...

How can I parse a mathematical function from user input in Perl?

I wrote a tool for polar functions. It lists values from an input range like that: 0 Grad: (0 RAD|1 RES) 20 Grad: (0.349065850398866 RAD|1.3639702342662 RES) 40 Grad: (0.698131700797732 RAD|1.83909963117728 RES) 60 Grad: (1.0471975511966 RAD|2.73205080756888 RES) 80 Grad: (1.39626340159546 RAD|6.67128181961771 RES) 100 Grad: ...

How can I box content in LaTeX such that all boxes are on the same line and the same height?

I need to represent calculator key presses by the text for the keys to press surrounded by a box. I tried to get away with just the bare key presses (no box) but I got marked down for it because it would appear my assessor is a bit of a pedant. Anyway, a bit of research turned up the likes of \boxit and \fbox. I gave them both a go but...

Why does Visual Studio 2008 tell me .9 - .8999999999999995 = 0.00000000000000055511151231257827?

When I type this into the Visual Studio 2008 immediate window: ? .9 - .8999999999999995 It gives me this as the answer: 0.00000000000000055511151231257827 The documentation says that a double has 15-16 digits of precision, but it's giving me a result with 32 digits of precision. Where is all that extra precision coming from? ...

Standard Normal Distribution z-value function in C#

I been looking at the recent blog post by Jeff Atwood on Alternate Sorting Orders. I tried to convert the code in the post to C# but I ran into an issue. There is no function in .NET that I know of that will return the z-value, given the percentage of area under the standard normal curve. The recommended values to use for the algorithm a...

CSS Transformation

Hello, how can I change with CSS (-moz-transform) a div that should look like this: ...