由于C#没有提供复数(Complex)的运算类库,复数类需要自己定义。
我们主要呈现了两个类,Complex,并做了一个MathX,将三角函数、指对函数等拓展到复数域。
| Complex(double re, double im) | 复数类构造函数 |
| ! | 共轭运算符,返回共轭 |
| +-*/ | 四则运算符 |
| Arg() Modulus() ModulusSqure() | 幅角,模长,模长平方 |
| Complex(double a) | 强制类型转换运算符 |
| Exp | 自然指数函数 |
| Log | 自然对数函数,指定底数对数函数 |
| Sin | 正弦 |
| Cos | 余弦 |
| Tan | 正切 |
| Cot | 余切 |
| Csc | 正割 |
| Sec | 余割 |
| Pow | 指数函数 |
| Acos | 反余弦 |
| Asin | 反正弦 |
| Atan | 反正切 |
| Sqrt | 平方根 |
MathX类的成员函数都是静态的,参数和返回值都是复数。
/// <summary>
/// 常数
/// </summary>
public class Constants
{
/// <summary>
/// 圆周率π
/// </summary>
public const double π = 3.1415926536;
/// <summary>
/// 自然底数e
/// </summary>
public const double e = 2.71828182846;
/// <summary>
/// 欧拉常数γ
/// </summary>
public const double γ = 0.5772156649;
/// <summary>
/// 混沌常数δ
/// </summary>
public const double δ = 4.6692016091;
}
/// <summary>
/// 复数类型
/// </summary>
public struct Complex
{
public double Re

本文介绍了如何在C#中自定义复数(Complex)运算类库,包括一个名为MathX的静态类,该类将三角函数、指数与对数等数学运算扩展到复数域。文章旨在解决C#标准库中缺失复数运算的问题,并欢迎读者指出可能存在的错误。
最低0.47元/天 解锁文章
368

被折叠的 条评论
为什么被折叠?



