📄 利用卷积运算求两多项式相乘的c语言代码.txt
字号:
利用卷积运算求两多项式相乘的C语言代码[原创]
卷积运算主要步骤是翻转、移位、相乘、相加。
设有两个多项式(9x2+9x+9)*(9x2+9x+9),利用卷积运算过程如下:
1) 9x2+9x +9
9+9x +9x2 ==>81x4 垂直对应位相乘,然后把水平位置的乘积相加
2) 9x2+9x +9
9+9x +9x2 ==>162x3
3) 9x2+9x +9
9 +9x +9x2 ==>243x2
4) 9x2+9x +9
9 +9x +9x2 ==>162x
5) 9x2+9x +9
9 +9x +9x2 ==>81
C语言代码如下:
#i nclude <conio.h>
#i nclude <stdlib.h>
void juanji(int x[],int y[],int z[],int n,int m)
{
int i,j;
for(i=0;i<=n+m;i++)
{
int t=0;
for(j=0;j<=n;j++)
if(i-j>=0&&i-j<=m)
t+=x[j]*y[i-j];
z[i]=t;
}
}
void output(int array[],int n)
{
int i,j;
j=n;
printf("\n");
for(i=0;i<n;i++)
printf("%dx^%d+",array[i],j--);
printf("%d\n",array[i]);
}
void main()
{
int x[3]={9,9,9},y[3]={9,9,9},z[5];
int i;
juanji(x,y,z,2,2);
printf("\nThe first poly is:\n");
output(x,2);
printf("\nThe second poly is:\n");
output(y,2);
printf("\nThe result poly is:\n");
output(z,4);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -