numeric

Predefinition of often used values in computations - does it change anything?

末鹿安然 提交于 2019-12-11 07:06:26
问题 I'm auto generating C code to compute large expressions and try to figure out with simple examples whether it makes sense to predefine certain subparts in separate variables. As a simple example, say we compute something of the form: #include <cmath> double test(double x, double y) { const double c[9][9] = { ... }; // constants properly initialized, irrelevant double expr = c[0][0]*x*y + c[1][0]*pow(x,2)*y + ... + c[8][0]*pow(x,9)*y + c[1][1]*pow(x,2)*pow(y,2) + ... + c[8][1]*pow(x,9)*pow(y,2

Converting non-integer decimal numbers to binary

偶尔善良 提交于 2019-12-11 06:25:22
问题 data frame input (DF) a 123.213 4343.344 3434.43255 422.45 34534 results required in binary (16 bits) I have tried a function intTobits rawTobits but didn't worked for me 回答1: The conversion of integer decimal numbers into binary numbers is thoroughly discussed in this post. Non-integer numbers are a different issue. For the binary representation of floating point decimal numbers you can try this function: floatToBin <- function(x){ int_part <- floor(x) dec_part <- x - int_part int_bin <- R

Display a numeric keypad on activity without an input area

空扰寡人 提交于 2019-12-11 03:59:47
问题 I use the following code to pop up the soft input keyboard in my Activity InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.getInputMethodList(); imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); This displays the alphabetic keyboard. But I want to display the numeric keyboard. Please note I know that using setInputType() works when used with an Edittext or a TextView but I want to be able to display the keyboard without an input area such

Given a number series, finding the Check Digit Algorithm…?

纵饮孤独 提交于 2019-12-11 03:35:40
问题 Suppose I have a series of index numbers that consists of a check digit. If I have a fair enough sample (Say 250 sample index numbers), do I have a way to extract the algorithm that has been used to generate the check digit? I think there should be a programmatic approach atleast to find a set of possible algorithms. UPDATE: The length of a index number is 8 Digits including the check digit. 回答1: No, not in the general case, since the number of possible algorithms is far more than what you

Calculate area between two curves (that are normal distributions)

笑着哭i 提交于 2019-12-11 03:25:34
问题 I need to calculate the area between two curves. I have lots of data, so I'd like to do it programmatically. Basically, I always have 2 normal distributions, calculated from a mean value and standard deviation. I would then like to calculate how much they intersect. Here is an example of what I mean, and also some code in R (that I don't know). Is there already a function in matplotlib or scipy or some other module that does it for me? In case I have to implement it myself, I think that I

A function for referring to columns by either name or index

℡╲_俬逩灬. 提交于 2019-12-11 02:13:54
问题 I would like to be able to refer to columns by name and index in one vector. As example I specify only: EDIT: I changed the order of the original vector as I want the order to not matter. columns <- c(1:7, "j", 8, "i") I would then like to retrieve the names of the index 1 to 9 and add them to the vector (in the correct place). I have a general idea, but coding wise I am not getting very far: library(data.table) df <- fread( "a b c d e f g h i j 1 2 3 4 5 6 7 8 9 10", header = TRUE ) function

How to simplify a symbolic and numeric mixed expression in Matlab

这一生的挚爱 提交于 2019-12-10 23:29:40
问题 I have a symbolic and numeric mixed expression: (3145495418313256125*sin(11334310783410932061962315977/17437937757178560512000000000)*cos(theta))/85568392920039424 where theta is a symbolic variable. I want to simplify this expression such that all the numeric numbers and their math operation results are changed to double. 回答1: In terms of data types, you can't mix floating point and symbolic values. However, you can use variable precision arithmetic so that the values are represented in

Strange performance behaviour for 64 bit modulo operation

混江龙づ霸主 提交于 2019-12-10 21:41:28
问题 The last three of these method calls take approx. double the time than the first four. The only difference is that their arguments doesn't fit in integer anymore. But should this matter? The parameter is declared to be long, so it should use long for calculation anyway. Does the modulo operation use another algorithm for numbers>maxint? I am using amd athlon64 3200+, winxp sp3 and vs2008. Stopwatch sw = new Stopwatch(); TestLong(sw, int.MaxValue - 3l); TestLong(sw, int.MaxValue - 2l);

BCPL octal numerical constants

纵饮孤独 提交于 2019-12-10 20:21:50
问题 I've been digging into the history of BCPL due to a question I was asked about the reasoning behind using the prefix "0x" for the representation hexadecimal numbers. In my search I stumbled upon a really good explanation of the history behind this token. (Why are hexadecimal numbers prefixed with 0x?) From this post, however, another questions sparked: For octal constants, did BCPL use 8 <digit> (As per specs: http://cm.bell-labs.com/cm/cs/who/dmr/bcpl.pdf) or did it use #<digit> (As per http

Where are the implicit conversions between Numeric and Double defined in Scala 2.9

北战南征 提交于 2019-12-10 18:05:59
问题 I've been working on some scala code that was compiling fine, but somehow I've broken the implicit conversions and I can't work out what I've done wrong. Boiling it down to a very simple case, this code doesn't compile and the reason seems to be that I'm not importing the implicit conversions between Double and Numeric[Double]: import scala.math.Numeric import scala.math.Numeric._ import scala.math.Numeric.Implicits._ import Ordering.Implicits._ object ImplicitNumericConversions { val v: