mirror of
https://bitbucket.org/cosmicvoids/vide_public.git
synced 2025-07-04 23:31:12 +00:00
beginning to fold in HOD code with jeremy tinker's approval
This commit is contained in:
parent
d8108d3a8e
commit
44cd0eb71f
95 changed files with 21950 additions and 0 deletions
22
c_tools/hod/least_squares.c
Normal file
22
c_tools/hod/least_squares.c
Normal file
|
@ -0,0 +1,22 @@
|
|||
#include "header.h"
|
||||
|
||||
/* Just a little ditty to do a least squares fit to the arrays given
|
||||
* (assuming no errors).
|
||||
*/
|
||||
void least_squares(double *x, double *y, int n, double *a, double *b)
|
||||
{
|
||||
int i,j;
|
||||
double delta,sx=0,sy=0,sxx=0,sxy=0,syy=0;
|
||||
|
||||
for(i=0;i<n;++i)
|
||||
{
|
||||
sx+=x[i];
|
||||
sy+=y[i];
|
||||
sxx+=x[i]*x[i];
|
||||
syy+=y[i]*y[i];
|
||||
sxy+=x[i]*y[i];
|
||||
}
|
||||
delta=n*sxx-sx*sx;
|
||||
*a=(sxx*sy-sx*sxy)/delta;
|
||||
*b=(n*sxy-sx*sy)/delta;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue