I am trying to make a 2×2 matrix from two 2D arrays that contain values in C.The Matrix to be produced, named overlap and is a 2×2 matrix, has elements that are functions of each D and A Arrays.
I have written the following code and its output shown below.
I don’t know what I am doing wrong and was wondering if whoever reads this can help a misguided new C learner.
P.S. I know I can write each element explicitly then put them into a matrix without using an array; however, I plan to use this skeleton as a foundation for an automation caculcation code for bigger input.
Thank you all for your time and effort,
Moe
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define BASISFUN 2
#define PI 3.14159265358979323846
void overlaps(double overlap[][2], double d[][2], double a[][2]){
printf("nThe Overlap Matrix isn");
for (int i = 0; i < BASISFUN; i++) {
for (int j = 0; j < BASISFUN; j++) {
overlap[i][j] = 0.0;
if (i == j && i == 0){
overlap[0][0] = pow(d[0][0], 2.0) * pow((PI/(a[0][0] + a[0][0])), 1.5);
} else if (i == j && i == 1){
overlap[1][1] = pow(d[1][1], 2.0) * pow((PI/(a[1][1] + a[1][1])), 1.5);
} else if (i != j && i == 1){
overlap[1][0] = pow(d[1][0], 2.0) * pow((PI/(a[1][0] + a[1][0])), 1.5);
} else {
overlap[0][1] = pow(d[0][1], 2.0) * pow((PI/(a[0][1] + a[0][1])), 1.5);
}
printf("%.4ft", overlap[i][j]);
}
printf("n");
}
}
int main(){
double A1 = 0.532149;
double A2 = 4.097728;
double D1 = 0.82559;
double D2 = 0.28317;
double a[1][2] = {A1, A2};
double d[1][2] = {D1, D2};
double overlap[2][2];
overlaps(overlap, d, a);
return 0;
}
OUTPUT:
The Orbital Coefficient Matrix is
3.4567 0.0190
3.6998 44.0676
However, the product is supposed to be as follows when using Matlab, which is 100% correct:
3.4567 0.1307
0.1307 0.0190