ios - Matrix multiplication and inverse problems with accelerate framework -


i trying multiply 2 matrices in objective-c. have imported accelerate framework project in xcode, compiles fine. did matrix multiplication on calculator , got correct values, however, when running code, not. how defined matrices..

float matrixa [3][3] = {{-.045, -.141, -.079}, {-.012, -.079, .0578}, {.112, -.011, -.0830}};  float matrixb [3][1] = {{40}, {-61}, {98}}; 

i used mmul function in accelerate framework..

vdsp_mmul(&matrixa[3][3], 1, &matrixb[3][1], 1, &results[3][1], 1, 3, 1, 3); 

the array results created doing following..

float results[3][1]; 

i placed in viewdidload method of empty project nslog results. when multiply matrixa matrixb should following results.. (-1, 10, -3). however, results in nslog show (-0.045, 0.000, 0.000). not correct , don't understand why. understanding function multiply 2 matrices together. not sure doing. inputing incorrectly , hoping me out.

side note: matrixa inverse of matrix. however, can't find in accelerate framework take inverse. did find function called

sgetrf_ 

with lapack don't it. if has help, advice, or tutorial follow appreciate it, been @ 3 days looking thing on internet!!

you passing pointers memory after end of matrices.

fixing (untested code):

vdsp_mmul(&matrixa[0][0], 1, &matrixb[0][0], 1, &results[0][0], 1, 3, 1, 3); 

passing array function in c pass pointer first element of array, in case appears need do. passing pointer piece of memory directly after final array element in matrices, means you'll nonsense results, or crash.


Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -