Hướng dẫn initialize complex number c++ - khởi tạo số phức c ++

Nhận cuốn sách này -> Vấn đề về Array: Đối với các cuộc phỏng vấn và lập trình cạnh tranh

Nội dung chính ShowShow

  • Biểu diễn các số phức trong c
  • Đại diện cho số phức tạp sử dụng cấu trúc
  • Đại diện cho các số phức tạp bằng thư viện
  • Hoạt động trên các số phức tạp
  • Bổ sung hai số phức [sử dụng cấu trúc]
  • Bổ sung hai số phức [sử dụng thư viện]
  • Phép trừ hai số phức [sử dụng cấu trúc]
  • Phép trừ hai số phức [sử dụng thư viện]
  • Phép nhân hai số phức [sử dụng cấu trúc]
  • Phép nhân hai số phức [sử dụng thư viện]

Một số phức là một số có thể được viết trong Mẫu X+Yi trong đó X và Y là số thực và tôi là một số tưởng tượng.

  • Do đó, một số phức là sự kết hợp của:
  • số thực.
  • số tưởng tượng.

Example:

6+2i    //here i=√-1
        //6 is real part and 2i is imaginary

Biểu diễn các số phức trong c

Đại diện cho số phức tạp sử dụng cấu trúc

Đại diện cho các số phức tạp bằng thư viện

Hoạt động trên các số phức tạpstructure, a C feature
II]
#include
2 library

Đại diện cho số phức tạp sử dụng cấu trúc

Đại diện cho các số phức tạp bằng thư viện

Example:

struct complex
{
    int real, imag; 
};

Hoạt động trên các số phức tạp
real is variable to hold the real part and imag is a variable to hold the imaginary part.
real and imag can be of any data type [int, float, double].

Đại diện cho các số phức tạp bằng thư viện

Hoạt động trên các số phức tạp

#include

Bổ sung hai số phức [sử dụng cấu trúc]
Depending on type of x and y there are three data types in C for complex numbers:
-double complex
-float complex
-long double complex
Example of initialization of complex numbers:

double complex c1=5.0+2.0*I;   //I is imaginary part
double complex c2=7.0-5.0*I;

Bổ sung hai số phức [sử dụng thư viện]exponential functions, power functions, trigonometric functions, and some manipulation function.

**Manipulation functions**
  creal[] :computes the real part of the funtion.
  crealf[]     //for float
  creall[]     //for long double.

  cimag[] :computes the imaginary part of the function.
  cimagf[]     //for float
  cimagl[]     //for long double

**Exponential functions**
  cexp[] :computes the complex base-e exponential
  cexpf[]      //for float
  cexpl[]      //for double

**Trigonometric functions**
  csin[] :computes the complex sine
  csinf[]      //for float
  csinl[]      //for double

  ccos[] :computes the complex cosine
  ccosf[]      //for float
  ccosl[]      //for double
  
  ctan[] :computes the complex tangent
  ctanf[]      //for float
  ctanl[]      //for double
  
  casin[] :computes the complex arc sine
  casinf[]    //for float
  casinl[]    //for double

  cacos[] :computes the complex arc cosine
  cacosf[]    //for float
  cacosl[]    //for double
  
  catan[] :computes the complex arc tangent
  catanf[]    //for float
  catanl[]    //for double
  
**Power function**
  cpow[] :computes the complex power function
  cpowf[]     //for float
  cpowl[]     //for double
  
  csqrt[] :computes the complex square root
  csqrtf[]    //for float
  csqrtl[]    //for double

Hoạt động trên các số phức tạp

Bổ sung hai số phức [sử dụng cấu trúc]

Bổ sung hai số phức [sử dụng thư viện]
Here we will use structure to store a complex number.

#include        //standard input output library
struct complex           //structure for coplex number
{
	double real,imag;     //variables holding real and imaginary part of type double
};
int main[]
{
	struct complex x,y,c;
	printf["enter the value of x and y for first complex number: "];
	scanf["%lf%lf",&x.real, &x.imag];
	printf["enter the value of x and y for second complex number: "];
	scanf["%lf%lf",&y.real, &y.imag];
	c.real=x.real+y.real;     //addition of real part
	c.imag=x.imag+y.imag;     //addition of imaginary part
	printf["Sum of complex numbers: %.2lf%+.2lfi",c.real,c.imag];
	return 0;
}

OUTPUT:

enter the value of x and y for first complex number: 4 6
enter the value of x and y for second complex number: 2 3
Sum of complex numbers: 6.00+9.00i

Bổ sung hai số phức [sử dụng thư viện]

Phép trừ hai số phức [sử dụng cấu trúc] library.
In this we will compute the real part and imaginary part of the function using creal[] and cimag[] functions respectively.

#include       //standard input output library
#include     //standard complex number library

int main[] {

    double complex c1=5.0+3.0*I;     //declaration of a complex number 
    double complex c2=7.0-4.0*I;
    printf["Addition of complex numbers:\n"];
    printf["values of complex number c1:c1=%.2lf+%.2lfi\n", creal[c1], cimag[c1]];   //computing real and imaginary part of c1
    printf["values of complex number c2:c2=%.2lf+%.2lfi\n", creal[c2], cimag[c2]];   //computing real and imaginary part of c2
    double complex sum =c1+c2;
    printf["The sum: c1+c2= %.2lf%+.2lfi\n", creal[sum], cimag[sum]];
    return 0;
}

OUTPUT:

Phép trừ hai số phức [sử dụng thư viện]

Phép trừ hai số phức [sử dụng cấu trúc]

Phép trừ hai số phức [sử dụng thư viện]
Here we will use structure to store a complex number.

#include
1

OUTPUT:

struct complex
{
    int real, imag; 
};
0

Phép trừ hai số phức [sử dụng thư viện]

Phép nhân hai số phức [sử dụng cấu trúc] library.
In this we will compute the real part and imaginary part of the function using creal[] and cimag[] functions respectively.

struct complex
{
    int real, imag; 
};
1

OUTPUT:

struct complex
{
    int real, imag; 
};
2

Phép nhân hai số phức [sử dụng cấu trúc]

Phép nhân hai số phức [sử dụng thư viện]
Here we will use structure to store a complex number.

struct complex
{
    int real, imag; 
};
3
struct complex
{
    int real, imag; 
};
4

OUTPUT:

struct complex
{
    int real, imag; 
};
5

Phép nhân hai số phức [sử dụng thư viện]

Một số phức là một số có thể được viết trong Mẫu X+Yi trong đó X và Y là số thực và tôi là một số tưởng tượng. library.
In this we will compute the real part and imaginary part of the function using creal[] and cimag[] functions respectively.

struct complex
{
    int real, imag; 
};
6

OUTPUT:

struct complex
{
    int real, imag; 
};
7

Do đó, một số phức là sự kết hợp của:

struct complex
{
    int real, imag; 
};
8

OUTPUT:

struct complex
{
    int real, imag; 
};
9

số thực.

#include
0

OUTPUT:

#include
1

Bài Viết Liên Quan

Chủ Đề