📄 complex.cpp
字号:
#include "stdafx.h"
ComplexNumber ComplexMultiply(ComplexNumber x, ComplexNumber y)
//
// Copyright 2002 The Mobile and Portable Radio Research Group
//
{
ComplexNumber Result;
Result.real = x.real * y.real - x.imaginary * y.imaginary;
Result.imaginary = x.real * y.imaginary + x.imaginary * y.real;
return(Result);
}
ComplexNumber ComplexAdd(ComplexNumber x, ComplexNumber y)
//
// Copyright 2002 The Mobile and Portable Radio Research Group
//
{
ComplexNumber Result;
Result.real = x.real + y.real;
Result.imaginary = x.imaginary + y.imaginary;
return(Result);
}
ComplexNumber ComplexSubtract(ComplexNumber x, ComplexNumber y)
//
// Copyright 2002 The Mobile and Portable Radio Research Group
//
{
ComplexNumber Result;
Result.real = x.real - y.real;
Result.imaginary = x.imaginary - y.imaginary;
return(Result);
}
ComplexNumber ComplexRealMultiply(double x, ComplexNumber y)
//
// Copyright 2002 The Mobile and Portable Radio Research Group
//
{
ComplexNumber Result;
Result.real = x * y.real;
Result.imaginary = x * y.imaginary;
return(Result);
}
double ComplexEnergy(ComplexNumber x)
//
// Copyright 2002 The Mobile and Portable Radio Research Group
//
{
double Result;
Result = (x.real * x.real) + (x.imaginary * x.imaginary);
return(Result);
}
ComplexNumber ComplexDivide(ComplexNumber top, ComplexNumber bottom)
//
// Copyright 2002 The Mobile and Portable Radio Research Group
//
{
ComplexNumber Result;
double r,den;
if (fabs(bottom.real) >= fabs(bottom.imaginary))
{
r = bottom.imaginary / bottom.real;
den = bottom.real + r * bottom.imaginary;
Result.real = (top.real + r * top.imaginary) / den;
Result.imaginary = (top.imaginary - r * top.real) / den;
}
else
{
r = bottom.real / bottom.imaginary;
den = bottom.imaginary + r * bottom.real;
Result.real = (top.real * r + top.imaginary) / den;
Result.imaginary = (top.imaginary * r - top.real) / den;
}
return(Result);
}
ComplexNumber ComplexRealDivide(ComplexNumber top,double bottom)
//
// Copyright 2002 The Mobile and Portable Radio Research Group
//
{
ComplexNumber Result;
Result.real = top.real / bottom;
Result.imaginary = top.imaginary / bottom;
return(Result);
}
ComplexNumber Conjugate(ComplexNumber a)
//
// Copyright 2002 The Mobile and Portable Radio Research Group
//
{
ComplexNumber Result;
Result.real = a.real;
Result.imaginary = -a.imaginary;
return(Result);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -