math

Compress two or more numbers into one byte

天涯浪子 提交于 2020-05-24 15:48:54
问题 I think this is not really possible but worth asking anyway. Say I have two small numbers (Each ranges from 0 to 11). Is there a way that I can compress them into one byte and get them back later. How about with four numbers of similar sizes. What I need is something like: a1 + a2 = x. I only know x and from that get a1, a2 For the second part: a1 + a2 + a3 + a4 = x. I only know x and from that get a1, a2, a3, a4 Note: I know you cannot unadd, just illustrating my question. x must be one byte

Discrete Fourier transform

你离开我真会死。 提交于 2020-05-24 10:11:43
问题 I am currently trying to write some fourier transform algorithm. I started with a simple DFT algorithm as described in the mathematical definition: public class DFT { public static Complex[] Transform(Complex[] input) { int N = input.Length; Complex[] output = new Complex[N]; double arg = -2.0 * Math.PI / (double)N; for (int n = 0; n < N; n++) { output[n] = new Complex(); for (int k = 0; k < N; k++) output[n] += input[k] * Complex.Polar(1, arg * (double)n * (double)k); } return output; } } So

How to get the combination of array values from nested arrays in an array of objects

天涯浪子 提交于 2020-05-23 09:21:13
问题 I have an array of objects with the following structure: var varientSections = [ { type: "frame", values: ["black", "white", "wood"] }, { type: "finish", values: ["matte", "glossy"] } ]; I want to get the combination of the array values and create a new list with it. Right now, I am able to retrieve the combination from the nested array values using the method called getCombination(varientSections) . However, I do not know how to create a new list with the following structure: var results = [

Can “System.Math.Cos” return a (float)?

本秂侑毒 提交于 2020-05-23 08:00:24
问题 In C# it bugs me how there is no "Math.Cos" function that returns a float. A double is the only value you can get back thus forcing you to cast it to a float. Like so: float val = (float)Math.Cos(someVal); I need to use floats because i'm doing stuff in Direct3D which strictly uses floats. Floats are much more common in the graphics world(as it stands now) because they are 32bit. Is there any functionality within C# I can use that would simply just process floats like C++ can do?? I do not

Can “System.Math.Cos” return a (float)?

泄露秘密 提交于 2020-05-23 08:00:13
问题 In C# it bugs me how there is no "Math.Cos" function that returns a float. A double is the only value you can get back thus forcing you to cast it to a float. Like so: float val = (float)Math.Cos(someVal); I need to use floats because i'm doing stuff in Direct3D which strictly uses floats. Floats are much more common in the graphics world(as it stands now) because they are 32bit. Is there any functionality within C# I can use that would simply just process floats like C++ can do?? I do not

What is the easiest way to get a list of whole factor pairs of a given integer?

六月ゝ 毕业季﹏ 提交于 2020-05-23 06:58:31
问题 What is the easiest way to get a list of whole factor pairs of a given integer? For example: f(20) would return [(1,20), (2,10), (4,5)] . 回答1: def f(value): factors = [] for i in range(1, int(value**0.5)+1): if value % i == 0: factors.append((i, value / i)) return factors Or the same thing using a list comprehension: def f(val): return [(i, val / i) for i in range(1, int(val**0.5)+1) if val % i == 0] 回答2: Or this: def f(n): factors_list = [] for i in xrange(1, int(n**0.5) + 1): if n % i == 0:

How to calculate float type precision and does it make sense?

风流意气都作罢 提交于 2020-05-22 10:04:27
问题 I have a problem understanding the precision of float type. The msdn writes that precision from 6 to 9 digits. But I note that precision depends from on the size of the number: float smallNumber = 1.0000001f; Console.WriteLine(smallNumber); // 1.0000001 bigNumber = 100000001f; Console.WriteLine(bigNumber); // 100000000 The smallNumber is more precise than big, I understand IEEE754, but I don't understand how MSDN calculate precision, and does it make sense? Also, you can play with the

Calculating the perspective projection matrix according to the view plane

被刻印的时光 ゝ 提交于 2020-05-18 18:23:51
问题 I'm working with openGL but this is basically a math question. I'm trying to calculate the projection matrix, I have a point on the view plane R(x,y,z) and the Normal vector of that plane N(n1,n2,n3). I also know that the eye is at (0,0,0) which I guess in technical terms its the Perspective Reference Point. How can I arrive the perspective projection from this data? I know how to do it the regular way where you get the FOV, aspect ration and near and far planes. 回答1: I think you created a

Calculating the perspective projection matrix according to the view plane

∥☆過路亽.° 提交于 2020-05-18 18:23:31
问题 I'm working with openGL but this is basically a math question. I'm trying to calculate the projection matrix, I have a point on the view plane R(x,y,z) and the Normal vector of that plane N(n1,n2,n3). I also know that the eye is at (0,0,0) which I guess in technical terms its the Perspective Reference Point. How can I arrive the perspective projection from this data? I know how to do it the regular way where you get the FOV, aspect ration and near and far planes. 回答1: I think you created a

Can you please explain Reed Solomon encoding part's Identity matrix?

一个人想着一个人 提交于 2020-05-17 07:27:04
问题 I am working on a object storage project where I need to understand Reed Solomon error correction algorithm, I have gone through this Doc as a starter and also some thesis paper. 1. content.sakai.rutgers.edu 2. theseus.fi but I can't seem to understand the lower part of the identity matrix (red box), where it is coming from. How this calculation is done? Can anyone please explain this. 回答1: The encoding matrix is a 6 x 4 Vandermonde matrix using the evaluation points {0 1 2 3 4 5} modified so