solution of tridiagonal matrix

Jan 7, 2009 at 10:16am
//tridiagonal
#include <iostream>
#include <vector>
#include <math.h>

using namespace std;
#define m 4

template<class T>
<T> tri(int n, vector<T> a,vector<T> b,vector<T> c, vector<T> u, vector<T>& v)
{
/* b :subdiagonal
* a :diagonal
* c :super diagonal
* v :column vector elements
* u :column vector unknown
* n :dimension of the matrix(n*n matrix)
*/
T xmult;
for(int i=2;i<n;i++)
{
xmult = b[i-1]/a[i-1];
a[i]-=xmult*c[i-1];
v[i]-=xmult*v[i-1];
}
u[n]=v[n]/a[n];
for(i=n-1; i<=1; i--)
u[i]=(v[i]-c[i]*u[i+1])/a[i];
}

<T> main()
{

for (i = 1; i <= m; i++)
{
a[i] = 0.5;
b[i] = 3.0;
c[i] = 0.5;
v[i] = 2.0;
}

tri (m, a, b, c, u, v);
}


When I compile this program it returns errors that I cant solve the tri function takes the dimension of the matrix, the vectors a,b,c,v and returns the vector u
Jan 7, 2009 at 11:06am
...what error?
Jan 7, 2009 at 12:05pm
<T> main()
try changing the above to int main()
Jan 7, 2009 at 3:49pm
If Warnis is right you'll need to add return 0; to the end of main() as well. Unless your funtion is declared as void you always need a return value.
If thats not supposed to be your main function you should rename it so as not to confuse other people, yourself, or your compiler. I'm sure it'd spew an error on two functions with the same name, regardless of their type, anyway.
Last edited on Jan 7, 2009 at 3:49pm
Topic archived. No new replies allowed.