【问题标题】:Negative complex exponentiation负复数幂
【发布时间】:2021-03-01 11:21:07
【问题描述】:

我想计算复数角度和大小,我很擅长

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

double pi = 4 * atan(1.0);

int main() {
    double complex z = cexp(I * -1 * pi * 1.2 - 1);
    printf("%f + %f * i\n", creal(z), cimag(z));

    double complex base = clog(z);
    printf("%f + %f * i\n", creal(base), cimag(base));
 
    double arg = carg(base);
    printf(" Angle of z in radian %f and as degree %f \n", arg, arg * 180 / pi);

    double magnitude = cabs(base);
    printf("Magnitude of z %f \n", magnitude);

    return 0;
}

这个程序打印

-0.297621 + 0.216234 * i
-1.000000 + 2.513274 * i
 Angle of z in radian 1.949480 and as degree 111.696984 
Magnitude of z 2.704912

但是,这个结果没有负虚部。 但所有复数都有正数。 如何获得复平面第三象限的值?

【问题讨论】:

  • 你期望什么输出? Edit你的问题。
  • double pi = 4 * atan(1.0); 全局空间中的 C 代码无效。 maxemilian,你用的是什么 C 编译器?
  • @Jabberwocky 我希望在第三象限或第四象限区域有任何值。我需要负虚部来判断天气是否有效
  • @chux-ReinstateMonica Code OSS(VS code)基于Linux下的GCC
  • @chux-ReinstateMonica 是的,通常会给出错误,但在 "-lm" 文件中的 "${fileDirname}/${fileBasenameNoExtension}", 之后尝试 "${fileDirname}/${fileBasenameNoExtension}", 这一行。同样,gcc -lm filename.c

标签: c complex-numbers


【解决方案1】:

看看cexp(I * -1*pi*1.2-1)。 角度为-1.2*pi,相当于-1.2pi + 2*pi = 0.8pi。这个角度指向第二象限,实部为负,虚部为

0.8 * pi ~= 2.51327412287

与您的示例中的 clog(z) 值一样。 一切正常。正角变为负角的一些直观解释如下:

向右转 200 度将使您处于与向右转 -160 度相同的方向。

要获得第三象限中的数字,角度必须在 (pi ... 1.5 pi) 加上 2kpi 之间,其中 k 是任意整数。试试 1.2 * pi。

-0.297621 + -0.216234 * i
-1.000000 + -2.513274 * i
 Angle of z in radian -1.949480 and as degree -111.696984 
Magnitude of z 2.704912 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-09-06
    • 2011-12-31
    • 2017-12-03
    • 1970-01-01
    • 2012-02-10
    • 1970-01-01
    • 2018-09-08
    相关资源
    最近更新 更多