⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 complex.cpp

📁 该函数可以实现任意行列数double型矩阵的张量乘积 用数组实现
💻 CPP
字号:
#include"complex.h"
#include"iostream.h"
#include <cmath>

/******************************************************************************
                            以下定义实现复数类的函数
  ****************************************************************************/
complex operator+(complex &c1,complex & c2)//加
{
 return complex(c1.real+c2.real,c1.imag+c2.imag);//前面的complex不能忽略,注意!!!
}

complex operator-(complex &c1,complex & c2)//减
{
return complex(c1.real-c2.real,c1.imag-c2.imag);
}

complex operator*(complex &c1,complex &c2)//乘
{
	return complex(c1.real*c2.real-c1.imag*c2.imag,c1.real*c2.imag+c1.imag*c2.real);
}
 
complex operator/(complex &c1,complex &c2)//除
{
	return complex((c1.real*c2.real-c1.imag*c2.imag)/ sqrt (c2.imag*c2.imag+c2.real*c2.real),(c1.real*c2.imag+c1.imag*c2.real)/ sqrt (c2.imag*c2.imag+c2.real*c2.real));

}

complex operator*(complex &c2,double d)//复数和实数的乘
{
	return complex(d*c2.real,d*c2.imag);
}

void complex::display()//复数显示
{
 cout<<"("<<real<<","<<imag<<"i"<<")";//<<endl;
 
}

complex complex::conjugate()//求复数的共轭
{
  return complex(real,-imag);
}
complex complex::negconjugate()//求复数的负共轭
{
	return complex(-real,imag);
}
void complex::setinitial (double r ,double i)//复数对象的赋值
{
	real=r;
	imag=i;
}

double complex::mod()//复数求模
{
	return((double)sqrt((real*real)+(imag*imag)));
}

/**
void complex:: operator=(complex&c1)
{
	complex c2;
	c2.real=c1.real;
	c2.imag=c1.imag;
}
**/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -