The above code implements the formula shown in the attached image.Code:float crocor(float a[], float b[]){ float numerator=0; float denominator=0; float t1=0,t2=0,t3=0,t4=0,t5=0; for(int i=0; i<=SCANRAD; i++){ t1+=a[i]*b[i]; t2+=a[i]; t3+=b[i]; //flsq simply squares the floating point number t4+=flsq(a[i]); t5+=flsq(b[i]); } numerator=flsq((SCANRAD+1)*t1-t2*t3); denominator=((SCANRAD+1)*t4-flsq(t2))*((SCANRAD+1)*t5-flsq(t3)); if(denominator==0) return(0); else return(numerator/denominator); }
This code runs a number of times in my final code and the speed of the program hinges almost solely on this. Memory is not an issue. Please suggest any optimization if you can.
Regards.
P.S.: The (x 100) in the given formula is for calculating percent correlation and is not needed in the above case.




Reply With Quote