exponential

Function returning random double with exponential distribution in range (a,b)

怎甘沉沦 提交于 2019-12-10 21:25:53
问题 I want to generate a random number from a to b . The problem is, the number has to be given with exponential distribution. Here's my code: public double getDouble(double low, double high) { double r; (..some stuff..) r = rand.NextDouble(); if (r == 0) r += 0.00001; return (1 / -0.9) * Math.Log(1 - r) * (high - low) + low; } The problem is that (1 / -0.9) * Math.Log(1 - r) is not between 0 and 1, so the result won't be between a and b . Can someone help? Thanks in advance! 回答1: I

How can I overlay timeseries models for exponential decay into ggplot2 graphics?

浪尽此生 提交于 2019-12-08 14:08:30
问题 I'm trying to plot an exponential decay line (with error bars) onto a scatterplot in ggplot of price information over time. I currently have this: f2 <- ggplot(data, aes(x=date, y=cost) ) + geom_point(aes(y = cost), colour="red", size=2) + geom_smooth(se=T, method="lm", formula=y~x) + # geom_smooth(se=T) + theme_bw() + xlab("Time") + scale_y_log10("Price over time") + opts(title="The Falling Price over time") print(f2) The key line is in the geom_smooth command, of formula=y~x Although this

Convert exponential format into numeric format in XSLT

旧城冷巷雨未停 提交于 2019-12-08 09:45:49
问题 I have to convert within my XSLT number in exponential format ( i.e: 1,2345E7 ) into numeric ( i.e: 12340000 ). What would the a XSLT function to achieve this. 回答1: I haven't tried it, but this implementation claims to do what you ask: http://www.orm-designer.com/article/xslt-convert-scientific-notation-to-decimal-number 回答2: XSLT 2.0 accepts exponential notation for numbers on input, XSLT 1.0 does not. So the answer rather depends which version you are using (I suspect you are using 1.0,

Convert '6E+007' into Decimal

心不动则不痛 提交于 2019-12-08 03:06:03
问题 I have a python function that checks if the value passed is a valid number. The values passed are in string format. def is_valid_numeral(text_to_check): '''Check if passed value is a valid numeral figure''' try: float(text_to_check) return True except ValueError: return False A value like 6E+007 is passed and this function returns True which is correct. After the above function, I need to save the passed figure into a Decimal field. So I run a format_decimal function as below def format

round exponential float to 2 decimals

时间秒杀一切 提交于 2019-12-07 17:13:43
问题 I want to round exponential float to two decimal representation in Python. 4.311237638482733e-91 --> 4.31e-91 Do you know any quick trick to do that? Simple solutions like round(float, 2) and "%.2f"%float are not working with exponential floats:/ EDIT: It's not about rounding float, but rounding exponential float, thus it's not the same question as How to round a number to significant figures in Python 回答1: You can use the g format specifier, which chooses between the exponential and the

How to find the Longest Common Subsequence in Exponential time?

坚强是说给别人听的谎言 提交于 2019-12-07 10:52:27
问题 I can do this the proper way using dynamic programming but I can't figure out how to do it in exponential time. I'm looking to find the largest common sub-sequence between two strings. Note: I mean subsequences and not sub-strings the symbols that make up a sequence need not be consecutive. 回答1: Just replace the lookups in the table in your dynamic programming code with recursive calls. In other words, just implement the recursive formulation of the LCS problem: EDIT In pseudocode (almost

Computing e^(-j) in C

≡放荡痞女 提交于 2019-12-07 07:06:49
问题 I need to compute imaginary exponential in C. As far as I know, there is no complex number library in C. It is possible to get e^x with exp(x) of math.h , but how can I compute the value of e^(-i) , where i = sqrt(-1) ? 回答1: Note that exponent of complex number equals: e^(ix) = cos(x)+i*sin(x) Then: e^(-i) = cos(-1)+i*sin(-1) 回答2: In C99, there is a complex type. Include complex.h ; you may need to link with -lm on gcc. Note that Microsoft Visual C does not support complex ; if you need to

Convert '6E+007' into Decimal

给你一囗甜甜゛ 提交于 2019-12-06 10:23:40
I have a python function that checks if the value passed is a valid number. The values passed are in string format. def is_valid_numeral(text_to_check): '''Check if passed value is a valid numeral figure''' try: float(text_to_check) return True except ValueError: return False A value like 6E+007 is passed and this function returns True which is correct. After the above function, I need to save the passed figure into a Decimal field. So I run a format_decimal function as below def format_decimal(value, decimals): '''Format a value to "n" decimal places http://mkaz.com/solog/python/python-string

How to redefine the .^ operator in MATLAB?

▼魔方 西西 提交于 2019-12-06 06:55:30
问题 How can I redefine the exponential function .^ in MATLAB? From: x.^y to: sign(x).*abs(x.^y)) 回答1: Can you redefine an arithmetic operator in MATLAB?... Yes Should you redefine an arithmetic operator in MATLAB?... Eh, probably not. Why? Because every other function in MATLAB expects that the arithmetic operator will behave as defined by the built-in implementation. I've answered a few other related questions that have dealt with overloading arithmetic operators and shadowing built-in behavior,

Force exponential format of ticks LIKE MATLAB does it automatically

◇◆丶佛笑我妖孽 提交于 2019-12-06 01:45:28
问题 I have two plots. In the first plot the values for the y-axis go up to 30000. Therefor, Matlab is labeling the axis instead of '30000' with '3' and the 'x10^4' ABOVE the plot. In the second plot the y-values just go til 10000. Due to the fact that this value is too low to automatically switch to exponential format it really prints '10000'. I would like to know if there is a way to force the exponential formatting. This will result in THE SAME FORMAT as Matlab does it automatically. I am