C++解決二元二次方程组

本文介绍了如何利用C++编程语言,结合Eigen库来解决二元二次方程组。首先提供了Eigen库的下载链接,接着讨论了一元四次、一元三次和一元二次方程的求解方法。参考了两篇相关技术文章以供深入学习。
摘要由CSDN通过智能技术生成

要配置一个库Eigen库
链接:https://pan.baidu.com/s/1AofB13zldSq1fT_lKMGf6g
提取码:wqcc

#include <iostream>
#include <Eigen/Core>
#include <Eigen/Dense>
#include <complex>
#include <cmath>
#include <math.h>
#include <cfloat>
#include<opencv2\opencv.hpp>
using namespace std;
using namespace cv;
double real_x1 = 0.0;
double real_x2 = 0.0;
double real_x3 = 0.0;
double imag_y1 = 0.0;
double imag_y2 = 0.0;
double imag_y3 = 0.0;
int sign = 0;

int one_three(double a, double b, double c, double d);
void one_Two(float a, float b, float c,float C, float E, float D);
void quadratic2quartic(Eigen::Matrix<double, 6, 1>& _par1,
    Eigen::Matrix<double, 6, 1>& _par2,
    Eigen::Matrix<double, 5, 1>& _y2x_par,
    Eigen::Matrix<std::complex<double>, 5, 1>& _quartic_par)
{
   
    double A, B, C, D, E;
    double a1, b1, c1, d1, e1, f1, a2, b2, c2, d2, e2, f2;

    a1 = _par1[0];
    b1 = _par1[1];
    c1 = _par1[2];
    d1 = _par1[3];
    e1 = _par1[4];
    f1 = _par1[5];

    //   std::cout  << a1 << "   " << b1 <<  "   " <<  c1  << "   " << d1 <<  "   " << e1 <<  "   " << f1 << std::endl;

    a2 = _par2[0];
    b2 = _par2[1];
    c2 = _par2[2];
    d2 = _par2[3];
    e2 = _par2[4];
    f2 = _par2[5];

    //   std::cout  << a2 << "   " << b2 <<  "   " <<  c2  << "   " << d2 <<  "   " << e2 <<  "   " << f2 << std::endl;


    A = a1 * c2 - c1 * a2;
    B = b1 * c2 - c1 * b2;
    C = d1 * c2 - c1 * d2;
    D = e1 * c2 - c1 * e2;
    E = f1 * c2 - c1 * f2;
    _y2x_par << A, B, C, D, E;
    //   std::cout << "A-E: \n";
    //   std::cout << A << "   " << B << "   " << C <<"   " << D << "   " << E << std::endl; 

    double M0, M1, M2, M3, M4;
    M4 = a1 * B * B - b1 * A * B + c1 * A * A;
    M3 = 2 * a1 * B * D - b1 * A * D - b1 * B * C + 2 * c1 * A * C + d1 * B * B - e1 * A * B;
    M2 = a1 * D * D - b1 * C * D - b1 * B * E + c1 * C * C + 2 * c1 * A * E + 2 * d1 * B * D - e1 * A * D - e1 * B * C + f1 * B * B;
    M1 = -b1 * D * E + 2 * c1 * C * E + d1 * D * D - e1 * C * D - e1 * B * E + 2 * f1 * B * D;
    M0 = c1 * E * E - e1 * D * E + f1 * D * D;
    //   std::cout << "m4-m0: \n";
    //   std::cout << M4 << "   " << M3 << "   " << M2 << "   " << M1 << "   " << M0 << std::endl;
    //   
  
    // 解一元四次方程
    if (M4!=0.0)
    {
   
        double b, c, d, e;
        b = M3 / M4;
        c = M2 / M4;
        d = M1 / M4;
        e = M0 / M4;
        _quartic_par << 1.0, b, c, d, e;
        sign = 1;
    }
    // 解一元三次方程
    else if (M4 == 0.0&&M3!=0.0)
    {
   
        if (one_three(M3, M2, M1, M0) 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值