numerical

Bisection method (Numerical analysis)

最后都变了- 提交于 2019-12-02 03:12:58
How many recursions are made before every single root is found? Also, which ones are the roots? Here's my code: e=0.000001; f1=@(x) 14.*x.*exp(x-2)-12.*exp(x-2)-7.*x.^3+20.*x.^2-26.*x+12; a=0; c=3; while abs(c-a)>e b=(c+a)/2; if f1(a)*f1(b)<0 c=b; else a=b; end disp(b); end Bisection works by taking endpoints of some initial interval [a,b] and finding which half of the interval must contain the root (it evaluates the midpoint, and identifies which half has the sign change). Then bisection repeats the process on the identified half. Bisection converges upon only one possible root, and if your

How to convert a column of string to numerical?

前提是你 提交于 2019-12-01 21:18:10
I have this pandas dataframe from a query: | name | event | ---------------------------- | name_1 | event_1 | | name_1 | event_2 | | name_2 | event_1 | I need to convert the column event to numerical, or something to look like this: | name | event_1 | event_2 | ------------------------------- | name_1 | 1 | 0 | | name_1 | 0 | 1 | | name_2 | 1 | 0 | In the software rapidminer, i can do this with an operator "nominal to numerical", so i assume that in python convert the type of the column should be effective, but i can be mistaken. In the final, the idea is make a sum on the columns value with

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

Deadly 提交于 2019-12-01 19:47:27
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 that it returns the maximum of TINY_FLOAT and the actual probability, but this made me curious about

Python arithmetic with small numbers

走远了吗. 提交于 2019-12-01 17:02:02
问题 I am getting the following unexpected result when I do arithmetic with small numbers in Python: >>> sys.float_info sys.float_info(max=1.7976931348623157e+308, max_exp=1024, max_10_exp=308, min=2.2250738585072014e-308, min_exp=-1021, min_10_exp=-307, dig=15, mant_dig=53, epsilon=2.220446049250313e-16, radix=2, rounds=1) >>> (1. - (1.e-17) ) < 1. False I know that floating point numbers do not have infinite precision, but it should be able to handle "large" small numbers like 1e-17, shouldn't

Python arithmetic with small numbers

无人久伴 提交于 2019-12-01 16:50:51
I am getting the following unexpected result when I do arithmetic with small numbers in Python: >>> sys.float_info sys.float_info(max=1.7976931348623157e+308, max_exp=1024, max_10_exp=308, min=2.2250738585072014e-308, min_exp=-1021, min_10_exp=-307, dig=15, mant_dig=53, epsilon=2.220446049250313e-16, radix=2, rounds=1) >>> (1. - (1.e-17) ) < 1. False I know that floating point numbers do not have infinite precision, but it should be able to handle "large" small numbers like 1e-17, shouldn't it? wim >>> import numpy as np >>> np.nextafter(1., 0.) 0.99999999999999989 This is the next float after

C#: Numerical algorithm to generate numbers from Binomial distribution

两盒软妹~` 提交于 2019-12-01 16:05:44
I need to generate random numbers from Binomial(n,p) distribution. A Binomial(n,p) random variable is sum of n uniform variables which take 1 with probability p. In pseudo code, x=0; for(i=0; i<n; ++i) x+=(rand()<p?1:0); will generate a Binomial(n,p). I need to generate this for small as well as really large n, for example n = 10^6 and p=0.02. Is there any fast numerical algorithm to generate it? EDIT - Right now this is what I have as approximation (along with functions for exact Poisson and Normal distribution)- public long Binomial(long n, double p) { // As of now it is an approximation if

C#: Numerical algorithm to generate numbers from Binomial distribution

[亡魂溺海] 提交于 2019-12-01 15:00:53
问题 I need to generate random numbers from Binomial(n,p) distribution. A Binomial(n,p) random variable is sum of n uniform variables which take 1 with probability p. In pseudo code, x=0; for(i=0; i<n; ++i) x+=(rand()<p?1:0); will generate a Binomial(n,p). I need to generate this for small as well as really large n, for example n = 10^6 and p=0.02. Is there any fast numerical algorithm to generate it? EDIT - Right now this is what I have as approximation (along with functions for exact Poisson and

LU Decomposition from Numerical Recipes not working; what am I doing wrong?

江枫思渺然 提交于 2019-12-01 09:11:39
I've literally copied and pasted from the supplied source code for Numerical Recipes for C for in-place LU Matrix Decomposition, problem is its not working. I'm sure I'm doing something stupid but would appreciate anyone being able to point me in the right direction on this; I've been working on its all day and can't see what I'm doing wrong. POST-ANSWER UPDATE: The project is finished and working . Thanks to everyone for their guidance. #include <stdlib.h> #include <stdio.h> #include <math.h> #define MAT1 3 #define TINY 1e-20 int h_NR_LU_decomp(float *a, int *indx){ //Taken from Numerical

Numerical derivative of a vector

霸气de小男生 提交于 2019-12-01 07:47:18
问题 I have a problem with numerical derivative of a vector that is x: Nx1 with respect to another vector t (time) that is the same size of x. I do the following (x is chosen to be sine function as an example): t=t0:ts:tf; x=sin(t); xd=diff(x)/ts; but the answer xd is (N-1)x1 and I figured out that it does not compute derivative corresponding to the first element of x. is there any other way to compute this derivative? 回答1: You are looking for the numerical gradient I assume. t0 = 0; ts = pi/10;

LU Decomposition from Numerical Recipes not working; what am I doing wrong?

ⅰ亾dé卋堺 提交于 2019-12-01 06:21:56
问题 I've literally copied and pasted from the supplied source code for Numerical Recipes for C for in-place LU Matrix Decomposition, problem is its not working. I'm sure I'm doing something stupid but would appreciate anyone being able to point me in the right direction on this; I've been working on its all day and can't see what I'm doing wrong. POST-ANSWER UPDATE: The project is finished and working. Thanks to everyone for their guidance. #include <stdlib.h> #include <stdio.h> #include <math.h>