approximation

Approximation Algorithm for non-intersecting paths in a grid

£可爱£侵袭症+ 提交于 2019-12-01 05:43:33
问题 I recently came across this question and thought I could share it here, since I wasn't able to get it. We are given a 5*5 grid numbered from 1-25, and a set of 5 pairs of points,that are start and end points of a path on the grid. Now we need to find 5 corresponding paths for the 5 pairs of points, such that no two paths should overlap. Also note that only vertical and horizontal moves are allowed. Also the combined 5 path should cover the entire grid. For example we are given the pair of

numpy.sin(pi) returns negative value

被刻印的时光 ゝ 提交于 2019-11-29 11:38:12
The following code: a = numpy.sin(2. * numpy.pi) print(a < 0) return "True". But in reality a = 0. How could I fix that? In addition, I have a matrix with a lot of value like "a" and I want to make sure that my matrix contains non-negative value. This because of floating point arithmetic, and accuracy reasons. The result is the best approximation of sin one can get to be representable as a floating point number. Usually you solve near-zero problems like this: a = numpy.sin(2. * numpy.pi) print(abs(a) < 1e-10) You may also want to read this . In reality a <> 0 because in reality numpy.pi is not

Circular approximation of polygon (or its part)

混江龙づ霸主 提交于 2019-11-28 14:16:45
SHORT DESCRIPTION OF MY PROBLEM I need to implement GCODE autorefactoring from G1 instructions to G2 and G3 ( http://www.cnccookbook.com/CCCNCGCodeArcsG02G03.htm ) for 3D Printing. G1 is a movement in straight line with printing (path is describe by vector). I'm searching for algorytm to aproxymate circle/arc (specialy it's midpoint) based on given vectors path. Note that G2 and G3 can't print curves that are not part of a circle - so not every vectors path can be approximate this way. LONG DESCRIPTION OF MY PROBLEM I'm searching way to approximate part (or all) of vectors path (can be regular

Sum of decimal number in java

拟墨画扇 提交于 2019-11-28 13:51:19
I have a problem for the managemente of decimal number in java (JDK 1.4). I have two double numbers first and second (as output of formatted String ). I do a sum between fist and second and I receive a number with more decimal digits! final double first=198.4;//value extract by unmodifiable format method final double second=44701.2;//value extract by unmodifiable format method final double firstDifference= first+second; //I receive 44899.598 instead of 44899.6 final double calculatedDifference=44900.1; // comparison value for the flow final double error=firstDifference-calculatedDifference;//

numpy.sin(pi) returns negative value

情到浓时终转凉″ 提交于 2019-11-28 05:08:20
问题 The following code: a = numpy.sin(2. * numpy.pi) print(a < 0) return "True". But in reality a = 0. How could I fix that? In addition, I have a matrix with a lot of value like "a" and I want to make sure that my matrix contains non-negative value. 回答1: This because of floating point arithmetic, and accuracy reasons. The result is the best approximation of sin one can get to be representable as a floating point number. Usually you solve near-zero problems like this: a = numpy.sin(2. * numpy.pi)

Division by a constant using shifts and adds/subtracts

£可爱£侵袭症+ 提交于 2019-11-27 22:39:04
问题 Hi all I'm trying to divide by an unsigned constant using only shifts and adds/subtracts - I have no problem with this if it were multiplication, but I'm a bit stumped by the division. For example, lets say the constant divisor is 192 and lets say the dividend is 8000 "full result" y = 8000/192 = 41 (assuming I'm not keeping fractional bits) y = 8000 >> 8 ... 31 y = 8000 >> 7 ... 62 But how do I get a more accurate solution? Many thanks! 回答1: There is almost certainly a more elegant way to do

Convert light frequency to RGB?

ε祈祈猫儿з 提交于 2019-11-27 10:09:58
Does anyone know of any formula for converting a light frequency to an RGB value? Here's a detailed explanation of the entire conversion process: http://www.fourmilab.ch/documents/specrend/ . Source code included! For lazy guys (like me), here is an implementation in java of the code found in @user151323 's answer (that is, just a simple translation from pascal code found in Spectra Lab Report ): static private double Gamma = 0.80; static private double IntensityMax = 255; /** Taken from Earl F. Glynn's web page: * <a href="http://www.efg2.com/Lab/ScienceAndEngineering/Spectra.htm">Spectra Lab

Circular approximation of polygon (or its part)

一个人想着一个人 提交于 2019-11-27 08:17:45
问题 SHORT DESCRIPTION OF MY PROBLEM I need to implement GCODE autorefactoring from G1 instructions to G2 and G3 (http://www.cnccookbook.com/CCCNCGCodeArcsG02G03.htm) for 3D Printing. G1 is a movement in straight line with printing (path is describe by vector). I'm searching for algorytm to aproxymate circle/arc (specialy it's midpoint) based on given vectors path. Note that G2 and G3 can't print curves that are not part of a circle - so not every vectors path can be approximate this way. LONG

Sum of decimal number in java

跟風遠走 提交于 2019-11-27 07:58:10
问题 I have a problem for the managemente of decimal number in java (JDK 1.4). I have two double numbers first and second (as output of formatted String ). I do a sum between fist and second and I receive a number with more decimal digits! final double first=198.4;//value extract by unmodifiable format method final double second=44701.2;//value extract by unmodifiable format method final double firstDifference= first+second; //I receive 44899.598 instead of 44899.6 final double

Choosing random numbers efficiently

邮差的信 提交于 2019-11-27 04:51:50
I have a method, which uses random samples to approximate a calculation. This method is called millions of times, so its very important that the process of choosing the random numbers is efficient. I'm not sure how fast javas Random().nextInt really are, but my program does not seem to benefit as much as I would like it too. When choosing the random numbers, I do the following (in semi pseudo-code): // Repeat this 300000 times Set set = new Set(); while(set.length != 5) set.add(randomNumber(MIN,MAX)); Now, this obviously has a bad worst-case running time, as the random-function in theory can