I have two matrices: A and B.
- How can I save them?
- How can I calculate the inverse matrix of matrix A using the Accelerate framework?
- How to find A * B product?
- How to transfer matrix A using the Accelerate frame?
Thank you for answering my questions!
Helper file
#import <Foundation/Foundation.h> #include <Accelerate/Accelerate.h> @interface Working_with_matrices : NSObject -(int)invert_matrix:(int) N andWithMatrix:(double*) matrix; @end
Implementation file
#import "Working_with_matrices.h" #include <Accelerate/Accelerate.h> @implementation Working_with_matrices -(int) matrix_invert:(int) N andWithMatrix:(double*)matrix { int error=0; int *pivot = malloc(N*N*sizeof(int)); double *workspace = malloc(N*sizeof(double)); dgetrf_(&N, &N, matrix, &N, pivot, &error); if (error != 0) { NSLog(@"Error 1"); return error; } dgetri_(&N, matrix, &N, pivot, workspace, &N, &error); if (error != 0) { NSLog(@"Error 2"); return error; } free(pivot); free(workspace); return error; }
Call my code from the main function
#import <Foundation/Foundation.h>
mr.M
source share