numerical-analysis

Integer cube root

你说的曾经没有我的故事 提交于 2019-12-09 05:08:33
问题 I'm looking for fast code for 64-bit (unsigned) cube roots. (I'm using C and compiling with gcc, but I imagine most of the work required will be language- and compiler-agnostic.) I will denote by ulong a 64-bit unisgned integer. Given an input n I require the (integral) return value r to be such that r * r * r <= n && n < (r + 1) * (r + 1) * (r + 1) That is, I want the cube root of n, rounded down. Basic code like return (ulong)pow(n, 1.0/3); is incorrect because of rounding toward the end of

Why is the output of inv() and pinv() not equal in Matlab and Octave?

孤街醉人 提交于 2019-12-09 03:29:11
问题 I have noticed that if A is a NxN matrix and it has the inverse matrix. But what the inv() and pinv() function output is different. - My environment is Win7x64 SP1, Matlab R2012a, Cygwin Octave 3.6.4, FreeMat 4.2 Have a look at the examples from Octave: A = rand(3,3) A = 0.185987 0.192125 0.046346 0.140710 0.351007 0.236889 0.155899 0.107302 0.300623 pinv(A) == inv(A) ans = 0 0 0 0 0 0 0 0 0 It's all the same ans result by running the same command above in Matlab. And I calculate inv(A)*A or

How to find mantissa length on a particular machine?

瘦欲@ 提交于 2019-12-06 06:39:36
问题 I'm wanting to find the number of mantissa digits and the unit round-off on a particular computer. I have an understanding of what these are, just no idea how to find them - though I understand they can vary from computer to computer. I need this number in order to perform certain aspects of numerical analysis, like analyzing errors. What I'm currently thinking is that I could write a small c++ program to slowly increment a number until overflow occurs, but I'm not sure what type of number to

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

。_饼干妹妹 提交于 2019-12-06 01:07:43
问题 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 be verified numerically? Write a computer program to verify this number. Here is what I have written so far, I need help bounding this problem as this currently

When to use DBL_EPSILON/epsilon

扶醉桌前 提交于 2019-12-05 13:37:52
The DBL_EPSILON/std::numeric_limits::epsilon will give me the smallest value that will make a difference when adding with one. I'm having trouble understanding how to apply this knowledge into something useful. The epsilon is much larger than the smallest value the computer can handle, so It would seem like a correct assumption that its safe to use smaller values than epsilon? Should the ratio between the values I'm working with be smaller than 1/epsilon ? AProgrammer The definition of DBL_EPSILON isn't that. It is the difference between the next representable number after 1 and 1 (your

How to find mantissa length on a particular machine?

给你一囗甜甜゛ 提交于 2019-12-04 12:42:41
I'm wanting to find the number of mantissa digits and the unit round-off on a particular computer. I have an understanding of what these are, just no idea how to find them - though I understand they can vary from computer to computer. I need this number in order to perform certain aspects of numerical analysis, like analyzing errors. What I'm currently thinking is that I could write a small c++ program to slowly increment a number until overflow occurs, but I'm not sure what type of number to use. Am I on the right track? How exactly does one go about calculating this? I would think that

Image interpolation from random pixels

自闭症网瘾萝莉.ら 提交于 2019-12-04 05:12:32
I would like to ask a question regarding single channel image interpolation. Single channel is chosen just for simplicity otherwise I'm working on multiple channel images. Assume there is a single channel image with pure black background ( pixel intensity 0) on which there are some pixels with non-zero intensity values. I want to apply an interpolation algorithm to fill the entire black area of the image with interpolated values coming from the neighboring non-zero intensity pixels. What interpolation algorithm would you recommend for a smooth interpolation applicable to this problem? As

How to pass a hard coded differential equation through Runge-Kutta 4

一世执手 提交于 2019-12-01 16:25:09
I'm trying to implement Runge-Kutta for example problems dy/dt = y - t^2 + 1 and dy/dt = t * y + t^3 in C# and I cannot seem to get the output I'm expecting. I have split my program into several classes to try and look at the work individually. I think that my main error is coming from trying to pass a method through the Runge-Kutta process as a variable using a delegate. Equation Class: namespace RK4 { public class Eqn { double t; double y; double dt; double b; public Eqn(double t, double y, double dt, double b) { this.t = t; this.y = y; this.dt = dt; this.b = b; } public void Run1() { double

How to pass a hard coded differential equation through Runge-Kutta 4

落花浮王杯 提交于 2019-12-01 15:24:55
问题 I'm trying to implement Runge-Kutta for example problems dy/dt = y - t^2 + 1 and dy/dt = t * y + t^3 in C# and I cannot seem to get the output I'm expecting. I have split my program into several classes to try and look at the work individually. I think that my main error is coming from trying to pass a method through the Runge-Kutta process as a variable using a delegate. Equation Class: namespace RK4 { public class Eqn { double t; double y; double dt; double b; public Eqn(double t, double y,

What algorithm is R using to calculate mean?

守給你的承諾、 提交于 2019-11-30 04:57:01
I am curious to know what algorithm R's mean function uses. Is there some reference to the numerical properties of this algorithm? I found the following C code in summary.c:do_summary(): case REALSXP: PROTECT(ans = allocVector(REALSXP, 1)); for (i = 0; i < n; i++) s += REAL(x)[i]; s /= n; if(R_FINITE((double)s)) { for (i = 0; i < n; i++) t += (REAL(x)[i] - s); s += t/n; } REAL(ans)[0] = s; break; It seems to do a straight up mean: for (i = 0; i < n; i++) s += REAL(x)[i]; s /= n; Then it adds what i assume is a numerical correction which seems to be the mean difference from the mean of the data