How to invert a matrix [closed] - c++

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 9 years ago.
Improve this question
I need to solve a system of n-linear equations with n-unknown variables in C++ using the gaussian method of elimnation. Any hints how to achieve that? I'll be probably using rand(); for the amount of n, since isn't available, because C++11 I can't use.

to solve a linear system
AX=B
you need to invert a matrix A, which results in A^(-1) and multiply A^(-1) * B to obtain X.
This is the example code to invert non-singular matrix using Gauss - Jordan elimination algorithm (complexity is O(n^3)):
matrix inversion using Gauss-Jordan elimination

Related

Gaussian Elimination of a Singular Matrix [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 8 years ago.
Improve this question
So i've been struggling to find code which can solve a set of simultaneous equations and also handle possibilities of Infinite Solutions, i.e. a singular Matrix. From all the sample code Gaussian Elimination in C that i've encountered the problem arises when dividing by zero in one of the steps for row reduction. Surely there must be some numerical ways to counter this problem.
Gaussian elimination[1] does not work on singular matrices. As you noticed numerically this usually leads to devision by zero or some other problem. If you suspect that a the matrix you want to diagonalize might be singular (or numerically close to singular) you should check out Singular Value Decomposition (SVD) which either provides you with the inverse matrix or something close. A nice resource is Numerical Recipes[1] or GSL[2] if you want to look into the how and why.
[1] http://www.haoli.org/nr/bookcpdf.html (Chap. 2.1)
[2] http://www.gnu.org/software/gsl/

Calculating large numbers in C++ without external libraries [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I need to write a program that will perform operations on float numbers higher than 10^100.
I can't use any arbitrary precision mathematics libraries that are not included in GCC package by default.
I have NO idea how how to go about it.
Can you point me in the right direction?
You can create a class that can store larger numbers. 12345678 equals to 1234 * 10e4 + 5678.
For large numbers I use string buffers and do manual computation on it. It is much overhead and slow but you get infinite precision.

Obtaining an algorithm [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Let's say I have a variable a and b. Now I want to find a value for c such that the fraction a / c is a positive integer, and where c is as close to b as possible.
For example: a = 100 and b = 30.
In this case I want c to be 25; because a / c is an integer, and c is as close as b for which this holds.
Any ideas how I can program a function in C++ which does exactly this?
Find the factors of a. (search web for methods)
Scan resulting list for minimum difference vs b.
Is this a homework assignment? Either way, think about how you would solve this problem without writing any code. A good algorithm comes from a good design. Break the problem down into pieces and walk through some more examples. For example, how would you solve the problem of determining whether the division results in an integer value? Hint: There is a different operator you could use as opposed to division to achieve this easily. Now, how would you solve the problem of determining what number to start at for c in the algorithm? Do not write any code until you have the pseudocode figured out.

How to create Eigen matrix out of 2 vectors [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have 2 vectors and a matrix:
VectorXd A;
VectorXd B;
MatrixXd C;
How should I efficiently (without explicit loops and working fast)
compute matrix C values so that
C(i,k) = A(i) * B(k);
Assume that matrix C already has appropriate dimensions.
IMPORTANT: I only need help in using built-in Eigen syntax. Please no CUDA/MKL/BLAS suggestions.
Thank you.
You are looking for an outer product which is just a standard matrix product:
C = A * B.transpose();
Since the destination c does not alias with the operand of the product you can save one temporary with:
C.noalias() = A * B.transpose();
noalias makes sense for matrix products only.

Best Package for Sparse Matrix Multiplication [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 9 years ago.
Improve this question
I am looking for the best package for sparse matrix multiplication on single core solution.
I am not looking for CUDA, MPI or OpenMP solutions.
My preference for languages in decreasing order : Matlab, Python, C/C++.
Matlab has its own matrix multiplication function which can be used for sparse matrix multiplication. But are there any better package(s) available ?
I have to multiply two large matrices which are in sparse format.
Eg., one matrix is 677000-by-48000 and another is 48000-by-8192. Here, n-by-d means n : # of rows, d : # of columns
I'm no expert for sparse matrices but I do know the renowned 'eigen' C++ library.
They have a tutorial on sparse matrices, reachable from the documentation page.