factorization

Efficient way to solve for X in AX=B in MATLAB when both A and B are big matrices

梦想的初衷 提交于 2019-11-28 10:19:24
I have this problem which requires solving for X in AX=B . A is of the order 15000 x 15000 and is sparse and symmetric. B is 15000 X 7500 and is NOT sparse. What is the fastest way to solve for X? I can think of 2 ways. Simplest possible way, X = A\B Using for loop, invA = A\speye(size(A)) for i = 1:size(B,2) X(:,i) = invA*B(:,i); end Is there a better way than the above two? If not, which one is best between the two I mentioned? angainor First things first - never, ever compute inverse of A. That is never sparse except when A is a diagonal matrix. Try it for a simple tridiagonal matrix. That

Efficiently finding all divisors of a number

我的未来我决定 提交于 2019-11-28 07:44:04
So I simply want to find all the divisors of a given number (excepting the number itself). Currently, I have this: public static List<int> proper_divisors(int x) { List<int> toreturn = new List<int>(); toreturn.Add(1); int i = 0; int j=1; int z = 0; while (primes.ElementAt(i) < Math.Sqrt(x)) { if (x % primes.ElementAt(i) == 0) { toreturn.Add(primes.ElementAt(i)); toreturn.Add(x / primes.ElementAt(i)); j = 2; z = (int)Math.Pow(primes.ElementAt(i), 2); while (z < x) { if (x % z == 0) { toreturn.Add(z); toreturn.Add(x / z); j++; z = (int)Math.Pow(primes.ElementAt(i), j); } else { z = x; } } } i++

Efficient storage of prime numbers

强颜欢笑 提交于 2019-11-28 03:42:58
For a library, I need to store the first primes numbers up to a limit L. This collection must have a O(1) lookup time (to check whether a number is prime or not) and it must be easy, given a number, to find the next prime number (assuming it is smaller than L). Given that L is fixed, an Eratostene sieve to generate the list is fine. Right now, I use a packed boolean array to store the list, which contains only entries for odd numbers between 3 and L (inclusive). This takes (L-2)/2 bits of memory. I would like to be able to statically increase L without using more memory. Is there a data

Efficiently getting all divisors of a given number

与世无争的帅哥 提交于 2019-11-28 03:15:25
According to this post , we can get all divisors of a number through the following codes. for (int i = 1; i <= num; ++i){ if (num % i == 0) cout << i << endl; } For example, the divisors of number 24 are 1 2 3 4 6 8 12 24 . After searching some related posts, I did not find any good solutions. Is there any efficient way to accomplish this? My solution: Find all prime factors of the given number through this solution . Get all possible combinations of those prime factors. However, it doesn't seem to be a good one. Factors are paired. 1 and 24 , 2 and 12 , 3 and 8 , 4 and 6 . An improvement of

Factorization of an integer

亡梦爱人 提交于 2019-11-27 23:03:21
While answering another, I stumbled over the question how I actually could find all factors of an integer number without the Symbolic Math Toolbox . For example: factor(60) returns: 2 2 3 5 unique(factor(60)) would therefore return all prime-factors, "1" missing. 2 3 5 And I'm looking for a function which would return all factors ( 1 and the number itself are not important, but they would be nice) Intended output for x = 60 : 1 2 3 4 5 6 10 12 15 20 30 60 I came up with that rather bulky solution, apart from that it probably could be vectorized, isn't there any elegant solution? x = 60; P =

Factor a large number efficiently with gmp

纵然是瞬间 提交于 2019-11-27 18:33:02
问题 I need to get all the prime factors of large numbers that can easily get to 1k bits. The numbers are practically random so it shouldn't be hard. How do I do it efficiently? I use C++ with GMP library. EDIT: I guess you all misunderstood me. What I mean by prime a number is to get all prime factors of the number. Sorry for my english, in my language prime and factor are the same :) clarification (from OP's other post): What I need is a way to efficiently factor(find prime factors of a number)

R Function for returning ALL factors

时光毁灭记忆、已成空白 提交于 2019-11-27 11:40:51
My normal search foo is failing me. I'm trying to find an R function that returns ALL of the factors of an integer. There are at least 2 packages with factorize() functions: gmp and conf.design, however these functions return only prime factors. I'd like a function that returns all factors. Obviously searching for this is made difficult since R has a construct called factors which puts a lot of noise in the search. To follow up on my comment (thanks to @Ramnath for my typo), the brute force method seems to work reasonably well here on my 64 bit 8 gig machine: FUN <- function(x) { x <- as

Efficient way to solve for X in AX=B in MATLAB when both A and B are big matrices

ぐ巨炮叔叔 提交于 2019-11-27 03:32:27
问题 I have this problem which requires solving for X in AX=B . A is of the order 15000 x 15000 and is sparse and symmetric. B is 15000 X 7500 and is NOT sparse. What is the fastest way to solve for X? I can think of 2 ways. Simplest possible way, X = A\B Using for loop, invA = A\speye(size(A)) for i = 1:size(B,2) X(:,i) = invA*B(:,i); end Is there a better way than the above two? If not, which one is best between the two I mentioned? 回答1: First things first - never, ever compute inverse of A.

Efficiently finding all divisors of a number

六眼飞鱼酱① 提交于 2019-11-27 01:57:23
问题 So I simply want to find all the divisors of a given number (excepting the number itself). Currently, I have this: public static List<int> proper_divisors(int x) { List<int> toreturn = new List<int>(); toreturn.Add(1); int i = 0; int j=1; int z = 0; while (primes.ElementAt(i) < Math.Sqrt(x)) { if (x % primes.ElementAt(i) == 0) { toreturn.Add(primes.ElementAt(i)); toreturn.Add(x / primes.ElementAt(i)); j = 2; z = (int)Math.Pow(primes.ElementAt(i), 2); while (z < x) { if (x % z == 0) { toreturn

What is the fastest factorization algorithm?

我与影子孤独终老i 提交于 2019-11-26 21:29:32
I've written a program that attempts to find Amicable Pairs. This requires finding the sums of the proper divisors of numbers. Here is my current sumOfDivisors() method: int sumOfDivisors(int n) { int sum = 1; int bound = (int) sqrt(n); for(int i = 2; i <= 1 + bound; i++) { if (n % i == 0) sum = sum + i + n / i; } return sum; } So I need to do lots of factorization and that is starting to become the real bottleneck in my application. I typed a huge number into MAPLE and it factored it insanely fast. What is one of the faster factorization algorithms? Sam Harwell Pulled directly from my answer