Wait, why would I need to diagonalize my matrices? I wrote out a taylor expansion of e^(x) (this code werks well) but it's e^(H) I want. So I started to write code for my taylor expansion, but I need A^n, where n is an int and A is a matrix. I can't get it to work.
Code:
#include <stdio.h>
#include <math.h>
int main(){
int A[2][2]={{0,1},{1,0}};
int M[2][2]={{0,1},{1,0}};
int I[2][2]={{1,0},{0,1}};
int n;
printf("A is the sigma_x matrix.\n");
getchar();
printf("How many times do you want to multiply the matrix?\n");
scanf("%d", &n);
for (int l=0; l<n; l++){
for (int i=0; i<2; i++)
for (int j=0; j<2; j++){
for (int k=0; k<2; k++)
M[i][j]=A[i][k]*A[k][j];}}
printf("\nThis is your new matrix.\n");
for ( int i=0; i<2; i++) {
for ( int j=0; j<2; j++)
printf(" %d", M[i][j]);
printf("\n");}
getchar();
scanf("%d", &n);
if (n==1) {main();}
else
return 0;
}