numerical-methods

C#: Loop to find minima of function

蓝咒 提交于 2019-12-10 17:35:07
问题 I currently have this function: public double Max(double[] x, double[] y) { //Get min and max of x array as integer int xMin = Convert.ToInt32(x.Min()); int xMax = Convert.ToInt32(x.Max()); // Generate a list of x values for input to Lagrange double i = 2; double xOld = Lagrange(xMin,x,y); double xNew = xMax; do { xOld = xNew; xNew = Lagrange(i,x,y); i = i + 0.01; } while (xOld > xNew); return i; } This will find the minimum value on a curve with decreasing slope...however, given this curve,

problem with arithmetic using logarthms to avoid numerical underflow

﹥>﹥吖頭↗ 提交于 2019-12-10 15:46:23
问题 I have two lists of fractions; say A = [ 1/212, 5/212, 3/212, ... ] and B = [ 4/143, 7/143, 2/143, ... ] . If we define A' = a[0] * a[1] * a[2] * ... and B' = b[0] * b[1] * b[2] * ... I want to calculate the values of A' / B' , My trouble is A are B are both quite long and each value is small so calculating the product causes numerical underflow very quickly... I understand turning the product into a sum through logarithms can help me determine which of A' or B' is greater ie max( log(a[0])

Using R to solve equations

限于喜欢 提交于 2019-12-10 14:56:19
问题 How might I solve for the roots of an equation of the following form numerically in R: f(r)=r*c+1-B*c-exp(-M(B-r)) Where M, B and c are known constants. Thanks in advance. 回答1: Since R can not do this functionality you might want to use a superset package like Sage. Sage includes R and many other packages and can do what you want using a webbrowser interface. The site is http://www.sagemath.org/ Examples are located at: http://www.sagemath.org/doc/reference/sage/symbolic/relation.html You can

Limiting Number of Decimal Places in GWT?

孤街醉人 提交于 2019-12-10 13:27:52
问题 In pure Java, I would normally have a function like the one below for limiting the number of decimal places to decimalCount for a given number value . However, according to the GWT docs, "GWT does not provide full emulation for the date and number formatting classes (such as java.text.DateFormat, java.text.DecimalFormat, java.text.NumberFormat, and java.TimeFormat)." What would one do to the following function in order to make it work in GWT? public static String getFormatted(double value,

Solve a particular linear system efficiently in julia

倾然丶 夕夏残阳落幕 提交于 2019-12-10 10:49:42
问题 I use extensively the julia's linear equation solver res = X\b . I have to use it millions of times in my program because of parameter variation. This was working ok because I was using small dimensions (up to 30 ). Now that I want to analyse bigger systems, up to 1000 , the linear solver is no longer efficient. I think there can be a work around. However I must say that sometimes my X matrix is dense, and sometimes is sparse, so I need something that works fine for both cases. The b vector

Vertical line fit using polyfit

牧云@^-^@ 提交于 2019-12-10 02:02:15
问题 Its just a basic question. I am fitting lines to scatter points using polyfit . I have some cases where my scatter points have same X values and polyfit cant fit a line to it. There has to be something that can handle this situation. After all, its just a line fit. I can try swapping X and Y and then fir a line. Any easier method because I have lots of sets of scatter points and want a general method to check lines. Main goal is to find good-fit lines and drop non-linear features. 回答1: First

Optimization to find complex number as input

隐身守侯 提交于 2019-12-09 18:12:05
问题 I am wondering if there is a C/C++ library or Matlab code technique to determine real and complex numbers using a minimization solver. Here is a code snippet showing what I would like to do. For example, suppose that I know Utilde , but not x and U variables. I want to use optimization ( fminsearch ) to determine x and U , given Utilde . Note that Utilde is a complex number. x = 1.5; U = 50 + 1i*25; x0 = [1 20]; % starting values Utilde = U * (1 / exp(2 * x)) * exp( 1i * 2 * x); xout =

Generating Full Period/Full Cycle Random Numbers or Permutations Similar to LCG but without odd/even

限于喜欢 提交于 2019-12-09 05:47:15
问题 I wish to generate psuedo-random numbers/permutations that 'occupy' a full period or full cycle within a range. Usually an 'Linear Congruential Generator' (LCG) can be used to generate such sequences, using a formula such as: X = (a*Xs+c) Mod R Where Xs is the seed, X is the result, a and c are relatively prime constants and R is the maximum (range). (By full period/full cycle, I mean that the constants can be chosen so that any X will occur only once in some random/permuted sequence and will

Solving an overdetermined constraint system

荒凉一梦 提交于 2019-12-08 19:12:02
问题 I have n real number variables (don't know, don't really care), let's call them X[n] . I also have m >> n relationships between them let's call them R[m] , of the form: X[i] = alpha*X[j] , alpha is a nonzero positive real number, i and j are distinct but the (i, j) pair is not necessarily unique (i.e. there can be two relationships between the same variables with a different alpha factor) What I'm trying to do is find a set of alpha parameters that solve the overdetermined system in some

C++ numerical integrators to solve systems of ode's

别来无恙 提交于 2019-12-08 13:31:16
问题 I recently started using C++ and I just created a class that allows the integration of a user-defined system of ode's. It uses two different integrators in order to compare its performance. Here is the general layout of the code: class integrators { private: double ti; // initial time double *xi; // initial solution double tf; // end time double dt; // time step int n; // number of ode's public: // Function prototypes double f(double, double *, double *); // function to integrate double rk4