本文整理汇总了C++中ComplexNumber类的典型用法代码示例。如果您正苦于以下问题:C++ ComplexNumber类的具体用法?C++ ComplexNumber怎么用?C++ ComplexNumber使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ComplexNumber类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: reset
void reset(double r1, double i1,ComplexNumber&a, ComplexNumber&c)
{
a.setReal(r1);
a.setImag(i1);
c.setReal(0);
c.setImag(0);
};
示例2: getReal
ComplexNumber ComplexNumber::operator +(const ComplexNumber& other)
{
ComplexNumber c;
c.real = getReal() + other.getReal();
c.imag = getImag() + other.getImag();
return c;
}
示例3: ComplexNumber
ComplexNumber ComplexNumber::operator*(const ComplexNumber& z) const
{
return ComplexNumber(mRealPart * z.GetRealPart()
- mImaginaryPart * z.GetImaginaryPart(),
mImaginaryPart * z.GetRealPart()
+ mRealPart * z.GetImaginaryPart());
}
示例4: if
bool ComplexNumber::operator <(ComplexNumber& other)
{
if(getReal() < other.getReal())
return true;
else if(getReal() == other.getReal())
return (getImag() < other.getImag());
}
示例5: TEST
TEST(Zhiltsov_Max_ComplexNumberTest, LimitingValueAddition_Correct) {
const ComplexNumber z(std::numeric_limits<double>::max(), 0);
ComplexNumber sum = z + z;
EXPECT_TRUE(std::isinf(sum.getRe()));
}
开发者ID:1995konstantin,项目名称:devtools-course-practice-1,代码行数:7,代码来源:test_zhiltsov_max_complex_number.cpp
示例6: exp
ComplexNumber Exponential::eval(const ComplexNumber z) const {
ComplexNumber exponent = lambda * z;
double exp_re = exp(exponent.real()) * cos(exponent.imag());
double exp_im = exp(exponent.real()) * sin(exponent.imag());
ComplexNumber w (exp_re, exp_im);
return coefficient * w;
}
示例7: pow
// Override.
// (r * exp(i * theta))^(a + bi) = r^(a + bi) * exp(i * theta * a - theta * b)
// = (r^a * exp(-theta * b)) * (r^b * exp(theta * a))^i
ComplexNumber Power::eval(const ComplexNumber z) const {
double r = z.mag(), theta = z.angle();
double a = exponent.real(), b = exponent.imag();
double coeff = pow(r, a) * exp(-theta * b);
ComplexNumber w = iPower(pow(r, b) * exp(theta * a));
ComplexNumber v (coeff * w.real(), coeff * w.imag());
return v;
}
示例8: ln_z
// Override.
// ln(z) = ln(|r|) + i * theta, where z = r * e^(i * theta)
// log_z(w) = ln(w) * log_z(e) = ln(w) * 1 / (ln(r) + i * theta), where z = r * e^(i * theta).
ComplexNumber Logarithm::eval(const ComplexNumber z) const {
ComplexNumber argument = z + lambda;
ComplexNumber ln_z (log(argument.mag()), argument.angle());
if (base == exp(1)) {
return coefficient * ln_z;
} else {
ComplexNumber one (1, 0);
ComplexNumber log_base (log(base.mag()), base.angle());
return coefficient * ln_z * (one / log_base);
}
}
示例9:
ComplexNumber operator*( ComplexNumber& first, ComplexNumber& second) {
ComplexNumber c;
double newRe=(first.Re()*second.Re())-(first.Im()*second.Im());
double newIm=(first.Re()*second.Im())+(first.Im()*second.Re());
c.setRe(newRe);
c.setIm(newIm);
return c;
}
示例10: main
int main(){
long real1,imaginary1,real2,imaginary2;
scanf("%ld%ld",&real1,&imaginary1);
ComplexNumber a={real1,imaginary1};
scanf("%ld%ld",&real2,&imaginary2);
ComplexNumber b={real2,imaginary2};
ComplexNumber c;
c.saberi(a,b);
c.oduzmi(a,b);
c.pomnozi(a,b);
c.podeli(a,b);
return 0;
}
示例11: autoReplot
//
// re-calculate frequency response
//
void Plot::setDamp( double damping )
{
const bool doReplot = autoReplot();
setAutoReplot( false );
const int ArraySize = 200;
double frequency[ArraySize];
double amplitude[ArraySize];
double phase[ArraySize];
// build frequency vector with logarithmic division
logSpace( frequency, ArraySize, 0.01, 100 );
int i3 = 1;
double fmax = 1;
double amax = -1000.0;
for ( int i = 0; i < ArraySize; i++ )
{
double f = frequency[i];
const ComplexNumber g =
ComplexNumber( 1.0 ) / ComplexNumber( 1.0 - f * f, 2.0 * damping * f );
amplitude[i] = 20.0 * log10( qSqrt( g.real() * g.real() + g.imag() * g.imag() ) );
phase[i] = qAtan2( g.imag(), g.real() ) * ( 180.0 / M_PI );
if ( ( i3 <= 1 ) && ( amplitude[i] < -3.0 ) )
i3 = i;
if ( amplitude[i] > amax )
{
amax = amplitude[i];
fmax = frequency[i];
}
}
double f3 = frequency[i3] - ( frequency[i3] - frequency[i3 - 1] )
/ ( amplitude[i3] - amplitude[i3 -1] ) * ( amplitude[i3] + 3 );
showPeak( fmax, amax );
show3dB( f3 );
showData( frequency, amplitude, phase, ArraySize );
setAutoReplot( doReplot );
replot();
}
示例12: setAll
ComplexNumber::ComplexNumber(const ComplexNumber& orig) {
setAll(orig.getReal(), orig.m_imag);
}
示例13: add
ComplexNumber ComplexNumber::add(const ComplexNumber& c1,const ComplexNumber& c2){
//std::cout << __PRETTY_FUNCTION__ << std::endl;
ComplexNumber sum = c1;
sum.add(c2);
return sum;
}
示例14:
bool operator==(const ComplexNumber& c1, const ComplexNumber& c2){
if ((c1.Real()==c2.Real())&(c1.Imag()==c2.Imag())) return true;
return false;
}
示例15:
// Checking if not Equal
bool operator!=(const ComplexNumber & lhs, const ComplexNumber & rhs) {
if(lhs.equals(rhs)) return false;
return true;
}