math

LaTeX renderer for .NET?

I'm curious as to whether a native .NET renderer for TeX/LaTeX exists. So for in my search the closest I have been able to find is a Java implementation, JMathTeX. I am tempted to port this to C#, but before I do so, I would simply like to check whether anyone is aware of a .NET implementation out there. My curent thuoghts are to use Mi...

Is there a way to optimise this program in Haskell?

Hi I am doing project euler question 224. And whipped up this list comprehension in Haskell: prob39 = length [ d | d <- [1..75000000], c <- [1..37500000], b <-[1..c], a <- [1..b], a+b+c == d, a^2 + b^2 == (c^2 -1)] I compiled it with GHC and it has been running with above average kernel priority for over an hour without returning a re...

Why is there a difference between the same value stored as a float and a double in Java?

I expected the following code to produce: "Both are equal", but I got "Both are NOT equal": float a=1.3f; double b=1.3; if(a==b) { System.out.println("Both are equal"); } else{ System.out.println("Both are NOT equal"); } What is the reason for this? ...

Unit-safe square roots

I just wondered how it is possible to write a user-defined square root function (sqrt) in a way that it interacts properly with F#'s unit system. What it should be like: let sqrt (x : float<'u ^ 2>) = let x' = x / 1.0<'u ^ 2> // Delete unit (x ** 0.5) * 1.0<'u> // Reassign unit But this is disallowed due to nonzero const...

rounding in base 10

I have a function to round a number given to the function to the nearest whole pence. <script type='text/javascript'> Math.roundNumber = function(a,b){ if(!isNaN(parseInt(a))){ c = Math.pow(10,b); return (Math.round(a*c)/c); } return false; } </script> however it has come to my attention that the said number inputte...

Global angle of 3d vectors

I have 3 Vectors, Up Right and Front that represent a direction. I need to convert these into an XYZ angle (3 floats) so i can use with glRotatef() Please help [EDIT] Its not rendering properly. can you see if its anything blatant here: pastebin.com/f6683492d ...

Finding similarities in a multidimensional array

Consider a sales department that sets a sales goal for each day. The total goal isn't important, but the overage or underage is. For example, if Monday of week 1 has a goal of 50 and we sell 60, that day gets a score of +10. On Tuesday, our goal is 48 and we sell 46 for a score of -2. At the end of the week, we score the week like this: ...

Fast permutation -> number -> permutation mapping algorithms

I have n elements. For the sake of an example, let's say, 7 elements, 1234567. I know there are 7! = 5040 permutations possible of these 7 elements. I want a fast algorithm comprising two functions: f(number) maps a number between 0 and 5039 to a unique permutation, and f'(permutation) maps the permutation back to the number that it...

How to round a decimal to the nearest fraction?

Not sure if that is the right way to ask this or not but here is the problem. Given a latitude of 26.746346081599476, how do I find the number 26.75 as the 16th greater than the number and 26.6875 as the 16th lower than the number? 26.0 26.0625 26.125 26.1875 26.25 26.3125 26.375 26.4375 26.5 26.5625 26.625 26.6875 My Number: 26.746346...

How to optimize my SQL in server?

I would like to know how to optimize the following SQL to let my server load faster and take low usage? I need to calculate the radius distance for a US ZIP Code to get the result, such as 50 miles from a particular ZIP Code ( using latitude and longitude to calculate ) and to getting how many other data ( e.g. others ZIP Code ) from my...

Algorithm for fair distribution of numbers into two sets.

Hello, Given a set of n numbers (1 <= n <= 100) where each number is an integer between 1 and 450,we need to distribute those set of numbers into two sets A and B, such that the following two cases hold true: The total numbers in each set differ by at most 1. The sum of all the numbers in A is as nearly equal as possible to the sum of...

Building a Collaborative filtering / Recommendation System

I'm in the process of designing a website that is built around the concept of recommending various items to users based on their tastes. (i.e. items they've rated, items added to their favorites list, etc.) Some examples of this are Amazon, Movielens, and Netflix. Now, my problem is, I'm not sure where to start in regards to the mathema...

calculate lat/lon point

If I have the coordinates of a point (lat lon) and the azimuth angle how can I calculate what points are at "the end' of a distance of 10 miles. Ex. I am watching North , I know I am at a certain point ... At 10 miles apart what coordinates has that geo point ? ...

Solving a matrix in MATLAB?

How does one solve the (non-trivial) solution Ax = 0 for x in MATLAB? A = matrix x = matrix trying to solve for I've tried solve('A * x = 0', 'x') but I only get 0 for an answer. ...

How do I flip a polygon by flipping the array?

I have 2 arrays of ints I am using to create a polygon (that looks like a fish). What do I need to do to the arrays to flip the polygon horizontally? x = new int[] { 0, 18, 24, 30, 48, 60, 60, 54, 60, 48, 30, 24, 0 }; y = new int[] { 0, 18, 6, 0, 0, 12, 18, 24, 24, 36, 36, 30, 36 }; ...

Getting the point of a catmull rom spline after a certain distance?

If I have a Catmull-Rom spline of a certain length how can I calculate its position at a certain distance? Typically to calculate the point in a catmull rom spline you input a value between 0 and 1 to get its position via proportions, how can I do this for distances? For example if my spline is 30 units long how can I get its position at...

Find the normal angle of the face of a triangle in 3D, given the co-ordinated of its verticies

As you may be able to tell from this screenshot, I am trying to make a physics engine for a platformer I am working on, but I have run into a definite problem: I need to be able to find out the angle of any one of the triangles that you can see make up this mesh, so that I can work out the rotation and therefore angular acceleration of t...

Show lat/lon points on screen, in 3d

It's been a while since my math in university, and now I've come to need it like I never thought i would. So, this is what I want to achieve: Having a set of 3D points (geographical points, latitude and longitude, altitude doesn't matter), I want to display them on a screen, considering the direction I want to take into account. This is...

About an exercise appearing in TAOCP volume one's "Notes on the Exercises".

Hi, There is a question in TAOCP vol 1, in "Notes on Exercises" section, which goes something like: "Prove that 13^3 = 2197. Generalize your answer. (This is a horrible kind of problem that the author has tried to avoid)." Questions: How would you actually go about proving this ? (Direct multiplication is one way, another way could ...

Rotation about the Y-Axis

Doing a couple rotations in Matlab, one which is rotation about the y-axis, however online I've found two different answers: here and here. Which is correct, if both how does one get to the other? ...