math

Math.sqrt(-5) -> Force Exception in JSP?

I've 3 .jsp files. index.jsp and sqrtcalculator.jsp and error.jsp. In index.jsp there's a text field and a button. In sqrtcalculator.jps there's the, well, calculator. Now, when I leave the field empty and press the button, an expection is called, because the field is empty. And I can then reroute to an individual error.jsp site to dis...

Algorithm for logarithmically converting a number to a percentage

I am looking for a way to convert any number to a percentage in the following way: 1.00 is 50% numbers below 1.00 approach 0% logarithmically numbers above 1.00 approach 100% logarithmically. x > 0. So y needs to approach 0 as x becomes infinitely small on the positive side. I'm sure this is simple to do, but I can't recall how ...

Averaging angles... Again

I want to calculate the average of a set of angles, which represents source bearing (0 to 360 deg) - (similar to wind-direction) I know it has been discussed before (several times). The accepted answer was Compute unit vectors from the angles and take the angle of their average. However this answer defines the average in a non intuitiv...

Intersection between bezier curve and a line segment

I am writing a game in Python (with pygame) that requires me to generate random but nice-looking "sea" for each new game. After a long search I settled on an algorithm that involves Bezier curves as defined in padlib.py. I now need to figure out when the curves generated by padlib intersect a line segment. The brute force method would b...

2D Mathematics Geographical Directions

Hi All, I am trying to check the location of a point(px, py) on 2D graph in relation to a line segment (lx1, ly1) (lx2, ly2), using logic of North South East West directions. The logic I have implemented is to draw a perpendicular on the line segment from the point. if perpendicular is on line that means its south. If point on right...

multidimensional images raw data format

Is there a lowest common denominator format for multidimensional images or matrices analogous to netpbm/netpgm for 2d images? How would you use protocol buffers to define a 3d image or matrix of 16 bit unsigned numbers? Why didn't the netpbm people allow more dimensions in the row, column line? ...

How to raise a double value by power of 12?

I have a double which is: double mydouble = 10; and I want 10^12, so 10 * 10 * 10 * 10 * 10 * 10 * 10 * 10 * 10 * 10 * 10 * 10. I tried double newDouble = pow(10, 12); and it returns me in NSLog: pow=-1.991886 makes not much sense... I think pow isn't my friend right? ...

Calculating revenue share at different tiers

I'm trying to write a function that can calculate revenue at different tiered levels... For example you sell $10000 worth of widgets. Any earnings from $1 - $999 we take 50%, $1000 - $4999 we take 25%, $5000 - $9999 we take 10%, $10000 - $19999 5%. The percentage is not taken based on the final value. So if you earned $10000 you don't ...

How to generate this sequence programmatically

Hello, How can i generate dynamically this array. var posX:Array = [0,-20,20,-40,0,40,-60,-20,20,60,-80,-40,0,40,80,-100,-60,-20,20,60,100] The numbers in the array refer to the x position of the object. I use it to place objects in triangular formation. 0 -20 20 -40 0 40 -60 -20 20 60 etc Thank you in advance ...

If there are M different boxes and N identical balls

and we need to put these balls into boxes. How many states of the states could there be? This is part of a computer simulation puzzle. I've almost forget all my math knowledges. ...

Get the slope from one point and an angle in degrees.

In javascript, I am trying to draw a line that is at an angle that is user defined. Basically, I have a point (x,y) and an angle to create the next point at. The length of the line need to be 10px. Let's say that the point to start with is (180, 200)... if I give it angle "A" and the (I guess)hypotenuse is 10, what would my equation(s...

Integer Relation Implementation (finding ratio between real numbers)

Can anyone point me to a library or module with a decent integer relation implementation (most likely PSLQ)? My target platform is .NET (C#), but if there's source code in C/C++, Java, whatever, even a semi-comprehensible algorithm, that would help me a lot. All I was able to find on Google was some unreadable Mathematica code. I was ...

A good algorithm for generating an order number

As much as I like using GUIDs as the unique identifiers in my system, it is not very user-friendly for fields like an order number where a customer may have to repeat that to a customer service representative. What's a good algorithm to use to generate order number so that it is: Unique Not sequential Numeric values only < 10 digits C...

What kind of Maths should a student Computer Science be familiar with?

I am considering go back to College to get a Master Degree on Computer Science in 2011. As I have been a programmer who had been building all kinds of software, I don't think any thing related to programming shall be a big problem for me. But I did forgotten almost all knowledge I've learned as a undergraduate student. So I think may...

Optimized dot product in Python

The dot product of two n-dimensional vectors u=[u1,u2,...un] and v=[v1,v2,...,vn] is is given by u1*v1 + u2*v2 + ... + un*vn. A question posted yesterday encouraged me to find the fastest way to compute dot products in Python using only the standard library, no third-party modules or C/Fortran/C++ calls. I timed four different approach...

Solving a cubic equation

As part of a program I'm writing, I need to solve a cubic equation exactly (rather than using a numerical root finder): a*x**3 + b*x**2 + c*x + d = 0. I'm trying to use the equations from here. However, consider the following code (this is Python but it's pretty generic code): a = 1.0 b = 0.0 c = 0.2 - 1.0 d = -0.7 * 0.2 q = (3*a...

Euler (Tait-Bryan) to WPF Transformation3D. Is it possible

I'm trying to use WPF integrated 3D classes to rotate a WPF 3D model. I'm stuck. I'm looking for the 10 or so C# instructions which in pure 3D WPF would rotate a model based on Euler's angles as input (yaw, pitch, roll): RotateTransform3D myTransform = TheSolution (yaw, pitch, roll) I'd then use myTransform to rotation myModel (myMod...

Intersection Of A Surface An Plane

I'm trying to find out when a quadratic selection algorithm is faster than a linear selection algorithm. Running some experiments I generated two 3D plots that show the algorithm run times as a function of the input array size and the desired order statistic. Using gnuplot to draw the plot I confirmed that there are cases when the quadra...

How do I use the least squares approximation in MATLAB?

For a homework assignment in linear algebra, I have solved the following equation using MATLAB's \ operator (which is the recommended way of doing it): A = [0.2 0.25; 0.4 0.5; 0.4 0.25]; y = [0.9 1.7 1.2]'; x = A \ y which produces the following answer: x = 1.7000 2.0800 For the next part of assignment, I'm supposed to solve the ...

What algorithm to use to solve this simple mathematical problem efficiently?

I am puzzled with the following simple problem: Given positive integers b, c, m where (b < m) is True it is to find a positive integer e such that (b**e % m == c) is True where ** is exponentiation (e.g. in Ruby, Python or ^ in some other languages) and % is modulo operation. What is the most effective algorithm (with the lowest big-...