numerical-methods

incremental way of counting quantiles for large set of data

I need to count the quantiles for a large set of data. Let's assume we can get the data only through some portions (i.e. one row of a large matrix). To count the Q3 quantile one need to get all the portions of the data and store it somewhere, then sort it and count the quantile: List<double> allData = new List<double>(); foreach(var ro...

Lisp, OCaml or what for Runge Kutta?

Which language would you propose for solving a system with: first order differential equations complex variables N-dimensions using 4th order Runge Kutta or the like. Speed matters a lot but would sacrifice for: Elegant (clean and short) code Flexibility + scalability I'm mostly between a Lisp and OCaml but any other suggestion...

Matlab code help. Backward Euler method.

Here is the matlab/freemat code I got to solve ODE numerically using backward Euler method. However the results are inconsistent with my textbook results, and sometimes even ridiculously inconsistent. Please point out what is wrong with the code. I have already asked this question on mathoverflow.com no help there, hope someone here can...

How should I deal with floating numbers that numbers that can get so small that the become zero

So I just fixed an interesting bug in the following code, but I'm not sure the approach I took it the best: p = 1 probabilities = [ ... ] # a (possibly) long list of numbers between 0 and 1 for wp in probabilities: if (wp > 0): p *= wp # Take the natural log, this crashes when 'probabilites' is long enough that p ends up # being...

What algorithm to use for optimization af a function of N variables?

Given the function y=f(x1,x2,x3,x4,x5,x6), I'm trying to find the values of x1..x6, where the function reaches its maximum. The function is quite well behaved, continuous, with a single peak with the value of 1 and low-level, noise-like values around it. The function is quite costly to evaluate, so I'm looking to limit evaluations to a m...

Python+Scipy+Integration: dealing with precision errors in functions with spikes

Hi, I am trying to use scipy.integrate.quad to integrate a function over a very large range (0..10,000). The function is zero over most of its range but has a spike in a very small range (e.g. 1,602..1,618). When integrating, I would expect the output to be positive, but I guess that somehow quad's guessing algorithm is getting confus...

How to compute exact complexity of an algorithm?

Without resorting to asymptotic notation, is tedious step counting the only way to get the time complexity of an algorithm? And without step count of each line of code can we arrive at a big-O representation of any program? Details: trying to find out the complexity of several numerical analysis algorithms to decide which will be best s...

Compute perpendicular vector to a known vector, both embedded in the same plane, in 3D (R^3)

Hi, it seems to me that this is kind of a very easy question, but today I don't seem to find a reasonable answer by myself. I have two points, A and B in R^3 (3D) that belong to plane PI. I want to find a vector r in PI, perpendicular to the vector v = A - B. I know vector n, the normal of plane PI. Mathematically I can solve v.r = 0 an...

Multivariate Bisection Method

I need an algorithm to perform a 2D bisection method for solving a 2x2 non-linear problem. Example: two equations f(x,y)=0 and g(x,y)=0 which I want to solve somultaneously. I have very familiar with the 1D bisection ( as well as other numerical methods ). Assume I already know the solution lies between the bounds x1 < x < x2 and y1 < y ...

Making C code plot a graph automatically.

I have written a program which writes a list of data to a '.dat' file with the intention of then plotting it separately using gnuplot. Is there a way of making my code plot it automatically? My output is of the form: x-coord analytic approximation x-coord analytic approximation x-coord analytic approximation x-coord ...

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

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 ...

Is there a hyperreal datatype implementation for doing computations in non-standard analysis?

Non-standard mathematical analysis extends the real number line to include "hyperreals" -- infinitesimals and infinite numbers. Is there (specification for an) implementation of a data type to implement computations using hyperreals? I'm looking for something analogous to the complex number data type you find in Python and Fortran and ...

Converting a simple C code into a CUDA code

Hello, I'm trying to convert a simple numerical analysis code (trapezium rule numerical integration) into something that will run on my CUDA enabled GPU. There is alot of literature out there but it all seems far more complex than what is required here! My current code is: #include <stdio.h> #include <math.h> #include <stdlib.h> #defi...

Bounding this program to determine the sum of reciprocal integers not containing zero

Let A denote the set of positive integers whose decimal representation does not contain the digit 0. The sum of the reciprocals of the elements in A is known to be 23.10345. Ex. 1,2,3,4,5,6,7,8,9,11-19,21-29,31-39,41-49,51-59,61-69,71-79,81-89,91-99,111-119, ... Then take the reciprocal of each number, and sum the total. How can this ...

Scipy optimize.curve_fit sometimes won't converge

Hi, I'm trying to use numpy.optimize.curve_fit to estimate the frequency and phase of an on/off sequence. This is the code I'm using: from numpy import * from scipy import optimize row = array([0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0...

Is this a bug in NSolve in mathematica?

One would expect and hope that if you ask Mathematica to find the roots of a polynomial, it should give the same (approximate) answers whether you do this symbolically, then find numerical approximations to these exact answers, or whether you do it numerically. Here's an example which (in Mathematica 7, running on OS X) where this fails ...

Numerical precision in simple financial computations

Hi everyone I did a course at university that explained how (amongst other things) to order your mathematical execution to maximize precision and reduce the risk of rounding errors in a finite precision environment. We are working on a financial system with your usual interest calculations and such. Can somebody please share/remind me ...

Using a smoother with the L Method to determine the number of K-Means clusters

Has anyone tried to apply a smoother to the evaluation metric before applying the L-method to determine the number of k-means clusters in a dataset? If so, did it improve the results? Or allow a lower number of k-means trials and hence much greater increase in speed? Which smoothing algorithm/method did you use? The "L-Method" is deta...