math

Generate a periodic value based on dates

I was hoping someone that is good with math and loops could help me out. I'm writing a program in Objective C where I need to come up with a way to do a cycle. If you don't know Objective C I would appreciate any help in pseudo code just to help me figure this out. What I need is a scale that is based on two dates. I know this will be s...

Picking a bounded uniform random value in GF(2^M) without exponentiation or tables

I am looking for a way to uniformly choose values in GF(2^M) between two bounds. GF(2^M) is a Galois Field - See GF(4) as defined on this page - http://www.math.umbc.edu/~campbell/Math413Spr09/Notes/12-13_Finite_Fields.html From a technical, non-math perspective, this is most similar to CRC operations. For example: ulong gf2step...

Data structure for finding nearby keys with similar bitvalues

I have some data, up to a between a million and a billion records, each which is represented by a bitfield, about 64 bits per key. The bits are independent, you can imagine them basically as random bits. If I have a test key and I want to find all values in my data with the same key, a hash table will spit those out very easily, in O(1)...

Math equation to calculate different speeds for fade animation

I'm trying to add a fade effect to my form by manually changing the opacity of the form but I'm having some trouble calculating the correct value to increment by the Opacity value of the form. I know I could use the AnimateWindow API but it's showing some unexpected behavior and I'd rather do it manually anyways as to avoid any p/invoke...

Circle Problem

I want to move circle in a circular path like knob tune....... How could i do this? can any one help me?...Thanks in advance ...

Determining the best initial buffer size for decompressing streamed compressed data

I am trying to calculate an initial buffer size to use when decompressing data of an unknown size. I have a bunch of data points from existing compression streams but don't know the best way to analyze them. Data points are the compressed size and the ratio to uncompressed size. For example: 100425 (compressed size) x 1.3413 (compressi...

Counting combinations of pairs of items from multiple lists without repetition

Given a scenario where we have multiple lists of pairs of items, for example: {12,13,14,23,24} {14,15,25} {16,17,25,26,36} where 12 is a pair of items '1' and '2' (and thus 21 is equivalent to 12), we want to count the number of ways that we can choose pairs of items from each of the lists such that no single item is repeated. You mu...

Simple 3x3 matrix inverse code (C++)

What's the easiest way to compute a 3x3 matrix inverse? I'm just looking for a short code snippet that'll do the trick for non-singular matrices, possibly using Cramer's rule. It doesn't need to be highly optimized. I'd prefer simplicity over speed. I'd rather not link in additional libraries. Primarily I was hoping to have this on Sta...

Convert a value into row, column and char

My data structure is initialized as follows: [[0,0,0,0,0,0,0,0] for x in range(8)] 8 characters, 8 rows, each row has 5 bits for columns, so each integer can be in the range between 0 and 31 inclusive. I have to convert the number 177 (can be between 0 and 319) into char, row, and column. Let me try again, this time with a better co...

Strange result of division in C

Some Duplicates: 1.265 * 10000 = 126499.99999999999 ????? How is floating point stored? When does it matter? Strange floating-point behaviour in a Java program Why do I see a double variable initialized to some value like 21.4 as 21.399999618530273? Error in Flash addition I divide 23 by 40 (23/40). In C this operation res...

Determining if a dataset approximates a sine wave

Is there an algorithm that can be used to determine whether a sample of data taken at fixed time intervals approximates a sine wave? ...

Projecting a sphere onto a cube

I'm currently working on building a game which is on a planet, the way in which I'm planning to store the data is in 6 2dimensional arrays, which are heightmaps around the sphere (on the faces of a cube). The problem I have is this, given a normalised vector which points outwards from the centre of the sphere how can I determine these tw...

Matching algorithm

Odd question here not really code but logic,hope its ok to post it here,here it is I have a data structure that can be thought of as a graph. Each node can support many links but is limited to a value for each node. All links are bidirectional. and each link has a cost. the cost depends on euclidian difference between the nodes the mini...

Algebraic logic

Both Wolfram Alpha and Bing are now providing the ability to solve complex, algebraic logic problems (ie "solve for x, given this equation"), and not just evaluate simple arithmetic expressions (eg "what's 5+5?"). How is this done? I can read most types of code that might get thrown at me, so it doesn't really make a difference what yo...

Efficient comparison of 100.000 vectors

I save 100.000 Vectors of in a database. Each vector has a dimension 60. (int vector[60]) Then I take one and want present vectors to the user in order of decreasing similarity to the chosen one. I use Tanimoto Classifier to compare 2 vectors: Is there any methods to avoid doing through all entries in the database? One more thing! ...

PHP/GD - Cropping and Resizing Images

I've coded a function that crops an image to a given aspect ratio and finally then resizes it and outputs it as JPG: <?php function Image($image, $crop = null, $size = null) { $image = ImageCreateFromString(file_get_contents($image)); if (is_resource($image) === true) { $x = 0; $y = 0; $width = imagesx($imag...

Advanced Formal logic / Automata Theory textbook

I know this is more a Math/Formal Language/Automata/Computer science question than an a programming one, but I hope I can get some advice on a comprehensible textbook (not an indecipherable monograph) on formal logic beyond Propositional and Predicate Calculus. I’m especially interested in monadic second order logic and Büchi Automata. ...

Math Question in C or Objective C

This is probably a silly and easy question, but it seems sometimes the simplest things give me more problems! This formula is suppose to give me a number between 0 and 100. (200 / 23) * Abs(Mod(2987, 23) - 23 / 2) In objective C I coded it like this: (200 / 23) * abs(2987 % 23) - (23 / 2); Is the formula flawed (and doesn't give a...

Calculate maximum size for encypted data

Is there any way to calculate the largest outcome from an Rijndael encryption with a fixed array lenght? Encryption method: RijndaelManaged Padding: PKCS7 CipherMode: CBC BlockSize 128 KeySize: 128 I need this as im converting a database where all string are going to be encrypted so i need to change the size of all string fields. ...

Midnight in UTC time zone with unix timestamp

I was looking for a numeric representation for a date and unix time for midnight (in UTC) seems to be reasonable choice for that. However, as I'm not sure in my math skills, so is date = date - date % (24 * 60 * 60); where date is unix timestamp, the way to do that? Is there any simpler method? ...