I have two matrices: A and B.
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 main function
#import <Foundation/Foundation.h>
#import "Working_with_matrices.h"
int main(int argc, const char * argv[])
{
int N = 3;
double A[9];
Working_with_matrices* wm=[[Working_with_matrices alloc]init];
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;
[wm invert_matrix:N andWithMatrix:A];
// [ -1.25 -1.0 3.25 ]
// A^-1 = [ 0.5 1.0 -1.5 ]
// [ 0.25 0.0 -0.25 ]
for (int i=0; i<9; i++)
{
NSLog(@"%f", A[i]);
}
return 0;
}
Accelerate provides high-performance numerical computation across all Apple platforms: MacOS, iOS, iPadOS, watchOS and tvOS. Accelerate also provides access to the machine learning accelerators in Apple Silicon Macs and recent iPhone and iPad devices.
A matrix of four columns and four rows that contains single-precision values.
This function multiplies A * B and multiplies the resulting matrix by alpha . It then multiplies matrix C by beta . It stores the sum of these two products in matrix C .
The Accelerate Framework is the core methodology that serves as the foundation of Accelerate Institute's work closing the achievement gap. By moving through the Framework objectives, educators from around the country implement the proven approach for driving ongoing results at their schools.
I'm still kinda new to using the accelerate framework but I'll answer what I can.
The method you'll want to use is vDSP_mmul
for single precision or vDSP_mmulD
for double precision. You might want to look at the documentation for it to get a better unerstanding of how to use it but heres an example to get you started.
float *matrixA; //set by you
float *matrixB; //set by you
float *matrixAB; //the matrix that the answer will be stored in
vDSP_mmul( matrixA, 1, matrixB, 1, matrixAB, 1, 4, 4, 4 );
// the 1s should be left alone in most situations
// The 4s in order are:
// the number of rows in matrix A
// the number of columns in matrix B
// the number of columns in matrix A and the number of rows in matrix B.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With