Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8209267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:39:54+00:00 2026-06-07T09:39:54+00:00

I would like to find the inverse of a matrix. I know this involves

  • 0

I would like to find the inverse of a matrix.

I know this involves first LU factorisation then the inversion step but I cannot find the required function by searching apple’s docs of 10.7!

This seems like a useful post Symmetric Matrix Inversion in C using CBLAS/LAPACK, pointing out that the sgetrf_ and sgetri_ functions should be used. However searching these terms I find nothing in Xcode docs.

Does anybody have boiler plate code for this matrix operation?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T09:39:56+00:00Added an answer on June 7, 2026 at 9:39 am

    Apple does not document the LAPACK code at all, I guess because they just implement the standard interface from netlib.org. It’s a shame that you cannot search the these function names from the built-in Xcode docs, however the solution is fairly straight forward: just specify the function name in the URL e.g. for dgetrf_() go to, http://www.netlib.org/clapack/what/double/dgetrf.c.

    To invert a matrix two LAPACK function are need: dgetrf_(), which performs LU factorisation, and dgetri_() which takes the output of the previous function and does the actual inversion.

    I created a standard Application Project using Xcode, added the Accelerate Framework, create two C files: matinv.h, matinv.c and edited the main.m file to remove Cocoa things:

    // main.m
    
    #import "matinv.h"
    
    int main(int argc, char *argv[])
    {
        int N = 3;
        double A[N*N];
        A[0] = 1; A[1] = 1; A[2] = 7;
        A[3] = 1; A[4] = 2; A[5] = 1;
        A[6] = 1; A[7] = 1; A[8] = 3;
        matrix_invert(N, A);
        //        [ -1.25  -1.0  3.25 ]
        // A^-1 = [  0.5       1.0  -1.5  ]
        //        [  0.25   0.0 -0.25 ] 
        return 0;
    }
    

    Now the header file,

    //  matinv.h
    
    int matrix_invert(int N, double *matrix);
    

    and then source file,

    int matrix_invert(int N, double *matrix) {
    
        int error=0;
        int *pivot = malloc(N*sizeof(int)); // LAPACK requires MIN(M,N), here M==N, so N will do fine.
        double *workspace = malloc(N*sizeof(double));
    
        /*  LU factorisation */
        dgetrf_(&N, &N, matrix, &N, pivot, &error);
    
        if (error != 0) {
            NSLog(@"Error 1");
            free(pivot);
            free(workspace);
            return error;
        }
    
        /*  matrix inversion */
        dgetri_(&N, matrix, &N, pivot, workspace, &N, &error);
    
        if (error != 0) {
            NSLog(@"Error 2");
            free(pivot);
            free(workspace);
            return error;
        }
    
        free(pivot);
        free(workspace);
        return error;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to find out the date of the Monday in this year's
I would like to find if this file /path/to/file/profile.yaml contains the folowing values: Cpanel::Easy::PHP5::Curl:
I would like to find the distance of every pixel coordinate in an image
I would like to find out which version of an executable the CMD shell
I would like to find a way to store multiple addresses for one subject
I would like to find out is as3 is doing is doing anything in
I would like to find an API like Apache Commons that will easily and
I would like to find a way to see what happens while my XAML
I would like to find the values of some of windows API constants, such
I would like to find a way to compile and package our iPhone application

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.