Moved linspace function into module

This commit is contained in:
Ethan Smith-Coss 2024-09-11 14:24:24 +01:00
parent 62020d51e5
commit d2a050d1da
Signed by: TheOnePath
GPG Key ID: 1D351CCC6D01F32B
2 changed files with 22 additions and 0 deletions

10
include/linalg.h Normal file
View File

@ -0,0 +1,10 @@
#include <gsl/gsl_matrix.h>
#ifndef LINALG_H
#define LINALG_H
int
linspace
( double start, double end, int length, gsl_matrix *out );
#endif

12
src/linalg.c Normal file
View File

@ -0,0 +1,12 @@
#include "linalg.h"
int linspace ( double start, double end, int length, gsl_matrix *out ) {
if ( out->size2 != length )
return 1;
double by = end / length;
for ( int i = 0 ; i < length ; i++ )
(void)gsl_matrix_set(out, 0, i, i*by);
return 0;
}