home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Simtel MSDOS 1992 June
/
SIMTEL_0692.cdr
/
msdos
/
microcrn
/
issue_40.arc
/
DAIMS.ARC
/
CHEB_VEC.CPP
< prev
next >
Wrap
Text File
|
1988-02-10
|
3KB
|
146 lines
#include <math.h>
#include "matrix.hxx"
#include "vimatrix.hxx"
#include "Cheb_vector.hxx"
double Cheb_vector::dx() { return 2/(size()-1);}
/* phys space range is from -1 to 1 */
/*
-*++ Cheb_vector::physical(): transforms a Chebyshev vector into physical space
**
** (*++ history:
** 17 Dec 87 Bruce Eckel Creation date
** ++*)
**
** (*++ detailed:
** ++*)
*/
phys_vector & Cheb_vector::physical()
{
int mode = 1;
phys_vector & physical_rep = *new phys_vector(size(),-1);
double fact = M_PI * mode / size();
for (int i = 0; i < size(); i++) {
double X = cos( ((double)i + 0.5) * fact);
double summation = 0;
for (int n = 0; n < size(); n++)
summation += (*this)[n] * T(n,X);
physical_rep[i] = summation;
}
return physical_rep;
}
/*
-*++ Cheb_vector::prime(): Returns the first derivative of a Cheb_vector
**
** (*++ history:
** 17 Dec 87 Bruce Eckel Creation date
** ++*)
**
** (*++ detailed:
** ++*)
*/
Cheb_vector & Cheb_vector::prime()
{
Cheb_vector & deriv = *new Cheb_vector(size(),-1);
for (int n = 0; n < size(); n++) {
double summation = 0;
for (int p = n+1; p < size(); p++)
if ((p+n)%2) /* if p+n is odd, we get a remainder */
summation += p * (*this)[p];
deriv[n] = 2.0*summation/C(n);
summation = 0;
}
return deriv;
}
/*
-*++ phys_vector::Chebyshev(): Transform to Chebyshev space
**
** (*++ history:
** 17 Dec 87 Bruce Eckel Creation date
** ++*)
**
** (*++ detailed:
** ++*)
*/
Cheb_vector & phys_vector::Chebyshev()
{
Cheb_vector & cheb = *new Cheb_vector(size(),-1);
for (int mode = 0; mode < size(); mode++) {
double fact = M_PI * mode / size();
double sum = 0;
for ( int i = 0; i < size(); i++)
sum += (*this)[i] * cos( ((double)i + 0.5) * fact);
cheb[mode] = 2 * sum/size();
}
return cheb;
}
/*
-*++ Cheb_vector::operator+(): function for Chebyshev vector addition
**
** (*++ history:
** 15 Jan 88 Bruce Eckel Creation date
** ++*)
**
** (*++ detailed:
** ++*)
*/
Cheb_vector & Cheb_vector::operator+(Cheb_vector & arg)
{
if(size() != arg.size())
error("Cheb_vectors must be same size to add!");
Cheb_vector & sum = *new Cheb_vector(size(),0);
for(int i = 0; i < size(); i++)
sum[i] = (*this)[i] + arg[i];
return sum;
}
/*
-*++ Cheb_vector::operator-(): vector subtraction
**
** (*++ history:
** 16 Jan 88 Bruce & Creation date
** ++*)
**
** (*++ detailed:
** ++*)
*/
Cheb_vector & Cheb_vector::operator-(Cheb_vector & arg)
{
if(size() != arg.size())
error("Cheb_vectors must be same size to subtract!");
Cheb_vector & sum = *new Cheb_vector(size(),0);
for(int i = 0; i < size(); i++)
sum[i] = (*this)[i] - arg[i];
return sum;
}
/*
-*++ Cheb_vector::operator*(): multiply a Cheb_vector by a double
**
** (*++ history:
** 16 Jan 88 Bruce & Creation date
** ++*)
**
** (*++ detailed:
** ++*)
*/
Cheb_vector & Cheb_vector::operator*(double & arg)
{
Cheb_vector & result = *new Cheb_vector(size(),0);
for(int i = 0; i < size(); i++)
result[i] = (*this)[i] * arg;
return result;
}