math

Mathematical problem help.

I have some code where, if a user has referred X number of people, he will get X number of credits. For example, referring 2 people = 1 credit. 4 people = 2 credits, and so on. However where this gets tricky is, the numbers can be changed so he gets 1 credit per person, or 1 credit per 3 people, 1 credit for 5 people, etc. If he gets ...

What are the most widely used C++ vector/matrix math/linear algebra libraries, and their cost and benefit tradeoffs?

It seems that many projects slowly come upon a need to do matrix math, and fall into the trap of first building some vector classes and slowly adding in functionality until they get caught building a half-assed custom linear algebra library, and depending on it. I'd like to avoid that while not building in a dependence on some tangenti...

LINQ to SQL Math.Round Problem

Hello all, I'm having an issue with a query I wrote where for some reason the variable that I'm using to store a decimal value in returns 6 values after the decimal place (they're mostly 0). I have tried the following (and different combinations using Math.Round) with no luck. Sales = (from invhed in INVHEAD ......

Alternatives to the GNU Scientific Library

Are there any C libraries (preferably open source) which are comparable to the GNU Scientific Library (a large library of commonly science & math routines)? ...

Calculating vs. lookup tables for sine value performance?

Let's say you had to calculate the sine (cosine or tangent - whatever) where the domain is between 0.01 and 360.01. (using C#) What would be more performant? Using Math.Sin Using a lookup array with precalculated values I would anticpate that given the domain, option 2 would be much faster. At what point in the precision of the dom...

Help optimizing algorithm

I have a particular application that needs to calculate something very specific, and while I excel at logic, math has always been my weak spot. Given a number, say -20, it needs to apply a calculation of a 100 base (that is, the base is 100, not 0. not to be confused with base 100 which would be something else totally). In other words...

Code Golf: Mathematical expression evaluator (full PEMDAS)

I challenge you to write a mathematical expression evaluator that respects PEMDAS (order of operations: parentheses, exponentiation, multiplication, division, addition, subtraction) without using regular expressions, a pre-existing "Eval()"-like function, a parsing library, etc. I saw one pre-existing evaluator challenge on SO (here), b...

Are there libraries for Square Root over BigDecimal?

Are there any libraries for Square Root over BigDecimal in Java? ...

Recommended math library for C#/.NET?

Hi, I'm currently evaluating different math libraries for my next .NET project, the decent one I found is Math.NET, which is free and open-source. Do you have any recommendation for good math libraries?, free ones are preferable of course, but that isn't a prerequisite. EDIT: To make the question a bit more clear, I need a math to do ...

PHP Problem Solving

What's the best way to create a PHP form that takes a users input in the form of five decimal numbers: displays the five decimal numbers display the sum of the five decimal numbers display the average the five decimal numbers display each number rounded to the nearest integer? ...

Finding a minimum number of transformation

I need an algorithm which calculates something similar to the Levenshtein distance. It should calculate the minimal possible number of transformations to get from one sequence to another. The allowed transformations are deletion, insertion and move: Deletion of 3: before {1, 2, 3, 4}, after {1, 2, 4} Insertion of 5: before {1, 2, 3, 4}...

How to round to a specific decimal accuracy?

I have a value var i = 0.69999980926513672. I need to round this value to 0.7 is there a built-in method that will do this? ...

Problems with bit-shifting in complicated expressions

I've distilled an equation down to this: speed = ( ( rear_wheel_speed_a + front_wheel_speed_a ) << 10 ) + ( ( rear_wheel_speed_b + front_wheel_speed_b ) << 2 ); but for some reason I'm getting unexpected results so I must be doing something wrong. This started out like this: speed = ((((rear_wheel_speed_a * 256 + rear_wheel_s...

Interpolation on excel

Hi to all I've a source data like this: 35 40 -15 15.0 15.1 -10 17.2 17.4 -5 19.7 19.8 and I need to find the value in (-16, 37). I've tried with linear interpolation but I can solve only with (x,y) couple of values. Could you help me? thanks a lot, Andrea ...

Vector Education

Does anyone know where I could get a rundown of the vector math I'd need in order to program a raytracer? I could use a refresher of linear algebra and multivar calc since it's been a few years since I've taken those classes. ...

Detecting if two number ranges clash

This is hopefully a very simple maths question. If I have two number ranges, what is the simplest and most efficient way to check if they clash, eg: 10-20 and 11-14 // clash as B is contained in A 11-15 and 20-22 // don't clash 24-26 and 20-30 // clash as A is contained in B 15-25 and 20-30 // clash as they overlap at each end I curre...

Can I rely on this to judge a square number in C++?

Can I rely on sqrt((float)a)*sqrt((float)a)==a or (int)sqrt((float)a)*(int)sqrt((float)a)==a to check whether a number is a perfect square? Why or why not? int a is the number to be judged. I'm using Visual Studio 2005. Edit: Thanks for all these rapid answers. I see that I can't rely on float type comparison. (If I wrote as a...

3D Least Squares Plane

What's the algorithm for computing a least squares plane in (x, y, z) space, given a set of 3D data points? In other words, if I had a bunch of points like (1, 2, 3), (4, 5, 6), (7, 8, 9), etc., how would one go about calculating the best fit plane f(x, y) = ax + by + c? What's the algorithm for getting a, b, and c out of a set of 3D poi...

Could someone explain the math behind how this cube-rotating script works?

If you go to the following link you'll see a really cool Javascript simulation of a cube that rotates based on your mouse position. Simulation: here. If you view the source of the cube rotating script you'll see: <script type="text/javascript"> /* I wrote this script in a few minutes just for fun. It's not made to win any compe...

Power in sparql and other math functions

Hi I am trying to write a sparql query where I want to filter on the square of something, but I am simply unable to figure out how to square a number (x^2) (except by multiplying it with itself of cause.) I guessed a square root function called math:sqrt() which works, yet nothing like math:pow seems to exist. How do I get the square o...