exponential

Subset-AVG - Finding a subset of List Which Matches Known Rational Number

别来无恙 提交于 2019-12-22 01:04:35
问题 I've asked this on math overflow and used comments to clarify/overstate my question. I hope it has the intended effect and doesn't come off as jarring. I'm attempting to find what subset of numbers reach a known average. I have a list of known values, negative and possible decimals. They look something like this {-.32,-.64,-.12,.08,-.54,-.43, ...} It's around 50 numbers in some cases, though this problem would be tested for other cases as well. The set mostly contains negative decimal numbers

Real-world example of exponential time complexity

我只是一个虾纸丫 提交于 2019-12-20 08:18:11
问题 I'm looking for an intuitive, real-world example of a problem that takes (worst case) exponential time complexity to solve for a talk I am giving. Here are examples for other time complexities I have come up with (many of them taken from this SO question): O(1) - determining if a number is odd or even O(log N) - finding a word in the dictionary (using binary search) O(N) - reading a book O(N log N) - sorting a deck of playing cards (using merge sort) O(N^2) - checking if you have everything

R: approximating `e = exp(1)` using `(1 + 1 / n) ^ n` gives absurd result when `n` is large

非 Y 不嫁゛ 提交于 2019-12-19 09:48:25
问题 So, I was just playing around with manually calculating the value of e in R and I noticed something that was a bit disturbing to me. The value of e using R's exp() command... exp(1) #[1] 2.718282 Now, I'll try to manually calculate it using x = 10000 x <- 10000 y <- (1 + (1 / x)) ^ x y #[1] 2.718146 Not quite but we'll try to get closer using x = 100000 x <- 100000 y <- (1 + (1 / x)) ^ x y #[1] 2.718268 Warmer but still a bit off... x <- 1000000 y <- (1 + (1 / x)) ^ x y #[1] 2.71828 Now, let

why (0+0i)^{0} == (nan, nan) in c++

五迷三道 提交于 2019-12-18 21:13:06
问题 take a look at the code blew: #include <complex> #include <iostream> int main() { std::cout << std::pow( std::complex<double>(0,0), std::complex<double>(0,0) ) << "\n"; std::cout << std::pow( std::complex<double>(0,0), double(0) ) << "\n"; return 0; } g++(4.8.1) gives an output of (nan,nan) (-nan,-nan) while clang++(3.3) gives an out put of (-nan,-nan) (-nan,-nan) But I am expecting (1.0, 0.0). Can anyone give an explanation? 回答1: According to std::pow documentation Return value base raised

Recursive power function: Why does this work if there's no initial return value?

坚强是说给别人听的谎言 提交于 2019-12-18 03:01:07
问题 because power(base, exponent) has no return value unless exponent is 0, initially, shouldn't power(base, exponent -1) return 'undefined', and therefore be unmultipliable, initially? So, I am having trouble following the logic of this code. Why/how does it work? function power(base, exponent) { if (exponent == 0) return 1; else return base * power(base, exponent - 1); } 回答1: It could be more concise: function power(base, exponent) { return exponent == 0? 1 : base * power(base, --exponent); }

Different output from same code with exponents in python

隐身守侯 提交于 2019-12-14 02:53:22
问题 I'm running some code in a loop, which runs for many thousands of data points, where at one point I have this line of code: z[i, j] = -math.exp(oneminusbeta[j, i]) I put comments before each line of code, and the last line comment outputted before the code crashed was this: z[30416,20] = -math.exp(oneminusbeta (which is 8.04812689598e-13)) The error was: OverflowError: math range error Which means that the above line caused the crash. However, when I open a separate console and type this a =

Better way to find the powers of 2

北城余情 提交于 2019-12-13 07:58:40
问题 I am new to python. Is 1 << n is always better than 2 ** n ? Why or Why not? Are there any better ways to find the powers of 2? 回答1: An important programming tenet: don't over-optimise prematurely. Given that 1 << n will be performed in integer arithmetic which significantly limits the results space, the fastest way would be to precompute them and use a lookup table (e.g. a simple array). For a 64 bit unsigned integral types such a table would only have 64 entries. (In C++ you could even

How to find coefficients of exponential formula from given pairs of numbers

梦想的初衷 提交于 2019-12-13 00:44:24
问题 I have 44 pairs of values, the following: X Y X Y 1 1303 23 1471979 2 2689 24 1855942 3 4373 25 2339735 4 7421 26 3096779 5 10037 27 3903252 6 13333 28 5153666 7 20665 29 6199765 8 26849 30 8185063 9 37305 31 10314552 10 47879 32 13588513 11 65572 33 17122961 12 89127 34 21576366 13 106217 35 27187657 14 152379 36 35747356 15 193512 37 45043166 16 244886 38 56755887 17 309618 39 71513915 18 414190 40 93863574 19 552058 41 118269663 20 660106 42 149021335 21 925396 43 187768443 22 1108885 44

Converting exponential number to decimal 1.11111117E+9 - trailing digits become zero

我只是一个虾纸丫 提交于 2019-12-12 21:20:23
问题 I'm trying to convert and exponential number 1.11111117E+9 which is actually a 10 digit number '1111111111'. When I'm trying to convert this exponential number using decimal.TryParse method it is making last 3 digits as zero and giving the number as ' 111111000 '. This is happening with any 10 digit number. decimal amount; decimal.TryParse("1.11111117E+9", NumberStyles.Any, null, out amount); This is weird but I'm not able to figure out what's the issue here, can anybody tell me what's wrong

How to get (-8)^0.333333 = -2 in MATLAB?

♀尐吖头ヾ 提交于 2019-12-12 20:00:31
问题 Using MATLAB exponential function: (-8)^0.333333 ans = 1.0000 + 1.7320i How to get (-8)^0.333333 = -2 instead? x=-10:-1; x.^0.333333 How to get real value? How to redefine ^ : x.^y to sign(x).*abs(x.^y)) 回答1: MATLAB 7.0 provides the NTHROOT function, which returns the real roots of a number. So your formula becomes NTHROOT(-8, 3) = -2 If you are using a version prior to MATLAB 7.0 (R14), please read the following: To obtain the real cube root of a negative real number "x", rather than