discrete-mathematics

How to calculate the energy per bin in a DFT?

为君一笑 提交于 2019-12-06 02:08:26
I am testing my knowledge about Discrete Fourier Transforms. What I am testing now is how to calculate the central frequency of a wave using DFT. For that purpose I create a sinusoidal data using this code: // create a 100 Hz wave with a sampling rate of 512 samples per second var data : [Double] = [] for i in 0...511 { let t = Double(i) * 100/256 let f = 10 * sin(2 * Double.pi * t) data.append(f) } Then I do a DWT on data and get two vectors, one containing the real part and one containing the imaginary part. I understand that the inside each vector I will have this: data has 512 samples

Equations Equality test (in C++ or with Unix tools) (algebra functions isomorphism) [closed]

╄→гoц情女王★ 提交于 2019-12-05 06:11:46
Closed. This question is off-topic . It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 years ago . I am looking for C++ open-source library (or just open-source Unix tool) to do: Equality test on Equations . Equations can be build during runtime as AST Trees, string or other format. Equations will mostly be simple algebra ones, with some assumptions about unknown functions. Domain, will be integer arithmetic (no floating point issues, as related issues are well known - Thanks @hardmath for stressing it out, I

How calculate three phase kilowatt hour from time sampled data [closed]

寵の児 提交于 2019-12-04 20:41:57
My problem is I want to calculate three phase power from time sampled data of current and voltages. My questions: How can I calculate the energy (unit kilowatt hour) from time sampled data? Are any equations available? Is it needed to take the phase shift in account? (How can I calculate the phase shift? How do I link this to calculating the three phase power?) Is some better platform is available for solving my question? I get the instantaneous sample value (not continuous). (I have some sensors that gives the current and voltage - I convert this to digital for processing). Around 50 samples

Minimum tip to be paid for bill amount B with two kind of coins (x,y) only

旧巷老猫 提交于 2019-12-04 19:21:37
I have two kind of coins (unlimited coins of each type). The values of these two coins are x and y . I have to pay a bill of amount B . What minimum amount i will need to pay as tip . tip can be any value >=0 The objective is to minimize the tip. I just was thinking about the Dynamic programming approach.Or any Faster method. Please help. function minTip(x,y,B){ if(z<=0) return -z; return minimum( minTip(x,y,B-x),minTip(x,y,B-y) ); } Can any one help with the DP approach.?? Paul Hankin You don't need DP to solve this. First, note that you may as well assume the coins are coprime. Because if

Generating Random Permutation Uniformly in Java

。_饼干妹妹 提交于 2019-12-04 16:57:59
Anyone know of a fast/the fastest way to generate a random permutation of a list of integers in Java. For example if I want a random permutation of length five an answer would be 1 5 4 2 3 , where each of the 5! possibilities is equally likely. My thoughts on how to tackle this are to run a method which generates random real numbers in an array of desired length and then sorts them returning the index i.e. 0.712 0.314 0.42 0.69 0.1 would return a permutation of 5 2 3 4 1 . I think this is possible to run in O(n^2) and at the moment my code is running in approximately O(n^3) and is a large

Golomb's sequence

不问归期 提交于 2019-12-04 14:42:09
问题 The Golomb's self-describing sequence {G(n)} is the only nondecreasing sequence of natural numbers such that n appears exactly G(n) times in the sequence. The values of G(n) for the first few n are n 1 2 3 4 5 6 7 8 9 10 11 12 G(n) 1 2 2 3 3 4 4 4 5 5 5 6 Given that G(10^3) = 86, G(10^6) = 6137. Also given that ΣG(n^3) = 153506976 for 1 <= n < 10^3. Find ΣG(n^3) for 1<= n< 10^6. It is easy to code away the formula for finding the sequence of numbers.But is there any way to track a

Allocate an array of integers proportionally compensating for rounding errors

不问归期 提交于 2019-12-04 12:53:42
问题 I have an array of non-negative values. I want to build an array of values who's sum is 20 so that they are proportional to the first array. This would be an easy problem, except that I want the proportional array to sum to exactly 20, compensating for any rounding error. For example, the array input = [400, 400, 0, 0, 100, 50, 50] would yield output = [8, 8, 0, 0, 2, 1, 1] sum(output) = 20 However, most cases are going to have a lot of rounding errors, like input = [3, 3, 3, 3, 3, 3, 18]

Solving a recurrence T(n) = 2T(n/2) + sqrt(n) [closed]

不想你离开。 提交于 2019-12-04 12:16:41
Need a little help! This is what I have so far using backward substitution: T(n) = 2T(n/2) + sqrt(n), where T(1) = 1, and n = 2^k T(n) = 2[2T(n/4) + sqrt(n/2)] + sqrt(n) = 2^2T(n/4) + 2sqrt(n/2) + sqrt(n) T(n) = 2^2[2T(n/8) + sqrt(n/4)] + 2sqrt(n/2) + sqrt(n) = 2^3T(n/8) + 2^2sqrt(n/4) + 2sqrt(n/2) + sqrt(n) In general T(n) = 2^kT(1) + 2^(k-1) x sqrt(2^1) + 2^(k-2) x sqrt(2^2) + ... + 2^1 x sqrt(2^(k-1)) + sqrt(2^k) Is this right so far? If it is, I can not figure out how to simplify it and reduce it down to a general formula. I'm guessing something like this? Combining the terms = 1 + 2^(k-(1

Checksumming large swathes of prime numbers? (for verification)

纵然是瞬间 提交于 2019-12-04 12:04:45
Are there any clever algorithms for computing high-quality checksums on millions or billions of prime numbers? I.e. with maximum error-detection capability and perhaps segmentable? Motivation: Small primes - up to 64 bits in size - can be sieved on demand to the tune of millions per second, by using a small bitmap for sieving potential factors (up to 2^32-1) and a second bitmap for sieving the numbers in the target range. Algorithm and implementation are reasonably simple and straightforward but the devil is in the details: values tend to push against - or exceed - the limits of builtin

Algorithm to detect redundant rules

我只是一个虾纸丫 提交于 2019-12-04 10:55:26
问题 I am looking for an algorithm to detect redundant rules. Rules have a fixed number of input parameters and each parameter has a distinct domain. Consider three rule parameters Color, Material and Size: Color : Red, Green, Blue Material : Wood, Glass, Aluminium Size : Small, Medium, Large Each rule can match on multiple values of a parameter or match on any value. The first rule that matches all parameters values is selected. There are no negation rules, but the domain is fixed, so a negation