the...@hotmail.com writes:
> Ok I considered what you both said and changed some things around.
You've fixed a couple of things and broken a couple of things that were
right before. In general, you can't write a program by trying things
out to see what happens!
The trouble is I don't know how much you want to learn about programming
or C++ or even if this is come course exercise. I'm going to point out
some things about your code and then show you a working example. If you
don't want to see a working example, just don't scroll down at the end
of this post.
> #include <iostream>
> #include <fstream>
> #include <string>
You don't need <string>
> #include "lapacke.h"
>
> using namespace std;
>
> int main(){
> // list the declarations
> int matrix_layout = LAPACK_COL_MAJOR; // store arrays in column major
> char jobz = 'N'; // computes eigenvalues only
> char uplo = 'U'; // stores the upper triangle of a in an array a
> lapack_int n = 10; // the order of the matrix a
If you make this const you would be able to use it in the two array
declarations. It's generally better not to keep repeating numbers like
10, but to give them a name and use that instead.
> float* a[10][10] = {
> {1, 11, 7, 9, 7, 11, 7, 9, 2, 11},
> {11, 4, 10, 10, 6, 2, 9, 6, 10, 0},
> {7, 10, 3, 5, 4, 4, 4, 4, 6, 10,},
> {9, 10, 5, 3, 8, 8, 3, 5, 1, 8,},
> {7, 6, 4, 8, 8, 10, 5, 6, 10, 0},
> {11, 2, 4, 8, 10, 9, 4, 3, 5, 11},
> {7, 9, 4, 3, 5, 4, 3, 10, 7, 2},
> {9, 6, 4, 5, 6, 3, 10, 11, 1, 7},
> {2, 10, 6, 1, 10, 5, 7, 1, 10, 5},
> {11, 0, 10, 8, 0, 11, 2, 7, 5, 1}
> }; // the symmetric matrix a for which the eigenvalues will be found
This is the source of the error you report below. You have declared the
array a to be of pointers and you have then tried to put 100 number into
it. Remove the *.
> lapack_int lda = 10; // the leading dimension of the array a
> float* w[10]; // stores the eigenvalues
Remove the *. You want and array of floats.
> // print the eigenvalues
> ofstream fout("eigenvaluesA.txt"); // title of text output
> lapack_int LAPACKE_ssyev(int matrix_layout, char jobz, char uplo,
> lapack_int n, float* a, lapack_int lda, float* w); // compute the eigenvalues
This is not a function call. The call does not have the types, but
instead lists the values to be passed. And (as you will see if you look
at my example) you don't have to name every single one of them.
> int i;
> for (i = 0; i < n; i++);
> fout << w[i] << endl; // record the eigenvalues
> fout.close();
>
> return 0;
> };
>
>
> I realized that I wasn't actually printing my eigenvalues. I was
> printing...a statement. The error I get now is "error: invalid
> conversion from 'int' to 'float*' [-fpermissive]" which I haven't been
> able to fix. Is that because float shouldn't be a pointer?
Spoiler alert: here is a working version (after the dots).
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
#include <iostream>
#include "lapacke.h"
int main(){
const lapack_int n = 10;
float a[n][n]= {
{1, 11, 7, 9, 7,11, 7, 9, 2,11},
{11, 4,10,10, 6, 2, 9, 6,10, 0},
{7, 10, 3, 5, 4, 4, 4, 4, 6,10},
{9, 10, 5, 3, 8, 8, 3, 5, 1, 8},
{7, 6, 4, 8, 8,10, 5, 6,10, 0},
{11, 2, 4, 8,10, 9, 4, 3, 5,11},
{7, 9, 4, 3, 5, 4, 3,10, 7, 2},
{9, 6, 4, 5, 6, 3,10,11, 1, 7},
{2, 10, 6, 1,10, 5, 7, 1,10, 5},
{11, 0,10, 8, 0,11, 2, 7, 5, 1}
};
float w[n];
if (LAPACKE_ssyev(LAPACK_COL_MAJOR, 'N', 'U', n, a[0], n, w) == 0) {
for (int i = 0; i < n; i++)
std::cout << w[i] << " ";
std::cout << "\n";
}
}
--
Ben.