设为首页 加入收藏

TOP

实现解一元二次方程(循环)(二)
2018-10-21 20:09:18 】 浏览:381
Tags:实现 一元二次方程 循环
complex roots.
 *       i1, i2  ---- the image part of the complex roots.
 *  RET: the status of the equation.
 *       0 ---- no solution.
 *       1 ---- one real root.
 *       2 ---- two real root.
 *       3 ---- has an arbitrary solution.
 *       4 ---- has a pair of conjugate complex roots.
 */
int eqution1(float a, float b, float c, float* r1, float* r2, float* image)
{
    return 0;
}

/*
 *    The function to caculate a Real coefficient eqution's(ax^2+bx+c=0) root.
 *  IN:  a,b,c   ---- the three real coefficient,
 *  OUT: r1, r2  ---- the two real roots or the real part of the complex roots.
 *       i1, i2  ---- the image part of the complex roots.
 *  RET: the status of the equation.
 *         0 ---- no solution.
 *       1 ---- one real root.
 *       2 ---- two real root.
 *       3 ---- has an arbitrary solution.
 *       4 ---- has a pair of conjugate complex roots.
 */
int equation2(float a, float b, float c, float& r1, float& r2, float& i1, float& i2)
{
    int s;
    double delta;
    if (0==a){
        if(0==b){
            if(0==c){
                s= 3;
            }
            else{
                s=0;
            }
        }
        else{
            r1=-c/b;
            s=1;
        }
    }
    else
    {
        delta=b*b-4.0f*a*c;
        if(delta>=-FLT_EPSILON && delta<=FLT_EPSILON)        // delta==0
        {
            r1=r2=-b/2.0f/a;
            s=1;
        }
        else if(delta>FLT_EPSILON){                            // delta>0
            r1=-b/2.0f/a+(float)sqrt(delta);
            r2=-b/2.0f/a-(float)sqrt(delta);
            s=2;
 &n
首页 上一页 1 2 3 下一页 尾页 2/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇串口实现FIFO接受数据(V2) 下一篇动态规划(DP)入门之-------最长..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目