math

Algorithm 2D Referential traduction

Hi, I am trying to build a function grapher, The user enters xmin, xmax, ymin, ymax, function. I got the x, y for all points. Now i want to translate this initial referential to a Canvas starting at 0,0 up to 250,250. Is there a short way or should i just check if x < 0 new x = (x - xmin) * (250 / (xmax - xmin)) ? etc .. Also ...

How do I get whole and fractional parts from double in jsp/java?

How do I get whole and fractional parts from double in jsp/java ? If the value is 3.25 then I want to get fractional =.25, whole = 3 How can we do this in java? Any pointers is highly appreciated. ...

What's a good algorithm to determine if an input is a perfect square?

Closed as Exact Duplicate: Fastest way to determine if an integer’s square root is an integer What's a way to see if a number is a perfect square? bool IsPerfectSquare(long input) { // TODO } I'm using C# but this is language agnostic. Bonus points for clarity and simplicity (this isn't meant to be code-golf). Edit: T...

How do Trigonometric functions work?

So in high school math, and probably college, we are taught how to use trig functions, what they do, and what kinds of problems they solve. But they have always been presented to me as a black box. If you need the Sine or Cosine of something, you hit the sin or cos button on your calculator and you're set. Which is fine. What I'm wonder...

Math - mapping numbers

How do I map numbers, linearly, between a and b to go between c and d. That is, I want numbers between 2 and 6 to map to numbers between 10 and 20... but I need the generalized case. My brain is fried. ...

Project Euler #219

I'm trying to do project Euler number 219 but am failing to get a grasp of it. I'm trying to use Python which according to project Euler should be able to do it within a minute! This leads me to think that they can't possibly want me to compute each individual bitstring since that would be too slow in Python - there has to be a sub O(n) ...

Ticking function grapher

Hello everyone, I am trying to figure out the following problem. I am building Yet another math function grapher, The function is drawn on its predefined x,y range, that's all good. Now I am working on the background and the ticking of X, Y axes (if any axes are shown). I worked out the following. I have a fixed width of 250 p The ti...

Rounding float to the nearest factor ?

I have a small math problem I am trying to solve Given a number x and resolution y, I need to find the next x' with the required resolution. e.g. x = 1.002 y = 0.1 x'= 1.1 x = 0.348 y = 0.1 x'= 0.4 x = 0.50 y = 1 x'= 1 x = 0.32 y = 0.05 x'= 0.35 Is there any smart way of doing this in Python? ...

Introduction to computer algebra systems?

Does anybody know of any resources (books, classes, lecture notes, or anything) about the general theory of computer algebra systems (e.g. mathematica, sympy)? "Introductory" materials are preferred, but I realize that with such a specialized subject anything is bound to be fairly advanced. ...

Calculating a LookAt matrix

I'm in the midst of writing a 3d engine and I've come across the LookAt algorithm described in the DirectX documentation: zaxis = normal(At - Eye) xaxis = normal(cross(Up, zaxis)) yaxis = cross(zaxis, xaxis) xaxis.x yaxis.x zaxis.x 0 xaxis.y yaxis.y zaxis.y 0 xaxis.z ...

How do I fix my output for floating-point imprecision?

Hi, I am doing some float manipulation and end up with the following numbers: -0.5 -0.4 -0.3000000000000000004 -0.2000000000000000004 -0.1000000000000000003 1.10E-16 0.1 0.2 0.30000000000000000004 0.4 0.5 The algorithm is the following: var inc:Number = nextMultiple(min, stepSize); trace(String(inc)); private function nextMultiple(...

Least Squares C# library

I am looking to perform a polynomial least squares regression and am looking for a C# library to do the calculations for me. I pass in the data points and the degree of polynomal (2nd order, 3rd order, etc) and it returns either the C0, C1, C2 etc. constant values or the calculated values "predictions". Note: I am using Least Squares...

Help! Where has Math.PI gone in F# CTP?

I'm just trying to do simple scripting with F#, and Math.PI seems to have 'disappeared'. I've referenced FSharp.PowerPack.dll, but still can't find it. ...

Base conversion of arbitrary sized numbers (PHP)

I have a long "binary string" like the output of PHPs pack funtion. How can I convert this value to base62 (0-9a-zA-Z)? The built in maths functions overflow with such long inputs, and BCmath doesn't have a base_convert function, or anything that specific. I would also need a matching "pack base62" function. ...

Determine the centroid of multiple points

Hello, I'm writing a mapping application that I am writing in python and I need to get the lat/lon centroid of N points. Say I have two locations a.lat = 101 a.lon = 230 b.lat = 146 b.lon = 200 Getting the center of two points is fairly easy using a euclidean formula. I would like to be able to do it for more then two points. Fund...

Number of arrangements

Suppose we have n elements, a1, a2, ..., an, arranged in a circle. That is, a2 is between a1 and a3, a3 is between a2 and a4, an is between an-1 and a1, and so forth. Each element can take the value of either 1 or 0. Two arrangements are different if there are corresponding ai's whose values differ. For instance, when n=3, (1, 0, 0) and...

Turn a N-Ary B-Spline into a sequence of Quadratic or Cubic B-Splines

Hi, I am doing some TTF work for MOSA (the correlating body between all the C# operating systems). Me and Colin Burn are currently working on getting some TTF code working (less me these days :) - he made a lot of progress). In any case, the TTF spec allows for an arbitrary amount of control points between the 'handles' and gasp NO han...

How to compute the nth root of a very big integer in python

I need a way to compute the nth root of a long integer in python. I tried pow(n, 1.0/3), but obviously it doesn't work any ideas ? UPDATE: By long integer i mean REALLY long ints like: 11968003966030964356885611480383408833172346450467339251 196093144141045683463085291115677488411620264826942334897996389 4850462628472657692808832376...

Align point clouds via 3 points correlation?

Let's say I have 3 point clouds: first that has 3 points {x1,y1,z1}, {x2,y2,z2}, {x3,y3,z3} and second point cloud that has same points as {xx1, yy1, zz1}, {xx2,yy2,zz2}, {xx3,yy3,zz3}... I assume to align second point cloud to first I have to multiply second one's points by T[3x3matrix]. 1) So how do I find this transform matrix(T) ? ...

"Plumber" Programmers vs. Computer Scientists

I'm a self taught programmer pushing 40 years old, and a self admitted "plumber programmer" that relies pretty heavily on APIs. I slowly play catch up on my understanding of how to properly implement data structures and algorithms, Big(O), etc., but find that my lack of Math background ends up preventing me from understanding some of the...