math

Why does this subtraction not equal zero?

I happened upon these values in my ColdFusion code but the Google calculator seems to have the same "bug" where the difference is non-zero. 416582.2850 - 411476.8100 - 5105.475 = -2.36468622461E-011 http://www.google.com/search?hl=en&rlz=1C1GGLS_enUS340US340&q=416582.2850+-+411476.8100+-+5105.475&aq=f&oq=&aqi= Java...

Bouncing a ball off the 4 walls of a stage

Just curious. When I bounce a ball off the walls of the stage using the following technique. if(y > sRef.stageHeight || y < 0) { yDir = yDir * -1; } else if ( x > sRef.stageWidth || x < 0) { xDir = xDir * -1; } x += xspeed * xDir; y += yspeed * yDir; The above seems fine and works well. But If I choose to use angles inst...

Implementation of vector class in Delphi?

How would you go about creating a vector class in Delphi? I would prefer to put all math related stuff into a DLL. Should I use a record or a class implementing an interface? Pros of record approach: Fast and lightweight Value type Operator overloading Cons of record approach: Implementation cannot be hidden in DLL (no inheritance...

PHP round math question?

What will the code below be if value is 2 and counter is 11? What would $rating be? $rating = (@round($rs[value] / $rs[counter],1)) * 10; The complete code is below. function getRating(){ $sql= "select * from vote"; $result=@mysql_query($sql); $rs=@mysql_fetch_array($result); $rating = (@round($rs[value] / $rs[counte...

How do I "round" a number to end in certain digits?

I need a mathematical function/formula/expression to take a number as parameter and find the lowest number ending with certain digits that is larger than the parameter. For instance, if the ending digits should be 88 these are some examples of what I want: f(0) = 0 f(87) = 88 f(88) = 88 f(89) = 188 //NB: NOT 88*2=176 f(187) = 188 f(18...

Matrix multiplication using matrix template library (MTL 2)

Kindly give me some hint of matrix multiplication using MTL 2. Or any ref. or link for the documentation of MTL 2. ...

Why do programming languages round down until .6?

If you put a decimal in a format where has to be rounded to the nearest 10th, and it is: 1.55, it'll round to 1.5. 1.56 will then round to 1.6. In school I recall learning that you round up when you reach five, and down if it's 4 or below. Why is it different in Python, et al. Here's a code example for Python 2.6x (whatever the latest v...

Scaling a 2D polygon with the mouse

Hi, I develop a Python-based drawing program, Whyteboard (https://launchpad.net/whyteboard) I'm developing features to allow the user to rotate and scale a polygon that they draw. Here's my problem: I have a Polygon class containing a list of all points, which is "closed off" at the end. Users can select drawn shapes in my program, wh...

AS3: Math-related - Constructing Equilateral Triangle

Hi there, I am trying to construct an equilateral triangle with the following code, but I am not seeing what I would expect to. I would expect to see a triangle drawn to the stage, but I don't see one. I think there must be something wrong in terms of the location of the tri sprite on the screen. public class test_drawing_triangle exten...

Need help in latent semantic indexing

Hi, I am sorry, if my question sounds stupid :) Can you please recommend me any pseudo code or good algo for LSI implementation in java? I am not math expert. I tried to read some articles on wikipedia and other websites about LSI ( latent semantic indexing ) they were full of math. I know LSI is full of math. But if i see some source co...

Matrix multiplication in GSL-GNU

Kindly tell me the function of matrix multiplication in GSL library. I have searched a lot but I am not be able to fine it. If any one know about that function kindly answer. Thanks in advance. ...

approximation methods

I attached image: So in this image there is a diagram of the function, which is defined on the given points. For example on points x=1..N. Another diagram, which was drawn as a semitransparent curve, That is what I want to get from the original diagram, i.e. I want to approximate the original function so that it becomes smooth. Are...

2-dimensional interpolation

I want to find a value of z at y = 12 and x = 3.5, given the below example data. How can I do this in C++? y = 10 x = [1,2, 3,4, 5,6] z = [2.3, 3.4, 5.6, 7.8, 9.6, 11.2] y = 20 x = [1,2, 3,4, 5,6] z = [4.3, 5.4, 7.6, 9.8, 11.6, 13.2] y = 30 x = [1,2, 3,4, 5,6] z = [6.3, 7.4, 8.6, 10.8, 13.6, 15.2] My current Python code: import...

Algorithm to find optimal combination of products and shops to minimise cost.

Hello there Stackoverflow people, I run a site that finds its users the cheapest place to buy books. This is easy for a single book, but for multiple books it can sometimes be cheaper to purchase one book at one store and another book from another store. Currently I find the cheapest store that sells all books in the user's list, but I...

How to find center of clusters of numbers? statistics problem?

Hi, I have a problem where I have a set of numbers eg. 5, 7, 7, 8, 8, 8, 7, 20, 23, 23, 24, 24, 24, 25 In the above set, there is two "clusters" of numbers, I want to write a program to find the centers of these clusters. Could you call them attractors as in Fractal theory? So the program would, I guess, find that the set can be divid...

C: mathematical power operator not working as expected

short sho1, sho2; printf("Enter two shorts.\n"); scanf("%hd %hd", &sho1, &sho2); printf("%hd^%hd is %hd.\n", sho1, sho2, sho1^sho2); When I enter '2 2', I get this output: 2^2 is 0. How come? I'm using the MinGW GCC compiler in Eclipse, in case that's of any importance. ...

How do you show that one algorithm is more efficient than another algorithm?

Hi, I'm no professional programmer and I don't study it. I'm an aerospace student and did a numeric method for my diploma thesis and also coded a program to prove that it works. I did several methods and implemented several algorithms and tried to show the proofs why different situations needed their own algorithm to solve the task. I...

Calculate a Vector that lies on a 3D Plane

I have a 3D Plane defined by two 3D Vectors: P = a Point which lies on the Plane N = The Plane's surface Normal And I want to calculate any vector that lies on the plane. ...

Normal Vector of Three Points

Hey math geeks, I've got a problem that's been stumping me for a while now. It's for a personal project. I've got three dots: red, green, and blue. They're positioned on a cardboard slip such that the red dot is in the lower left (0,0), the blue dot is in the lower right (1,0), and the green dot is in the upper left. Imagine stepping ba...

2D Rotation Array

I need help converting this code from this thread: http://stackoverflow.com/questions/646468/how-to-rotate-a-2d-array-of-integers to PHP arrays. int [,] newArray = new int[4,4]; for (int i=3;i>=0;--i) { for (int j=0;j<4;++j) { newArray[j,3-i] = array[i,j]; } } Also, will this code work if the blocks are off-center? ...