math

"Realistic" collision in pong

I want to write a pong in C# and XNA with friction and bounce. I tried to implement the collision as described by Garet Rees in a previous question. Here is the basic algorithm I use for pong: Seperate the colliding objects so that they are no longer colliding. Get the surface normal for collision response. Compute the new velocity - ...

Should developers know discrete math?

Is it important for developers to know discrete math? Most of the books about algorithms and analysis have at least some references to math. I can easily understand the algorithms in principle and can implement them without any problem, but when it comes to the math parts I get stuck. Is it generally assumed that developers will have dee...

Calculating total return with compound interest

So, I'm trying to figure out the total amount of return from an investment of £5 with a daily interest rate of 1.01%. Obviously, I am wanting the compound interest rate, so I have this so far: int main() { double i = 500; int loop; int loopa; double lowInterest; double highInterest; lowInterest = 1.01; high...

Graduate oppurtunities in functional programming/math area?

Hello, I'm currently applying to graduate schools, with the intention of getting a PhD in a field between math and CS. I am currently majoring in math, but two years ago I took a class in Haskell and got really interested in functional programming in general. I was interested in both the elegance of the ideas, both the abstract ones and...

How Do You Predict A Non-Linear Script's Run Time?

I wrote this simple code in python to calculate a given number of primes. The question I want to ask is whether or not it's possible for me to write a script that calculates how long it will take, in terms of processor cycles, to execute this? If yes then how? primes = [2] pstep = 3 count = 1 def ifprime (a): """ Checking if the pass...

Simpler way to find solution of equation

Hi. I have following equation: f(N): N = ((1+lam)^3 )/ ((1-lam)*(1+lam^2)); I need to create a function that finds lam for specified N. Right now I'm doing it using simple loop: lam = 0.9999; n = f(lam); pow = 0; delta = 0.1; while(abs(N - n)) > 0.1 & pow < 10000) lam = lam - 0.001; n = f(lam) pow = pow+1; end How c...

Image rotation & tracking locations

I am rotating an image around it center point but need to track a location on the image as it rotates. Given: Origin at 0,0 Image width and height of 100, 100 Rotation point at C(50,50) Angle of "a" (say 90 degrees in this example) Point P starts at (25,25) and after the rotation it is at Pnew(75,25) I haven't touched trig in 20 y...

How to adjust player sprite speed correctly? (Basically a math question?)

Background: I have a bird view's JavaScript game where the player controls a space ship by touching a circle -- e.g. touch to the left of the circle center, and the ship will move left, touch the top right and it will move to the top right and so on... the further away from the circle center of pseudo joystick, the more speed in that dir...

how to multiply integer or double with values in an array?

The title says it all actually. In a simple way, i have an array of 10 values for example..and i would like to multiply each value with 5. Can i actually just do the following? for (i = 0 ; i <10 ; i++) { x[i]=x[i]*5; } And what about getting square for values in the array and be stored back into the same array? As in I want x[...

Problem coming up with an array function

Let's say I have an increasing sequence of integers: seq = [1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 4 ... ] not guaranteed to have exactly the same number of each integer but guaranteed to be increasing by 1. Is there a function F that can operate on this sequence whereby F(seq, x) would give me all 1's when an integer in the sequence equals x an...

Shunting Yard implementation in PHP needed, interpret and parse a string perform a mathematical comparison and return a boolean result

Hi, I'm looking for something that can interpret a string in php and perform simple math calculation, and then return a boolean result as to whether the expression is true or false. For example: Sue types in "3*{mysalary}/9=10000" PHP splits this up into two expressions - explode('=',string); PHP takes my list of database fields, and...

Calculate correct sprite direction image in bird's view game? (Math here might be speed vector to degrees angle?)

Background: I have 8 images for every sprite in my bird's view JavaScript game, representing top, top-right, right, right-bottom etc., depending on the player's space ship speed. Question: Given the values sprite.speed.x and sprite.speed.y (which could be something like 4 and -2.5, or 2 and 0 for instance), how do I get the correct angl...

More elegant way of adding a percentage?

I'm wondering if there is a more elegant way of adding a percentage. For example, if I wanted to add 12% of $a's value to $a I'm doing: $a = 100; $a = $a + (($a / 100) * 12); Which gives me 112 as the new value, of course. But I can't help but feel this is a little too verbose and there must be a better way of doing the percentage add...

How do I convert a double to a fraction in a format suitable for representing inches?

I am using the Apache Commons math.Fraction class to convert my doubles to fractions, which is working fine. However, I need it to calculate these fractions in a way that makes sense for displaying lengths in inches, to the nearest 1/32". For example, converting 0.325 to a fraction yields 12/37, which doesn't make sense to someone look...

Math book for developer that covers derivations, differential equations, integrals and matrix operations

Hello, I looking for a really great math books that explain the following topics and how they can be implemented on PC: Derivations Differential equations Integrals Matrix operations I'm OK to read more than one book :) but I want to read really helpful ones. Thanks! ...

AS3 / Java - find point of triangle by knowing other two points and segment lengths

Sorry if this doesn't make sense... I know the length of the triangle segments and the xy coordinates of two points. How do I figure out the xy of the 3rd point? ...

Incidence matrix instead of adjacency matrix

What kind of problems on graphs is faster (in terms of big-O) to solve using incidence matrix data structures instead of more widespread adjacency matrices? ...

Greatest GCD between some numbers

Hi, We've got some nonnegative numbers. We want to find the pair with maximum gcd. actually this maximum is more important than the pair! For example if we have: 2 4 5 15 gcd(2,4)=2 gcd(2,5)=1 gcd(2,15)=1 gcd(4,5)=1 gcd(4,15)=1 gcd(5,15)=5 the answer is 5. ...

Need to create a log-prob chart in .NET

I can create a chart with a logarithmic scale on one axis, but I need to have a probability scale on the other axis as well. Thanks in advance. ...

How to extract specific values from auto-correlated data in MATLAB?

I have been working on extracting the peak values from a graph (see previous question) which looks like this: but I have noticed that for some of the xcorr graphs I have been working on the values do not turn out as expected and they normally turn out looking more like this: and this: Instead of trying to pick the peak values li...