numerical-computing

Avoid Overflow when Calculating π by Evaluating a Series Using 16-bit Arithmetic?

£可爱£侵袭症+ 提交于 2019-12-04 23:08:19
I'm trying to write a program that calculates decimal digits of π to 1000 digits or more. To practice low-level programming for fun, the final program will be written in assembly, on a 8-bit CPU that has no multiplication or division, and only performs 16-bit additions. To ease the implementation, it's desirable to be able to use only 16-bit unsigned integer operations, and use an iterative algorithm. Speed is not a major concern. And fast multiplication and division is beyond the scope of this question, so don't consider those issues as well. Before implementing it in assembly, I'm still

How to split diagonal matrix into equal number of items each along one of axis?

一笑奈何 提交于 2019-11-30 08:52:40
问题 I have a very large diagonal matrix that I need to split for parallel computation. Due to data locality issues it makes no sense to iterate through the matrix and split every n -th calculation between n threads. Currently, I am dividing k x k diagonal matrix in the following way but it yields unequal partitions in terms of the number of the calculations (smallest piece calculates a few times longer than the largest). def split_matrix(k, n): split_points = [round(i * k / n) for i in range(n +

How to split diagonal matrix into equal number of items each along one of axis?

你离开我真会死。 提交于 2019-11-29 08:57:28
I have a very large diagonal matrix that I need to split for parallel computation. Due to data locality issues it makes no sense to iterate through the matrix and split every n -th calculation between n threads. Currently, I am dividing k x k diagonal matrix in the following way but it yields unequal partitions in terms of the number of the calculations (smallest piece calculates a few times longer than the largest). def split_matrix(k, n): split_points = [round(i * k / n) for i in range(n + 1)] split_ranges = [(split_points[i], split_points[i + 1],) for i in range(len(split_points) - 1)]

What's the relative speed of floating point add vs. floating point multiply

半世苍凉 提交于 2019-11-27 08:01:09
A decade or two ago, it was worthwhile to write numerical code to avoid using multiplies and divides and use addition and subtraction instead. A good example is using forward differences to evaluate a polynomial curve instead of computing the polynomial directly. Is this still the case, or have modern computer architectures advanced to the point where *,/ are no longer many times slower than +,- ? To be specific, I'm interested in compiled C/C++ code running on modern typical x86 chips with extensive on-board floating point hardware, not a small micro trying to do FP in software. I realize

Solving non-square linear system with R

南楼画角 提交于 2019-11-27 01:22:50
How to solve a non-square linear system with R : A X = B ? (in the case the system has no solution or infinitely many solutions) Example : A=matrix(c(0,1,-2,3,5,-3,1,-2,5,-2,-1,1),3,4,T) B=matrix(c(-17,28,11),3,1,T) A [,1] [,2] [,3] [,4] [1,] 0 1 -2 3 [2,] 5 -3 1 -2 [3,] 5 -2 -1 1 B [,1] [1,] -17 [2,] 28 [3,] 11 If the matrix A has more rows than columns, then you should use least squares fit. If the matrix A has fewer rows than columns, then you should perform singular value decomposition. Each algorithm does the best it can to give you a solution by using assumptions. Here's a link that

What's the relative speed of floating point add vs. floating point multiply

烂漫一生 提交于 2019-11-26 22:16:57
问题 A decade or two ago, it was worthwhile to write numerical code to avoid using multiplies and divides and use addition and subtraction instead. A good example is using forward differences to evaluate a polynomial curve instead of computing the polynomial directly. Is this still the case, or have modern computer architectures advanced to the point where *,/ are no longer many times slower than +,- ? To be specific, I'm interested in compiled C/C++ code running on modern typical x86 chips with

Solving non-square linear system with R

自古美人都是妖i 提交于 2019-11-26 11:08:15
问题 How to solve a non-square linear system with R : A X = B ? (in the case the system has no solution or infinitely many solutions) Example : A=matrix(c(0,1,-2,3,5,-3,1,-2,5,-2,-1,1),3,4,T) B=matrix(c(-17,28,11),3,1,T) A [,1] [,2] [,3] [,4] [1,] 0 1 -2 3 [2,] 5 -3 1 -2 [3,] 5 -2 -1 1 B [,1] [1,] -17 [2,] 28 [3,] 11 回答1: If the matrix A has more rows than columns, then you should use least squares fit. If the matrix A has fewer rows than columns, then you should perform singular value