叶春勇的个人空间 https://bbs.21ic.com/?2803420 [收藏] [复制] [RSS]

日志

C语言中的复数运算笔记

已有 516 次阅读2021-1-30 16:18 |系统分类:兴趣爱好

#include <stdio.h>
#include <stdlib.h>
#include <complex.h>
#include <math.h>
#include <assert.h>

complex double get_hjw(double r1,double r2,double r3,double c1,double c2,double f)
{
    complex double S_1=I*2*M_PI*f;
    complex double S_2=S_1*S_1;
    double b1=(r1+r2)*r3*c1;
    double b0=r3;
    double a2=r1*r2*r3*c1*c2;
    double a1=r1*r2*c1+r1*r3*c1+r2*r3*c1+r1*r3*c2;
    double a0=r1+r3;
    complex double hs=(b1*S_1+b0)/(a2*S_2+a1*S_1+a0);
    return hs;
}

double get_abs_hjw(double r1,double r2,double r3,double c1,double c2,double f)
{
    complex double hjw=get_hjw(r1,r2,r3,c1,c2,f);
    return cabs(hjw);
}

double get_db(double x)
{
    assert(x>0);
    return 20*log10(x);
}



int main()
{
    printf("%f",get_db(get_abs_hjw(50e3,50e3,50e3,10e-9,6.8e-9,1000)));
    return 0;
}

1、首先#include<complex.h>
2、定义变量方法complex double x
3、基本运算,直接加减乘除
double __MINGW_ATTRIB_CONST creal (double _Complex);
double __MINGW_ATTRIB_CONST cimag (double _Complex);
double __MINGW_ATTRIB_CONST carg (double _Complex);
double __MINGW_ATTRIB_CONST cabs (double _Complex) __MINGW_ATTRIB_DEPRECATED_MSVC2005;

路过

鸡蛋

鲜花

握手

雷人

评论 (0 个评论)