Newsgroup: it.comp.lang.c++
Titolo: problema con puntatori

Sono nuovo nella programmazione in c e ho incontrato un problema nel gestire
un passaggio di variabile ad una funzione si fatta;
#include <math.h>
void tred2(float **a, int n, float d[], float e[])
/*Householder reduction of a real, symmetric matrix a[1..n][1..n]. On
output, a is replaced
by the orthogonal matrix Q e ecting the transformation. d[1..n] returns the
diagonal ele-
ments of the tridiagonal matrix, and e[1..n] the o -diagonal elements, with
e[1]=0. Several
statements, as noted in comments, can be omitted if only eigenvalues are to
be found, in which
case a contains no useful information on output. Otherwise they are to be
included.*/
{
 int l,k,j,i;
 float scale,hh,h,g,f;
 for (i=n;i>=2;i--)
 {
  l=i-1;
   a e una matrice che devo tridiagonalizzare cosa devo mettere nella
chiamata a funzione da main;
float a[4][4];
tred2(a,....
float a[4][4];
tred2(a[][],
float b[4][4];
float *a;
a=b;
tred2(a,.....    con b la matrice da tridiagonalizzare
Cosa vuol dire float **a nella definizione della funzione.
GRAZIE.
Andrea.

 void tred2(float **a, int n, float d[], float e[])



... togliete Ino dal mio nome per e-mail ...

GRAZIE.
Penso di aver risolto li problema nella seguente maniera.
 #include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
static float sqrarg;
#define SQR(a) ((sqrarg=(a)) == 0.0 ? 0.0 : sqrarg*sqrarg)
#define SIGN(a,b) ((b) >= 0.0 ? fabs(a) : -fabs(a))
void nrerror(char error_text[]);
void tqli(float d[], float e[], int n, float **z);
//float
a[5][5]={{1,0,0,0,0},{0,1,2,0,0},{0,2,1,2,0},{0,0,2,1,2},{0,0,0,2,1}};
float d[5],e[5];
void tred2(float **a, int n, float d[], float e[]);
main()
{
float a[5][5]={{0,0,0,0,0},{0,1,6,1,5},{0,6,2,2,4},{0,1,2,3,3},{0,5,4,3,4}};
float **aa;
int i;
aa=(float **) malloc((unsigned) 5*sizeof(float*));
for(i=0;i<=4;i++) aa[i]=a[i];
 tred2(aa,4,d,e);
 tqli(d,e,4,aa);
}
void tred2(float **a, int n, float d[], float e[])
/*Householder reduction of a real, symmetric matrix a[1..n][1..n]. On
output, a is replaced
by the orthogonal matrix Q e_ecting the transformation. d[1..n] returns the
diagonal ele-
ments of the tridiagonal matrix, and e[1..n] the o_-diagonal elements, with
e[1]=0. Several
statements, as noted in comments, can be omitted if only eigenvalues are to
be found, in which
case a contains no useful information on output. Otherwise they are to be
included.*/
{
int l,k,j,i;
float scale,hh,h,g,f;
for (i=n;i>=2;i--) {
l=i-1;
h=scale=0.0;
if (l > 1) {
for (k=1;k<=l;k++)
scale += fabs(a[i][k]);
if (scale == 0.0)
e[i]=a[i][l];
else {
for (k=1;k<=l;k++) {
a[i][k] /= scale;
h += a[i][k]*a[i][k];
}
f=a[i][l];
g=(f >= 0.0 ? -sqrt(h) : sqrt(h));
e[i]=scale*g;
h -= f*g;
a[i][l]=f-g;
f=0.0;
for (j=1;j<=l;j++) {
/* Next statement can be omitted if eigenvectors not wanted */
a[j][i]=a[i][j]/h;
g=0.0;
for (k=1;k<=j;k++)
g += a[j][k]*a[i][k];
for (k=j+1;k<=l;k++)
g += a[k][j]*a[i][k];
e[j]=g/h;
f += e[j]*a[i][j];
}
hh=f/(h+h);
for (j=1;j<=l;j++)
f=a[i][j];
e[j]=g=e[j]-hh*f;
for (k=1;k<=j;k++)
a[j][k] -= (f*e[k]+g*a[i][k]);
}
}
} else
e[i]=a[i][l];
d[i]=h;
}
/* Next statement can be omitted if eigenvectors not wanted */
d[1]=0.0;
e[1]=0.0;
/* Contents of this loop can be omitted if eigenvectors not
wanted except for statement d[i]=a[i][i]; */
for (i=1;i<=n;i++)
l=i-1;
if (d[i])
for (j=1;j<=l;j++) {
g=0.0;
for (k=1;k<=l;k++)
g += a[i][k]*a[k][j];
for (k=1;k<=l;k++)
a[k][j] -= g*a[k][i];
}
}
d[i]=a[i][i];
a[i][i]=1.0;
for (j=1;j<=l;j++) a[j][i]=a[i][j]=0.0;
}
 for(i=1;i<=4;i++)
 {
  printf("valore di e= %f valore di d= %f \n",e[i],d[i]);
 }
 for(i=1;i<=4;i++)
 {
  for(j=1;j<=4;j++) printf("%4.4f ",a[i][j]);
  printf("\n");
 }
}
void tqli(float d[], float e[], int n, float **z)
/*QL algorithm with implicit shifts, to determine the eigenvalues and
eigenvectors of a real, sym-
metric, tridiagonal matrix, or of a real, symmetric matrix previously
reduced by tred2 x 11.2. On
input, d[1..n] contains the diagonal elements of the tridiagonal matrix. On
output, it returns
the eigenvalues. The vector e[1..n] inputs the subdiagonal elements of the
tridiagonal matrix,
with e[1] arbitrary. On output e is destroyed. When _nding only the
eigenvalues, several lines
may be omitted, as noted in the comments. If the eigenvectors of a
tridiagonal matrix are de-
sired, the matrix z[1..n][1..n] is input as the identity matrix. If the
eigenvectors of a matrix
that has been reduced by tred2 are required, then z is input as the matrix
output by tred2.
In either case, the kth column of z returns the normalized eigenvector
corresponding to d[k].*/
{
float pythag(float a, float b);
int m,l,iter,i,k;
float s,r,p,g,f,dd,c,b;
for (i=2;i<=n;i++) e[i-1]=e[i];
e[n]=0.0;
for (l=1;l<=n;l++) {
iter=0;
do {
for (m=l;m<=n-1;m++)
dd=fabs(d[m])+fabs(d[m+1]);
if ((float)(fabs(e[m])+dd) == dd) break;
}
if (m != l) {
if (iter++ == 30) nrerror("Too many iterations in tqli");
g=(d[l+1]-d[l])/(2.0*e[l]);
r=pythag(g,1.0);
g=d[m]-d[l]+e[l]/(g+SIGN(r,g));
for (i=m-1;i>=l;i--)
f=s*e[i];
b=c*e[i];
e[i+1]=(r=pythag(f,g));
if (r == 0.0)
d[i+1] -= p;
e[m]=0.0;
break;
}
s=f/r;
c=g/r;
g=d[i+1]-p;
r=(d[i]-g)*s+2.0*c*b;
d[i+1]=g+(p=s*r);
g=c*r-b;
/* Next loop can be omitted if eigenvectors not wanted*/
for (k=1;k<=n;k++)
f=z[k][i+1];
z[k][i+1]=s*z[k][i]+c*f;
z[k][i]=c*z[k][i]-s*f;
}
}
if (r == 0.0 && i >= l) continue;
d[l] -= p;
e[l]=g;
e[m]=0.0;
}
} while (m != l);
}
}
float pythag(float a, float b)
//Computes (a 2 + b 2 ) 1=2 without destructive under ow or over ow.
{
 float absa,absb;
 absa=fabs(a);
 absb=fabs(b);
 if (absa > absb) return absa*sqrt(1.0+SQR(absb/absa));
 else
  return (absb == 0.0 ? 0.0 : absb*sqrt(1.0+SQR(absa/absb)));
}
void nrerror(char error_text[])
/* Numerical Recipes standard error handler */
{
fprintf(stderr,"Numerical Recipes run-time error...\n");
fprintf(stderr,"%s\n",error_text);
fprintf(stderr,"...now exiting to system...\n");
exit(1);
}
SECONDO VOI FUNZIONA ??
Andrea.