{
vect=NULL;
n=0;
}
//--------------------------------------------------------VECTOR::VECTOR(long ammount)
{
n=ammount;
vect=(double*)calloc(n,sizeof(double));
}
//--------------------------------------------------------VECTOR::VECTOR(const VECTOR &a)
{
n=a.n;
vect=(double*)calloc(n,sizeof(double));
for(long i=0;i<n;i++)
vect[i]=a.vect[i];
}
//--------------------------------------------------------VECTOR::~VECTOR()
{
if(vect!=NULL) {free(vect);n=0;}
}
//--------------------------------------------------------VECTOR VECTOR::operator=(VECTOR ob2)
{
if(vect!=NULL&&n!=ob2.n){free(vect);}
if(vect==NULL)
{
n=ob2.n;
vect=(double*)calloc(n,sizeof(double));
}
for(long i=0;i<n;i++)
vect[i]=ob2.vect[i];
return *this;
}
//--------------------------------------------------------VECTOR VECTOR::operator+(VECTOR ob2)
{
if(n==ob2.n)
{
VECTOR temp(n);
for(long i=0;i<n;i++)
temp.vect[i]=vect[i]+ob2.vect[i];
return temp;
}
printf("Error in operator +\n");
return NULL;
}
//---------------------------------------------------------VECTOR VECTOR::operator-(VECTOR ob2)
{
if(n==ob2.n)
{
VECTOR temp(n);
for(long i=0;i<n;i++)
temp.vect[i]=vect[i]-ob2.vect[i];
return temp;
}
printf("Error in operator +\n");
return NULL;
}
//----------------------------------------------------------VECTOR operator*(double a,VECTOR my)
{
VECTOR temp(my.n);
for(long i=0;i<my.n;i++)
temp.vect[i]=a*my.vect[i];
return temp;
}
//-------------------------------------------------double VECTOR::operator*(VECTOR ob2)
{
double temp=0;
if(n!=ob2.n) {printf ("ERROR IN VECTOR*VECTOR\n"); return 0;}
else
{
for(long i=0;i<n;i++) temp+=vect[i]*ob2.vect[i];
return temp;
}
}
//---------------------------------------------------------VECTOR operator*(MATRIX m,VECTOR v)
{
if(m.n!=v.n)
{
printf("Error in operator MATRIX*VECTOR\n");
return NULL;
}
VECTOR temp(m.n);
long i;
for(i=0;i<temp.n;i++)
temp.vect[i]=m.d[i]*v.vect[i];
for(i=0;i<temp.n;i++)
for(long j=m.ig[i];j<m.ig[i+1];j++)
{
temp.vect[i]+=m.gg[j-1]*v.vect[m.jg[j-1]-1];
temp.vect[m.jg[j-1]-1]+=m.gg[j-1]*v.vect[i];
}
return temp;
}
//----------------------------------------------------------double VECTOR::norm()
{
double a=0;
for(long i=0;i<n;i++)
a+=vect[i]*vect[i];
return sqrt(a);
}
//----------------------------------------------------------void VECTOR::cp_mas(double *mas,long ammount)
{
if(vect!=NULL) free(vect);
n=ammount;
vect=(double*)calloc(n,sizeof(double));
for(long i=0;i<n;i++)
vect[i]=mas[i];
}
//----------------------------------------------------------void VECTOR::call_memory(long ammount)
{
if(vect!=NULL) free(vect);
n=ammount;
vect=NULL;
vect=(double*)calloc(n,sizeof(double));
}
//----------------------------------------------------------void VECTOR::ins_el(double a,long pos)
{
if(pos>=n) printf("Error in insert VECTOR");
else
vect[pos]=a;
}
//----------------------------------------------------------void VECTOR::add_el(double a,long pos)
{
if(pos>=n) printf("Error in add_el VECTOR");
else
vect[pos]+=a;
}
//----------------------------------------------------------void VECTOR::ins_el_all(double a)
{
for(long i=0;i<n;i++)
vect[i]=a;
}
//----------------------------------------------------------double VECTOR::get_el(long pos)
{
if(pos>=n) {printf("Error in get_el VECTOR");return NULL;}
else
return vect[pos];
}
//----------------------------------------------------------void VECTOR::print_vect()
{
for(long i=0;i<n;i++)
printf("%5.3lf ",vect[i]);
printf("\n");
}
void VECTOR::print_vect(char *str)
{
FILE *s=fopen(str,"w");
for(long i=0;i<n;i++)
fprintf(s,"%5.3e\n",vect[i]);
fprintf(s,"\n");
fclose(s);
}
//-------------function of MATRIX+SLAU----------------------MATRIX::MATRIX()
{d=NULL;ig=NULL;jg=NULL,gg=NULL;n=0;}
//---------------------------------------------------------MATRIX::MATRIX(const MATRIX &a)
{
n=a.n;
d=(double*)calloc(n,sizeof(double));
for(long i=0;i<n;i++)
d[i]=a.d[i];
Уважаемый посетитель!
Чтобы распечатать файл, скачайте его (в формате Word).
Ссылка на скачивание - внизу страницы.