discrete-mathematics

How to calculate the energy per bin in a DFT?

折月煮酒 提交于 2019-12-07 15:15:52
问题 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

What is the total number of unique values for a double in the range [0.0, 1.0)?

随声附和 提交于 2019-12-07 00:18:24
问题 Random.NextDouble() (a Double from the range [0.0,1.0)) is sometimes multiplied with a large Int64 (let Int64 big = 9000000000L), and the result floored to obtain a random Int64 value larger than what can be obtained from Random.Next() (an Int32 from the range [0,Int32.MaxValue)). Random r = new Random(); long big = 9000000000L; long answer = (long) (r.NextDouble() * big); It seems to me that the total number of unique values for a Double in the range [0.0, 1.0) provides an upper-bound for

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

不想你离开。 提交于 2019-12-06 15:25:23
问题 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 6 years ago . 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

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

风格不统一 提交于 2019-12-06 13:36:03
问题 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.?? 回答1: You don't

Number of Sides Required to draw a circle in OpenGL

馋奶兔 提交于 2019-12-06 08:14:10
Does anyone know some algorithm to calculate the number of sides required to approximate a circle using polygon, if radius, r of the circle and maximum departure of the polygon from circularity, D is given? I really need to find the number of sides as I need to draw the approximated circle in OpenGL. Also, we have the resolution of the screen in NDC coordinates per pixel given by P and solving D = P/2, we could guarantee that our circle is within half-pixel of accuracy. What you're describing here is effectively a quality factor, which often goes hand-in-hand with error estimates. A common way

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

馋奶兔 提交于 2019-12-06 07:33:30
问题 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 6 years ago . 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

Parma Polyhedra Library: Vertex Enumeration

佐手、 提交于 2019-12-06 06:59:47
I'm trying to use the Parma Polyhedra Library [1] to enumerate the vertices of a (convex) polytope, e.g., I have a rectangle specified by four constraints: Constraint_System cs; cs.insert(x >= 0); cs.insert(x <= 3); cs.insert(y >= 0); cs.insert(y <= 3); C_Polyhedron ph(cs); How do I generate the vertices? Each shape in PPL has dual representations: 1) Constraint_System, 2) Generator_System. For a convex-polyhedra, the generator system will contain the set of generators which can either be 1) Point, 2) Line, 3) Rays. For the convex polytope, the set of generators would be all points. you can

Checksumming large swathes of prime numbers? (for verification)

岁酱吖の 提交于 2019-12-06 06:23:05
问题 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

Custom permutation, Equal distribution of pairs

狂风中的少年 提交于 2019-12-06 04:38:56
问题 I've been playing with a strange problem for a few weeks and can't seem to get the results I want. I'd like to take a permutation of a list of objects to get unique pairs. Then order them in a particular way to maximize equal distribution of the objects at any point in the list. This also means that if an object is at the beginning of a pair if should also be at the end of a pair soon after. No pairs can repeat. To clarify, here is an example. list (A,B,C,D) might result in the following: (A

Count of squarefree numbers in range

风格不统一 提交于 2019-12-06 02:11:43
问题 Given two numbers x and y , find count of numbers that are squarefree where squarefree number is one divisible by no perfect square, except 1 . For example, 10 is square-free but 18 is not, as it is divisible by 9 = 32 . Few positive square-free numbers are : 1, 2, 3, 5, 6, 7, 10, 11, 13, 14, 15 ... limits 1 <= X,Y <= 10^9 0 <= |X-Y| <= 10^6 x=10 , Y=15 gives ans=5 My approach is to generate all prime till squareroot(10^9) (sieve of eratosthenes), and check whether each number in given range