复数类n次方原理以及C#代码实现

完整代码下载https://download.csdn.net/download/u012737193/10359608

我们这里将复数类表示为complx = real + imag * i

那么要如何计算complex ^ n呢,这里的n是double类型,可以是任何数

首先进行如下转换


因此complex = r *(cos(mu)+ sin(mu)*i) = r*(e ^ (mu * i))(欧拉公式)

因此complex ^ n = (r^ n) * (e ^ (mu * n * i))

因此r2 = r ^ n ,mu2 = mu * n

real2 = r2 * cos(mu2) = (r ^ n) *cos(mu *n)

imag2 = r2 * cos(mu2) = (r ^ n) *sin(mu *n)

complex2 = complex ^ n = real2 + imag2 * i

至此得到结果complex类C#的实现如下

  classcomplex

    {

        double imag_;

double real_;

        double r()

        {

            return  Math.Sqrt(Math.Pow(imag_, 2) + Math.Pow(real_, 2));

        }

        double mu()

        {

            returnMath.Atan2(imag_, real_);

        }

        public complex()

        {

            this.imag_ = 0;

            this.real_ = 0;

        }

        public complex(double real,double imag)

        {

            this.imag_ = imag;

            this.real_ = real;

        }

        publicdouble imag()

        {

            return imag_;

        }

        publicdouble real()

        {

            return real_;

        }

        publiccomplex Pow(double comp)

        {

            double ther = r();

            double sita = mu();

            double R = Math.Pow(ther, comp) * Math.Cos(comp * sita);

            double I = Math.Pow(ther, comp) * Math.Sin(comp * sita);

            real_ = R;

            imag_ = I;

            return this;

        }

        //^的重载

        public static complex operator ^(complex z1, double z2)

        {

            return (z1.Pow(z2));

        }

    }

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值