•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 456,556 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,441 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser: Programming Forums
Views: 1564 | Replies: 4
![]() |
•
•
Join Date: Oct 2007
Posts: 6
Reputation:
Rep Power: 0
Solved Threads: 0
this is a small example from the gsl example online
I need to get the value from the "&evec_i.vector " into a 4x4 dimensional array
such that
abc[4][4]= vector elements
how can I do this ? those 16 values will create the 4x4 matrix
I need to get the value from the "&evec_i.vector " into a 4x4 dimensional array
such that
abc[4][4]= vector elements
how can I do this ? those 16 values will create the 4x4 matrix
#include <stdio.h>
#include <gsl/gsl_math.h>
#include <gsl/gsl_eigen.h>
int main (void)
{
double data[] = { 1.0 , 1/2.0, 1/3.0, 1/4.0,
1/2.0, 1/3.0, 1/4.0, 1/5.0,
1/3.0, 1/4.0, 1/5.0, 1/6.0,
1/4.0, 1/5.0, 1/6.0, 1/7.0 };
gsl_matrix_view m = gsl_matrix_view_array(data, 4, 4);
gsl_vector *eval = gsl_vector_alloc (4);
gsl_matrix *evec = gsl_matrix_alloc (4, 4);
gsl_eigen_symmv_workspace * w = gsl_eigen_symmv_alloc (4);
gsl_eigen_symmv (&m.matrix, eval, evec, w);
gsl_eigen_symmv_free(w);
gsl_eigen_symmv_sort (eval, evec, GSL_EIGEN_SORT_ABS_ASC);
{
int i;
for (i = 0; i < 4; i++)
{
double eval_i = gsl_vector_get(eval, i);
gsl_vector_view evec_i = gsl_matrix_column(evec, i);
printf("eigenvalue = %g\n", eval_i);
printf("eigenvector = \n");
gsl_vector_fprintf(stdout, &evec_i.vector, "%g");
}
}
return 0;
} Last edited by Ancient Dragon : Oct 18th, 2007 at 8:31 am. Reason: add code tags
•
•
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 11,541
Reputation:
Rep Power: 40
Solved Threads: 972
I don't really know, but did you try the obvious ?
for(i = 0; i < 4; ++i)
{
for(j = 0; j < 4; ++j)
{
data[i][j] = gsl_matrix_column(i, j);
}
}•
•
Join Date: Oct 2007
Posts: 6
Reputation:
Rep Power: 0
Solved Threads: 0
•
•
•
•
I don't really know, but did you try the obvious ?
for(i = 0; i < 4; ++i) { for(j = 0; j < 4; ++j) { data[i][j] = gsl_matrix_column(i, j); } }
It doesnt work, since the function takes argument as below
gsl_matrix_column (gsl_matrix * m, size_t j)
http://www.gnu.org/software/gsl/manu...005fcolumn-947
I got the value of eigenvalue pretty easily but I am having trouble with the eigenvector
•
•
Join Date: Oct 2007
Posts: 6
Reputation:
Rep Power: 0
Solved Threads: 0
Ancient Dragon:
I did a workaround the problem by printing the output of the vector to a file and then reading them into an array
sure doesnt look impressive :<
I did a workaround the problem by printing the output of the vector to a file and then reading them into an array
sure doesnt look impressive :<
#include <stdio.h>
#include <gsl/gsl_math.h>
#include <gsl/gsl_eigen.h>
// trying to take the values of eigenvector and eigenvalues and put it in a array
int main (void)
{
FILE *data3;
data3 = fopen("data3.txt", "w");
if (data3 == NULL)
{
printf("File doesn't exist\n");
exit (EXIT_FAILURE);
}
double data[] = { 1.0 , 1/2.0, 1/3.0, 1/4.0,
1/2.0, 1/3.0, 1/4.0, 1/5.0,
1/3.0, 1/4.0, 1/5.0, 1/6.0,
1/4.0, 1/5.0, 1/6.0, 1/7.0 };
double datax[4][4];
double datay[16];
gsl_matrix_view m = gsl_matrix_view_array (data, 4, 4);
gsl_vector *eval = gsl_vector_alloc (4);
gsl_matrix *evec = gsl_matrix_alloc (4, 4);
gsl_eigen_symmv_workspace * w = gsl_eigen_symmv_alloc (4);
gsl_eigen_symmv (&m.matrix, eval, evec, w);
gsl_eigen_symmv_free (w);
// gsl_vector_fprintf (stdout, evec.vector, "%g");
int i,j,p=0;
for (i = 0; i < 4; i++)
{
double eval_i = gsl_vector_get (eval, i);
gsl_vector_view evec_i = gsl_matrix_column (evec, i);
printf ("eigenvalue = %g\n", eval_i);
printf ("eigenvector = \n");
gsl_vector_fprintf (data3, &evec_i.vector, "%g");
}
gsl_vector_free (eval);
gsl_matrix_free (evec);
fclose(data3);
FILE *fr;
int n;
char line[80];
float abc[10][10];
// int i=0,j=0;
fr = fopen ("data3.txt", "r");
for(i = 0; i < 4; ++i)
{
for(j = 0; j < 4; ++j)
{
fgets(line, 80, fr);
sscanf (line, "%f", &abc[i][j]);
printf ("\n%f", abc[i][j]);
}
}
printf("\n\n");
for(i = 0; i < 4; ++i)
{
for(j = 0; j < 4; ++j)
{
printf ("%f ", abc[i][j]);
}
printf("\n");
}
fclose(fr);
return 0;
}
You're looking in the wrong section of the manual. You don't want to create a vector view. Check out this section: http://www.gnu.org/software/gsl/manu...-elements.html
I think that this is what you seek:
I think that this is what you seek:
•
•
•
•
double gsl_matrix_get (const gsl_matrix * m, size_t i, size_t j)
This function returns the (i,j)-th element of a matrix m. If i or j lie outside the allowed range of 0 to n1-1 and 0 to n2-1 then the error handler is invoked and 0 is returned. An inline version of this function is used when HAVE_INLINE is defined.
dwk
Seek and ye shall find.
"Only those who will risk going too far can possibly find out how far one can go."
-- TS Eliot.
"I have not failed. I've just found 10,000 ways that won't work."
-- Thomas Alva Edison
"The only real mistake is the one from which we learn nothing."
-- John Powell
Seek and ye shall find.
"Only those who will risk going too far can possibly find out how far one can go."
-- TS Eliot.
"I have not failed. I've just found 10,000 ways that won't work."
-- Thomas Alva Edison
"The only real mistake is the one from which we learn nothing."
-- John Powell
![]() |
•
•
•
•
•
•
•
•
DaniWeb C Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- Creating two dimensional array (C++)
- How do I convert a vector to a String array ? (Java)
- Need help passing a multi-dimensional array (C++)
- reading txt file into array (C++)
- Trying to create a method to convert string letters into a two dimensional array (Java)
- Need Help With two-dimensional array (VB.NET)
Other Threads in the C Forum
- Previous Thread: Using Returned Values and other questions...
- Next Thread: number of times each number in array occurs?



Linear Mode