Skip to content
Snippets Groups Projects
Commit f78468ba authored by Lucas Christesen Ahler's avatar Lucas Christesen Ahler
Browse files

Final linear equations

parent d69e3d7c
No related branches found
No related tags found
No related merge requests found
......@@ -20,6 +20,7 @@ time_graph.png: time_test.txt Makefile
plot\
"$<" using 1:2 with line title "My QR-decomp",\
"$<" using 1:3 with line title "GSL QR-decomp",\
"$<" using 1:4 with line title "N^3",\
' | gnuplot
.PHONEY: clean
......
......@@ -34,6 +34,7 @@ void GS_decomp(gsl_matrix* A, gsl_matrix* R) {
gsl_vector_memcpy(qiRij,&(ai.vector));
gsl_vector_scale(qiRij,Rij);
gsl_vector_sub(&(aj.vector),qiRij);
gsl_vector_free(qiRij);
}
}
}
......
......@@ -9,7 +9,7 @@
#include<gsl/gsl_matrix.h>
#include<gsl/gsl_blas.h>
#include<gsl/gsl_linalg.h>
#define RND (double)rand()/RAND_MAX
#define RND (double)rand()/10000
void print_vector(char s[], gsl_vector* v);
void print_matrix(gsl_matrix* M);
......
......@@ -71,37 +71,43 @@ int main() {
print_matrix(AB);
FILE* time_test_out_stream = fopen("time_test.txt","w");
for(int N=300;N<400;N++) {
gsl_matrix* My_time_test_A = gsl_matrix_alloc(N,N);
gsl_matrix* Gsl_time_test_A = gsl_matrix_alloc(N,N);
gsl_matrix* My_time_test_R = gsl_matrix_alloc(N,N);
gsl_vector* Gsl_time_test_v = gsl_vector_alloc(N);
for(int N=250;N<500;N+=2) {
int iterations = 3;
double my_time = 0;
double gsl_time = 0;
for(int i=0;i<iterations;i++) {
gsl_matrix* My_time_test_A = gsl_matrix_alloc(N,N);
gsl_matrix* Gsl_time_test_A = gsl_matrix_alloc(N,N);
gsl_matrix* My_time_test_R = gsl_matrix_alloc(N,N);
gsl_vector* Gsl_time_test_v = gsl_vector_alloc(N);
for(int k=0; k<My_time_test_A->size1;k++) {
for(int j=0; j<My_time_test_A->size2;j++) {
double kj=RND;
gsl_matrix_set(My_time_test_A,k,j,kj);
}
}
gsl_matrix_memcpy(Gsl_time_test_A,My_time_test_A);
for(int k=0; k<My_time_test_A->size1;k++) {
for(int j=0; j<My_time_test_A->size2;j++) {
double kj=RND;
gsl_matrix_set(My_time_test_A,k,j,kj);
}
}
gsl_matrix_memcpy(Gsl_time_test_A,My_time_test_A);
clock_t my_time1 = clock();
GS_decomp(My_time_test_A,My_time_test_R);
clock_t my_time2 = clock();
double my_time = (double)(my_time2-my_time1);
clock_t my_time1 = clock();
GS_decomp(My_time_test_A,My_time_test_R);
clock_t my_time2 = clock();
my_time += (double)(my_time2-my_time1);
clock_t gsl_time1 = clock();
gsl_linalg_QR_decomp(Gsl_time_test_A,Gsl_time_test_v);
clock_t gsl_time2 = clock();
double gsl_time = (double)(gsl_time2-gsl_time1);
clock_t gsl_time1 = clock();
gsl_linalg_QR_decomp(Gsl_time_test_A,Gsl_time_test_v);
clock_t gsl_time2 = clock();
gsl_time += (double)(gsl_time2-gsl_time1);
my_time /= CLOCKS_PER_SEC;
gsl_time /= CLOCKS_PER_SEC;
fprintf(time_test_out_stream,"%i %g %g\n",N,my_time,gsl_time);
gsl_matrix_free(My_time_test_A);
gsl_matrix_free(Gsl_time_test_A);
gsl_matrix_free(My_time_test_R);
gsl_vector_free(Gsl_time_test_v);
gsl_matrix_free(My_time_test_A);
gsl_matrix_free(Gsl_time_test_A);
gsl_matrix_free(My_time_test_R);
gsl_vector_free(Gsl_time_test_v);
}
my_time /= iterations; my_time /= CLOCKS_PER_SEC;
gsl_time /= iterations; gsl_time /= CLOCKS_PER_SEC;
double func_val = 0.001+1.6e-9*pow(N,3);
fprintf(time_test_out_stream,"%i %g %g %g\n",N,my_time,gsl_time,func_val);
}
fclose(time_test_out_stream);
......
homework/linear-equations/time_graph.png

6.95 KiB | W: | H:

homework/linear-equations/time_graph.png

8.76 KiB | W: | H:

homework/linear-equations/time_graph.png
homework/linear-equations/time_graph.png
homework/linear-equations/time_graph.png
homework/linear-equations/time_graph.png
  • 2-up
  • Swipe
  • Onion skin
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment