problem with matrix generating code

Hello all,

I am having trouble with generating this simple code.
It keeps on posting "invalid type errors" when I am compiling it.
It also posts that there is a problem with my "int main(***)".

I really would appreciate any help that I could get.
Anyone? Please?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
using namespace std;

int main(int nNumberofArgs, char* pszArgs[])
{




int i,j,k;
double a[7][7],b[7],tol,eps,n,h;

n=7;
h=1.0/(double)(n+1);
for(i=1;i<=n+1;i++)
a[i][j]=0.0;

a[1][1]=-(2.0+4.0*h*h);
a[1][2]=1.0;

for(i=2;i<=n-1;i++)
  {
  a[i][i-1]=1.0;
  a[i][i]=-(2.0+4.0*h*h);
  a[i][i+1]=1.0;
  }

a[n][n-1]=1.0;
a[n][n]=-(2.0+4.0*h*h);

for(i=1;i<=n-1;i++)
b[i]=h*h;
b[n]=h*h-1.0;

for(i=1;i<=7;i++)
  {
  printf("b[%d]=%8.6f \n",i,b[i]);
  }




system("PAUSE");
return 0;
}
you wrote

 
a[n][n-1]=1.0;


but n was declared as double, you can access to a[unsigned int][unsigned int] not to a[double][double]

anyway you should write

 
int main(int argc, char* argv[])

this is the standard main signature
Last edited on
and this will fix my problem? where should I declare 'n'? should I declare 'n' as an int? thanks for the help alex.
Topic archived. No new replies allowed.