Any code examples showing how to solve Mulitple Linear Equations in objC?

Are there code examples to solve a matrix like the one below on the iPhone platform. In fact, the real matrix is ​​much larger (about 100 variables). Since this is simple linear algebra, I cannot think that this code is complex, I also heard about the mathematical library and LAPACK packages, but I can not find examples where they are implemented.

If anyone knows about any examples or tutorials on how to move from creating a matrix to solving each variable, this will be very useful thanks to the ton.

 ____            ____
|                    |
|  4   3  -1   |  2  |
| -2   3   8   |  0  |
|  0   2   6   | -1  |
|____            ____|
+5
source share
2 answers

, Objective-C - C - . C iPhone, LAPACK.

- Objective-C LAPACK, , LAPACK .

+4

CLAPACK, Apple LAPACK, iOS 4.0 .

#define N 3
#define NRHS 1
#define LDA N
#define LDB N

void solve_system() {
    __CLPK_integer n = N, nrhs = NRHS, lda = LDA, ldb = LDB, info;
    __CLPK_integer ipiv[N];

    __CLPK_real a[LDA * N] = {
        4, -2, 0,
        3, 3, 2,
        -1, 8, 6,
    };

    __CLPK_real b[LDB * NRHS] = {
        2, 0, -1,
    };

    // Solve A * x = b
    sgesv_(&n, &nrhs, a, &lda, ipiv, b, &ldb, &info);

    if(info > 0) {
        // A is singular; solution is not unique.
    }

    print_matrix(N, NRHS, b);
}

void print_matrix(size_t rows, size_t columns, __CLPK_real *mat) {
    for(size_t r = 0; r < rows; ++r) {
        for(size_t c = 0; c < columns; ++c) {
            printf("%6.2f ", mat[r * columns + c]);
        }
        printf("\n");
    }
}

LAPACK SGESV, "" . , , LAPACK FORTRAN, . __CLPK_integer __CLPK_real typedefs long float .

+3

All Articles