Created
July 10, 2020 11:57
-
-
Save dj1711572002/e27b093453b8f4eefd4e0d58d7c56359 to your computer and use it in GitHub Desktop.
Processing pallav.Matrix for Moore-Penrose InverseMatrix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pallav.Matrix.*; | |
//Processing Matrix Libraly | |
//Demonstrating use of some of the static Methods of library | |
// MatrixTEST00_pallav_Matrix_asampleUseCases.pde | |
// ==========Shinshu-Makers MatrixLibrary Study no1============================= | |
int m = 3, n = 2; | |
float[][] A={{1,1},{1,-1},{0,1}}; //A data array | |
float[][]B={ {4},{0},{1} }; //B const array | |
float[][] At=new float [n][m]; | |
float[][] AtA=new float[n][n];// Square Matrix | |
float[][] AtA_1=new float[n][n];//Inverse Matrix | |
float[][] MPA=new float[m][m];// Moore_Penrose Inverse Matrix | |
float [][] XY=new float[1][2];// Calcuration Result | |
void setup() | |
{ | |
Matrix.print("array=",A); | |
Matrix.print("array=",B); | |
Rect_trans(A,At);//Traspose Rectangular Matrix X | |
Matrix.print("At=",At); | |
AtA=Matrix.Multiply(At,A);// Multiply Xt X then SquareMatrix get | |
Matrix.print("AtA=",AtA); | |
AtA_1=Matrix.inverse(AtA);//Inverse Matrix | |
Matrix.print("AtA_1=",AtA_1); | |
Matrix mAt=Matrix.array(At);//Matrix henkan | |
Matrix mAtA=Matrix.array(AtA);//Matrix henkan | |
Matrix mAtA_1=Matrix.array(AtA_1);//Matrix henkan | |
Matrix mMPA=Matrix.Multiply(mAtA_1,mAt);// Moore-Penrose Inverse Matrix XtX*Xt | |
Matrix.print("MPa+=",mMPA); | |
Matrix mB=Matrix.array(B); | |
//Matrix mXY=Matrix.array(XY); | |
Matrix mXY=Matrix.Multiply(mMPA,mB); | |
Matrix.print("mXY=",mXY); | |
} | |
///======Rectangular Matrix Transpose==================================== | |
void Rect_trans(float [][] array_Src,float [][] array_Trans) | |
{ | |
int Rnum,Cnum; | |
int i,j,k; | |
Rnum=array_Src.length; | |
Cnum=array_Src[0].length; | |
println("Rnum=",Rnum,"Cnum=",Cnum); | |
for(j=0;j<Cnum;j++) | |
{ | |
for (i=0;i<Rnum;i++) | |
{ | |
//println("array_src[",i,"][",j,"]=",array_Src[i][j]); | |
array_Trans[j][i]=array_Src[i][j]; | |
} | |
} | |
//Matrix.print("array_Src=",array_Src); | |
//Matrix.print("array_Trans=",array_Trans); | |
} | |
//============================================================== | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment