矩阵加减乘.h

来自「二维点集合聚类的图像化演示程序 用它可以很直观的看到聚类的整个过程」· C头文件 代码 · 共 48 行

H
48 行
字号
#include <iostream>
#include <iomanip>
#include <new>
using namespace std;
void matrix_mutiply(float **matrix_1,float **matrix_2,int lenth)
{
	int i,j,k;
	float temp_sum,**temp_matrix;
	temp_matrix=new( float *[lenth] );
	for( i=0;i<lenth;i++ )
	{
		temp_matrix[i]=new ( float [lenth] );
		for( j=0;j<lenth;j++ )
		{
			temp_sum=0;
			for( k=0;k<lenth;k++ )
			{
				temp_sum+=matrix_1[i][k]*matrix_2[k][j];
			}
		}
		temp_matrix[i][j]=temp_sum;
	}    
}
void matrix_add(float **matrix_1,float **matrix_2,int lenth)
{
	int i,j;	
	for( i=0;i<lenth;i++ )
	{
		for( j=0;j<lenth;j++ )
		{
			matrix_1[i][j]+=matrix_2[i][j];
		}
	
	}    
}

void matrix_sub(float **matrix_1,float **matrix_2,int lenth)
{
	int i,j;	
	for( i=0;i<lenth;i++ )
	{
		for( j=0;j<lenth;j++ )
		{
			matrix_1[i][j]-=matrix_2[i][j];
		}
	
	}    
}

⌨️ 快捷键说明

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