solution of tridiagonal matrix

//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
...what error?
<T> main()
try changing the above to int main()
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
Topic archived. No new replies allowed.