C语言实现复数矩阵

happyhappywdq 2011-05-26 11:11:27
请教高手,用C语言怎么实现复数矩阵,在VC6.0环境下可以运行,谢谢了,急!
...全文
614 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
飞天御剑流 2011-05-27
  • 打赏
  • 举报
回复
先实现一个complex ADT,然后用complex的数组实现complex matrix。
kerbcurb 2011-05-27
  • 打赏
  • 举报
回复
complex<float> **M;
或者:
complex<float> M[ROW][COL]
也就是复数的二维数组
happyhappywdq 2011-05-27
  • 打赏
  • 举报
回复
有高手可以详细些的吗?最好能有一个小例子,谢谢了
happyhappywdq 2011-05-27
  • 打赏
  • 举报
回复
我定义了结构体,但是最后生成的复数矩阵不是完全正确,我的程序是先产生二进制数据流,然后进行计算,得到了实部和虚部的所有数值,就是生成的复数矩阵不正确,不知道为什么?谢谢了!请高手看程序哪里有问题?谢谢了,下面是我的程序
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#define np 8
#define hang M
#define li 8
const int bit=2;
const int M=12;//行数
const int N=56;//列数
const float s=1.414;
typedef struct
{
float real[1][M*N];
float image[1][M*N];

}complex ;

void main()
{
int c[1][M*N*bit];
float a[1][M*N];
//float X1.real[m][n];
//float X1.image[m][n]
int g[hang][N];
float h[hang][N],q[hang][N];
//float X1;
complex X1;
srand( time(0) ); //初始种子
//cha ru
printf("生成1行1344列的随机序列c :\n");
int m=0;

for(int n=0;n<M*N*bit;n++)
{
//if(j%9==0)
//c[i][j]=1;
//else
c[m][n]=(rand() % 2);
}


//for( n=0;n<M*N*bit;n++)
// {
//printf("%d ",c[m][n]);
//}
// printf("\n");

//printf("\n");
//QPSK调制
for( n=0;n<M*N*bit;n++)
{

a[m][n]=(float)(c[m][n]*2-1)/s;
}


for( n=0;n<M*N*bit;n++)
{
printf("%3.3f ",a[m][n]);
}
printf("\n");
for( n=0;n<M*N*bit;)
{

X1.real[m][n]=a[m][n];
n=n+2;
}


for( n=0;n<M*N*bit;)
{
printf("%3.3f ",X1.real[m][n]);
n=n+2;
}
printf("\n");
for( n=1;n<M*N*bit;)
{

X1.image[m][n]=a[m][n];
n=n+2;
}


for( n=1;n<M*N*bit;)
{
printf("%3.3f ",X1.image[m][n]);
n=n+2;
}
printf("\n");//生成虚部
for( n=0;n<M*N;n++)
{if(X1.image[m][n]>0)
printf("X1=%8.3f+%8.3fi\n",X1.real[m][n],X1.image[m][n]);
printf("\n");
if(X1.image[m][n]<0)
printf("X1=%8.3f%8.3fi\n",X1.real[m][n],X1.image[m][n]);
printf("\n");
}


/*for( n=0;n<M*N;n++)
{
printf("%3.3f ",X[m][n]);
}*/
printf("\n");

}
AnYidan 2011-05-27
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 jqctop1 的回复:]
引用 1 楼 supermegaboy 的回复:
先实现一个complex ADT,然后用complex的数组实现complex matrix。


定义一个结构体,包括实部和虚部,然后用结构体数组实现呗
[/Quote]

就是如此
有点笨 2011-05-27
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 supermegaboy 的回复:]
先实现一个complex ADT,然后用complex的数组实现complex matrix。
[/Quote]

定义一个结构体,包括实部和虚部,然后用结构体数组实现呗
如此美丽的你 2011-05-27
  • 打赏
  • 举报
回复
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#define np 8
#define hang M
#define li 8
const int bit=2;
const int M=12;//行数
const int N=56;//列数
const float s=1.414;
typedef struct
{
float real[1][M*N];
float image[1][M*N];

}complex ;

void main()
{
int c[1][M*N*bit];
float a[1][M*N];
//float X1.real[m][n];
//float X1.image[m][n]
int g[hang][N];
float h[hang][N],q[hang][N];
//float X1;
complex X1;
srand( time(0) ); //初始种子
//cha ru
printf("生成1行1344列的随机序列c :\n");
int m=0;

for(int n=0;n<M*N*bit;n++)
{
//if(j%9==0)
//c[i][j]=1;
//else
c[m][n]=(rand() % 2);
}


//for( n=0;n<M*N*bit;n++)
// {
//printf("%d ",c[m][n]);
//}
// printf("\n");

//printf("\n");
//QPSK调制
for( n=0;n<M*N*bit;n++)
{

a[m][n]=(float)(c[m][n]*2-1)/s;
}


for( n=0;n<M*N*bit;n++)
{
printf("%3.3f ",a[m][n]);
}
printf("\n");
for( n=0;n<M*N*bit;)
{

X1.real[m][n]=a[m][n];
n=n+2;
}


for( n=0;n<M*N*bit;)
{
printf("%3.3f ",X1.real[m][n]);
n=n+2;
}
printf("\n");
for( n=1;n<M*N*bit;)
{

X1.image[m][n]=a[m][n];
n=n+2;
}


for( n=1;n<M*N*bit;)
{
printf("%3.3f ",X1.image[m][n]);
n=n+2;
}
printf("\n");//生成虚部
for( n=0;n<M*N;n++)
{if(X1.image[m][n]>0)
printf("X1=%8.3f+%8.3fi\n",X1.real[m][n],X1.image[m][n]);
printf("\n");
if(X1.image[m][n]<0)
printf("X1=%8.3f%8.3fi\n",X1.real[m][n],X1.image[m][n]);
printf("\n");
}


/*for( n=0;n<M*N;n++)
{
printf("%3.3f ",X[m][n]);
}*/
printf("\n");

}

69,336

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧