math

Prime Factorization

I have recently been reading about the general use of prime factors within cryptography. Everywhere i read, it states that there is no 'PUBLISHED' algorithm which operates in polynomial time (as opposed to exponential time), to find the prime factors of a key. If an algorithm was discovered or published which did operate in polynomial t...

Little Math-help for image resize needed

Hey, I have an Image with the Value X width and Y height. Now I want to set the height ever to 60px. With which calculation I can calculate the height that the image is correct resized? ...

Finding the spin of a sphere given X, Y, and Z vectors relative to sphere

I'm using Electro in Lua for some 3D simulations, and I'm running in to something of a mathematical/algorithmic/physics snag. I'm trying to figure out how I would find the "spin" of a sphere of a sphere that is spinning on some axis. By "spin" I mean a vector along the axis that the sphere is spinning on with a magnitude relative to the...

Java permutations with least random numbers possible

hi folks! i looking to generate a permutation of the array a and I dont want to use util function such as shuffle on collections... The permutations(#) should be randomised and every single permutation should be possible - but there is no need for an equally distributed probability. the following code was the first idea that struck my mi...

Relational Databases and Mathematics?

Can anyone suggest resources that take a mathematical approach to relational databases? Essentially relational algebra I'd guess. I have a mathematics background and now work a great deal with databases and would like to close the gap. ...

Radial plotting algorithm

Hi there, I have to write an algorithm in AS3.0 that plots the location of points radially. I'd like to input a radius and an angle at which the point should be placed. Obviously I remember from geometry coursework that 2(pi)r will give me an x on the point at the radius distance. The problem is I need to produce the x, y and the calcul...

Math Overflow -- Handling Large Numbers

I am having a problem handling large numbers. I need to calculate the log of a very large number. The number is the product of a series of numbers. For example: log(2x3x66x435x444) though my actual series are longer. I am getting a math overflow because product grows very large, very quickly. Are there special math libraries to ha...

Simple statistics - Java packages for calculating mean, standard deviation, etc...

Could you please suggest any simple Java statistics packages? I don't necessarily need any of the advanced stuff. I was quite surprised that there does not appear to be a function to calculate the Mean in the java.lang.Math package... What are you guys using for this? EDIT Regarding: How hard is it to write a simple class tha...

Maths in LaTex table of contents

I am trying to add a table of contents for my LaTex document. The issue I am having is that this line: \subsubsection{The expectation of \(X^2\)} Causes an error in the file that contains the table of contents \contentsline {subsubsection}{\numberline {1.2.3} The expectation of \relax $X^2\relax \GenericError { }{ LaTeX Error: Bad m...

How to use linear interpolation estimate current position between two Geo Coordinates?

I have the following available: last reported lat,lon w/timestamp target lat,lon estimated time to target heading How can I interpolate an estimated position over time? I know that's enough to calculate the required average velocity for the remainder of the trip. Given a straight-line distance, it's pretty trivial. I know it has to ...

One's complement instead of just a sum of bits

A question in my university homework is why use the one's complement instead of just the sum of bits in a TCP checksum. I can't find it in my book and Google isn't helping. Any chance someone can point me in the right direction? Thanks, Mike ...

How do I find the smallest positive integer congruent to i modulo m?

I have a variable that holds an angle, in degrees, which can be both positive and negative. I now need to make sure that this number is between 0 and 360 only. The number is a double. What would a nice algorithm for doing that be? Simply doing angle % 360 does not work, because negative numbers end up still being negative. Bonus points ...

Ruby Percentile calculations to match Excel formulas (need refactor)

I've written two simple calculations with Ruby which match the way that Microsoft Excel calculates the upper and lower quartiles for a given set of data - which is not the same as the generally accepted method (surprise). My question is - how much and how best can these methods be refactored for maximum DRYness? # Return an upper quar...

Is there a simple way to create a unique integer key from a two-integer composite key?

For various reasons that aren't too germane to the question, I've got a table with a composite key made out of two integers and I want to create a single unique key out of those two numbers. My initial thought was to just concatenate them, but I ran into a problem quickly when I realized that a composite key of (51,1) would result in the...

How do I compute the arcot (inverse cotangent) in PHP?

PHP has many builtin trig math functions, but the inverse cotangent does not seem to be available as one of them. This is also referred to as arccot. Does anyone have the function equivalent in PHP to compute this? ...

Evenly distribute values over a time period

I have got a variable amount of items, and a variable date range that I need to distribute them over. Lets say I have 3 items and I need to distribute them over 6 days. What I would want is to have every second day have an item, and it does not matter if the first day has an item or not. If I had 7 items over 6 days, one of the days woul...

Faster implementation of Math.round?

Are there any drawbacks to this code, which appears to be a faster (and correct) version of java.lang.Math.round? public static long round(double d) { if (d > 0) { return (long) (d + 0.5d); } else { return (long) (d - 0.5d); } } It takes advantage of the fact that, in Java, truncating to long rounds in to ...

Solving for optimal alignment of 3d polygonal mesh

I'm trying to implement a geometry templating engine. One of the parts is taking a prototypical polygonal mesh and aligning an instantiation with some points in the larger object. So, the problem is this: given 3d point positions for some (perhaps all) of the verts in a polygonal mesh, find a scaled rotation that minimizes the differen...

JavaScript subtraction problem

I thought I'd write a simple script to animate my webpage a little. The basic idea was to make a div grow bigger and smaller, when I push a button. I handled the growing part well, but I can't get it to shrink again. It would seem, after long debugging, that the subtraction in JavaScript just isn't working. Basically, it seems, that th...

'Difference' between two quaternions

I'm working in Ogre, but it's a general quaternion problem. I have an object, to which I apply a rotation quaternion Q1 initially. Later, I want to make it as if I initially rotated the object by a different quaternion Q2. How do I calculate the quaternion which will take the object, already rotated by Q1, and align it as if all I did ...