C 庫 - cproj() 函式



C 的複數cproj() 函式用於計算 z(複數)在黎曼球面上的投影。投影是指將點或點集從一個空間對映到另一個空間的對映或變換。

在數學中,黎曼球面是複平面的模型。它將平面上的所有點對映到球面上的點,引入了無窮大作為複函式在無窮大處的行為的表示。

語法

以下是 cproj() 函式的 C 庫語法:

double complex cproj( double complex z );

引數

此函式接受單個引數:

  • Z - 它表示我們要計算其投影的複數。

返回值

此函式返回一個複數值,其型別可以是 double、float 或 long double,表示 z 在黎曼球面上的投影。

示例 1

以下是一個基本的 c 程式,用於演示如何使用複數的 cproj()

#include <stdio.h>
#include <complex.h>
#include <math.h> 
int main()
{
   double complex proj1 = cproj(1 + 2*I);
   printf("cproj(1+2i) = %.1f%+.1fi\n", creal(proj1),cimag(proj1));
   
   double complex proj2 = cproj(INFINITY+2.0*I);
   printf("cproj(Inf+2i) = %.1f%+.1fi\n", creal(proj2),cimag(proj2));
}

輸出

以下是輸出:

cproj(1+2i) = 1.0+2.0i
cproj(Inf+2i) = inf+0.0i

示例 2

讓我們來看另一個例子,我們使用 CMPLX() 建立一個複數。然後我們使用 cproj() 計算複數的投影。

#include <stdio.h>
#include <complex.h>
#include <math.h>
int main()
{
   double real = 3;
   double imag = 4;
   double complex z  = CMPLX(real, imag);
   
   double proj = cproj(z);
   
   printf("Complex number: %.1f + %.1fi\n", creal(z), cimag(z));    
   
   printf("Projection of complex number = %.1f + %.1fi\n", creal(proj),cimag(proj));
}

輸出

以下是輸出:

Complex number: 3.0 + 4.0i
Projection of complex number = 3.0 + 0.0i

示例 3

下面的 c 示例計算負複數的投影。

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

int main(void) {
   double complex z = -3.0 + -4.0*I;

   // find the project of complex number
   double proj = cproj(z);

   printf("Complex number: %.2f + %.2fi\n", creal(z), cimag(z));
   printf("project of complex number: %.2f + %.2fi", creal(proj), creal(proj));
   return 0;
}

輸出

以下是輸出:

Complex number: -3.00 + -4.00i
project of complex number: -3.00 + -3.00i
c_library_complex_h.htm
廣告
© . All rights reserved.