Computational Physics - Department of Physics

(Axel Boer) #1

6.8 Exercises 205


// inline int Array::dim()const{return ndim;}


/**/
/ IMPLEMENTATION OF FRIEND FUNCTIONS /
/**/


/**/
/ (Arithmetic) Unary operators /
/**/
//! Unary operator +
template
inlineArrayoperator+(constArray& v){// u = + v
returnv;
}


//! Unary operator -
template
inlineArrayoperator-(constArray& v){// u = - v
returnArray(v.size[0],v.size[1]) -v;
}


//! Postmultiplication operator
template
inlineArrayoperator(constArray& v,doublescalar){// u = va
returnArray(v)*= scalar;
}


//! Premultiplication operator.
template
inlineArrayoperator(doublescalar,constArray& v){// u = av
returnv*scalar;// Note the call to postmultiplication operator defined above
}


//! Division of the entries in a array by a scalar
template
inlineArrayoperator/(constArray& v,doublescalar){
if(!scalar) std::cout <<"Division by zero!"<< std::endl;
return(1.0/scalar)*v;
}


#endif


6.8 Exercises.


6.1.The aim of this exercise is to write your own Gaussian elimination code.



  1. Consider the linear system of equations


a 11 x 1 +a 12 x 2 +a 13 x 3 =w 1
a 21 x 1 +a 22 x 2 +a 23 x 3 =w 2
a 31 x 1 +a 32 x 2 +a 33 x 3 =w 3.
Free download pdf