コード例 #1
0
int PolyBase::solveQuadratic(std::complex<double> &AnsA,
                             std::complex<double> &AnsB) const
/**
  Solves Complex Quadratic component.
  compress MUST have been called.
  @param AnsA :: complex roots of the equation
  @param AnsB :: complex roots of the equation
  @return Number of unique solutions
*/
{
  const double b = afCoeff[1];
  const double c = afCoeff[0];

  const double cf = b * b - 4.0 * c;
  if (cf >= 0) /* Real Roots */
  {
    const double q = (b >= 0) ? -0.5 * (b + sqrt(cf)) : -0.5 * (b - sqrt(cf));
    AnsA = std::complex<double>(q, 0.0);
    AnsB = std::complex<double>(c / q, 0.0);
    return (cf == 0) ? 1 : 2;
  }

  std::complex<double> CQ(-0.5 * b,
                          (b >= 0 ? -0.5 * sqrt(-cf) : 0.5 * sqrt(-cf)));
  AnsA = CQ;
  AnsB = c / CQ;
  return 2;
}
コード例 #2
0
ファイル: pr_08_1.c プロジェクト: qnu/mdoch
void CorrectorStepQ ()
{
  real cr[] = {3.,10.,-1.}, cv[] = {7.,6.,-1.}, div = 24., wr, wv;
  int n;

  wr = Sqr (deltaT) / div;
  wv = deltaT / div;
  DO_MOL {
    CQ (u1);
    CQV (u1);
    CQ (u2);
    CQV (u2);
    CQ (u3);
    CQV (u3);
    CQ (u4);
    CQV (u4);
  }
}
コード例 #3
0
 *
 * You should have received a copy of the GNU General Public License
 * along with liquid.  If not, see <http://www.gnu.org/licenses/>.
 */

//
// Complex fixed-point arithmetic
//

#include "liquidfpm.internal.h"

#define CQ(name)            LIQUIDFPM_CONCAT(cq32,name)
#define Q(name)             LIQUIDFPM_CONCAT(q32, name)

// compute a number's complex conjugate
CQ(_t) CQ(_conj)(CQ(_t) _x)
{
    CQ(_t) conj = {_x.real, -_x.imag};
    return conj;
}

// add 2 complex numbers
CQ(_t) CQ(_add)(CQ(_t) _a, CQ(_t) _b)
{
    CQ(_t) sum = {_a.real + _b.real, _a.imag + _b.imag};
    return sum;
}

// subtract 2 complex numbers
CQ(_t) CQ(_sub)(CQ(_t) _a, CQ(_t) _b)
{
コード例 #4
0
ファイル: complex_trig.c プロジェクト: bfdream/liquid-fpm
 *
 * You should have received a copy of the GNU General Public License
 * along with liquid.  If not, see <http://www.gnu.org/licenses/>.
 */

//
// Complex fixed-point trig functions
//

#include "liquidfpm.internal.h"

#define CQ(name)            LIQUIDFPM_CONCAT(cq32,name)
#define Q(name)             LIQUIDFPM_CONCAT(q32, name)

// compute magnitude squared
Q(_t) CQ(_abs2)(CQ(_t) _x)
{
    Q(_t) x2 = Q(_mul)(_x.real,_x.real) +
               Q(_mul)(_x.imag,_x.imag);
    return x2;
}

// compute magnitude
Q(_t) CQ(_abs)(CQ(_t) _x)
{
    unsigned int _n=20; // number of iterations (precision)

    return Q(_sqrt_newton)(CQ(_abs2)(_x), _n);
}

// compute complex sin(x) = (exp(j*x) - exp(-j*x))/(j*2)