numerical

Solve for integral limit

混江龙づ霸主 提交于 2019-12-20 03:23:56
问题 I need to find the limit of an integral in a numerical way, knowing the result of that integral. What I need to solve is: As you can see, that is the incomplete beta function. I know a , b and c . And the integral limits are from 0 to x . I need to find x . 回答1: The fzero function can solve all sorts of nonlinear equations. First, calculate the incomplete beta function as a function of X (I subtracted the c because we want to find the x that makes Y=0 ): Y=@(X) beta(a,b)*betainc(X,a,b)-c or,

What's the smallest non-zero, positive floating-point number in Perl?

醉酒当歌 提交于 2019-12-20 01:36:07
问题 I have a program in Perl that works with probabilities that can occasionally be very small. Because of rounding error, sometimes one of the probabilities comes out to be zero. I'd like to do a check for the following: use constant TINY_FLOAT => 1e-200; my $prob = calculate_prob(); if ( $prob == 0 ) { $prob = TINY_FLOAT; } This works fine, but I actually see Perl producing numbers that are smaller than 1e-200 (I just saw a 8.14e-314 fly by). For my application I can change calculate_prob() so

How to use TDD correctly to implement a numerical method?

旧城冷巷雨未停 提交于 2019-12-18 12:27:50
问题 I am trying to use Test Driven Development to implement my signal processing library. But I have a little doubt: Assume I am trying to implement a sine method (I'm not): Write the test (pseudo-code) assertEqual(0, sine(0)) Write the first implementation function sine(radians) return 0 Second test assertEqual(1, sine(pi)) At this point, should I: implement a smart code that will work for pi and other values, or implement the dumbest code that will work only for 0 and pi? If you choose the

Open source alternative to MATLAB's fmincon function?

孤人 提交于 2019-12-18 10:06:16
问题 Is there an open-source alternative to MATLAB's fmincon function for constrained linear optimization? I'm rewriting a MATLAB program to use Python / NumPy / SciPy and this is the only function I haven't found an equivalent to. A NumPy-based solution would be ideal, but any language will do. 回答1: Is your problem convex? Linear? Non-linear? I agree that SciPy.optimize will probably do the job, but fmincon is a sort of bazooka for solving optimization problems, and you'll be better off if you

How to write fast (low level) code? [closed]

纵然是瞬间 提交于 2019-12-18 09:54:47
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . I would like to learn more about low level code optimization, and how to take advantage of the underlying machine architecture. I am

Javascript to convert string to number?

血红的双手。 提交于 2019-12-17 20:08:29
问题 var str = '0.25'; How to convert the above to 0.25? 回答1: There are several ways to achieve it: Using the unary plus operator: var n = +str; The Number constructor: var n = Number(str); The parseFloat function: var n = parseFloat(str); 回答2: var num = Number(str); 回答3: var f = parseFloat(str); 回答4: For your case, just use: var str = '0.25'; var num = +str; There are some ways to convert string to number in javascript. The best way: var num = +str; It's simple enough and work with both int and

Least Squares C# library [closed]

孤街浪徒 提交于 2019-12-17 19:32:57
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 years ago . I am looking to perform a polynomial least squares regression and am looking for a C# library to do the calculations for me. I pass in the data points and the degree of polynomal (2nd order, 3rd order, etc) and it returns either the C0, C1, C2 etc. constant values or the calculated values "predictions". Note: I

How do I type a floating point infinity literal in python

与世无争的帅哥 提交于 2019-12-17 18:00:25
问题 How do I type a floating point infinity literal in python? I have heard inf = float('inf') is non portable. Thus, I have had the following recommended: inf = 1e400 Is either of these standard, or portable? What is best practice? 回答1: In python 2.6 it is portable if the CPU supports it The float() function will now turn the string nan into an IEEE 754 Not A Number value, and +inf and -inf into positive or negative infinity. This works on any platform with IEEE 754 semantics. 回答2: float('inf')

Plotting a line over several graphs

二次信任 提交于 2019-12-17 09:40:04
问题 I don't know how this thing is called, or even how to describe it, so the title may be a little bit misleading. The first attached graph was created with pyplot. I would like to draw a straight line that goes through all graphs instead of the three red dot I currently use. Is it possible in pyplot? Second image is what I am looking for. 回答1: You can pull this off by turning clipping off for the relevant lines. There's probably a cleaner way to do this -- you might be able to draw lines on the

Why do these division equations result in zero?

◇◆丶佛笑我妖孽 提交于 2019-12-17 02:28:05
问题 The result of all of the division equations in the below for loop is 0. How can I get it to give me a decimal e.g.: 297 / 315 = 0.30793650793650793650793650793651 Code: using System; namespace TestDivide { class Program { static void Main(string[] args) { for (int i = 0; i <= 100; i++) { decimal result = i / 100; long result2 = i / 100; double result3 = i / 100; float result4 = i / 100; Console.WriteLine("{0}/{1}={2} ({3},{4},{5}, {6})", i, 100, i / 100, result, result2, result3, result4); }