approximation

Continued Fractions Python [closed]

倾然丶 夕夏残阳落幕 提交于 2021-02-08 15:01:58
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 4 years ago . Improve this question I am new to Python and was asked to create a program that would take an input as a non-negative integer n and then compute an approximation for the value of e using the first n + 1 terms of the continued fraction: I have attempted to decipher the question but

Optimal shift scheduling algorithm

China☆狼群 提交于 2021-02-07 02:50:55
问题 I have been trying for some time solve a scheduling problem for a pool that I used to work at. This problem is as follows... There are X many lifeguards that work at the pool, and each has a specific number of hours they would like to work. We hope to keep the average number of hours away from each lifeguards desired number of hours as low as possible, and as fair as possible for all. Each lifeguard is also a college student, and thus will have a different schedule of availability. Each week

Need help fixing an algorithm that approximates pi

被刻印的时光 ゝ 提交于 2020-05-15 06:37:05
问题 I'm trying to write the C code for an algorithm that approximates pi . It's supposed to get the volume of a cube and the volume of a sphere inside that cube (the sphere's radius is 1/2 of the cube's side). Then I am supposed to divide the cube's volume by the sphere's and multiply by 6 to get pi. It's working but it's doing something weird in the part that is supposed to get the volumes. I figure it's something to do the with delta I chose for the approximations. With a cube of side 4 instead

Approximation error when using sqrt and floor

荒凉一梦 提交于 2020-01-24 10:56:05
问题 I have to do an enumeration of solutions of an equation and I know that y < x *( sqrt(n) - 1 ) , where x , y and n are integers. My naive approach would be to look for y less or equal than floor( x * ( sqrt( (float)n ) - 1 ) ) . Should I be worried about approximation error? For example, if my expression is a little be greater than an integer m , should I be worried to get m-1 at the end? How could I detect such errors? 回答1: You should definitely be worried about approximation error, but how

Removing slow int64 division from fixed point atan2() approximation

大兔子大兔子 提交于 2020-01-24 10:10:48
问题 I made a function to compute a fixed-point approximation of atan2(y, x). The problem is that of the ~83 cycles it takes to run the whole function, 70 cycles (compiling with gcc 4.9.1 mingw-w64 -O3 on an AMD FX-6100) are taken entirely by a simple 64-bit integer division! And sadly none of the terms of that division are constant. Can I speed up the division itself? Is there any way I can remove it? I think I need this division because since I approximate atan2(y, x) with a 1D lookup table I

Trying to implement the difference formula in MATLAB

女生的网名这么多〃 提交于 2020-01-16 06:10:36
问题 Im trying to implement the difference formula f'(x) ≈ [ f(x+h) - f(x) ] / h using MATLAB for x=1 and h=10^-k , where k=0,...,16 . Furthermore, I want to plot the error. Below is my code. I see that the error is around 3, which I believe it too big. It should be close to 0. syms f(x) f(x) = tan(x); df = diff(f,x); x = 1; for k = 0:16 h = 10^-k; finitediff = double((f(x+h)-f(x))/h); err = double(abs(finitediff-df(x))); end 回答1: There is nothing wrong in your code, the finite difference formula

Graph partitioning based on nodes and edges weights

风格不统一 提交于 2020-01-06 15:40:10
问题 I have a graph G=(V,E) that both edges and nodes have weights. I want to partition this graph to create equal sized partitions. The definition of the size of partition is sum(vi)-sum(ej) where vi is a node inside that partition and ej is an edge between two nodes in that partition. In my problem the graph is very dense (almost complete). Is there any approximation algorithm for that? This is somehow similar to the problem in bin packing with overlapping objects where bins have the same size.

RGB Similar Color Approximation Algorithm

て烟熏妆下的殇ゞ 提交于 2020-01-01 03:11:16
问题 Given that in RGB we can represent 256^3 combinations = 16,777,216 colors, and since the human eye can only distinguish roughly 10,000,000, there is obviously a surplus of 6,777,216 RGB combinations that chromatically are indistinguishable from counterpart colors. Compression algorithms work on this basis when approximating out spacial difference in color ranges across a frame I believe. With that in mind, how can one reliably compute whether a given color is within a range of 'similarity' to

In spark, how to estimate the number of elements in a dataframe quickly

不羁岁月 提交于 2019-12-30 07:50:59
问题 In spark, is there a fast way to get an approximate count of the number of elements in a Dataset ? That is, faster than Dataset.count() does. Maybe we could calculate this information from the number of partitions of the DataSet, could we ? 回答1: You could try to use countApprox on RDD API, altough this also launches a Spark job, it should be faster as it just gives you an estimate of the true count for a given time you want to spend (milliseconds) and a confidence interval (i.e. the