C/C++矩阵计算器

为方便计算旋转矩阵,作者使用C/C++编写了一个小型软件,具备加、减、乘、数乘等基本运算,并增加了求逆功能。
摘要由CSDN通过智能技术生成

问题描述

最近需要计算一些旋转矩阵,手算太麻烦,于是写了个小软件

参考

C/C++实现矩阵各种运算
Adjoint and Inverse of a Matrix

实现

Vecace博主的C/C++实现矩阵各种运算已经实现了诸如“加、减、乘、数乘”等大部分功能,在此基础上增加求矩阵的逆的功能,具体如下:

#include <iostream>
#include <malloc.h>
#include <stdio.h>
using namespace std;

typedef struct
{
   
	//结构体
	int row, col;
	//二维指针,目的是动态分配内存
	float** matrix;
} Matrix;

typedef struct
{
   
	char* name;
	char* number;
} Student;

Matrix CreateMatrix()
{
   
	Matrix m;
	int row, col;
	cout << "输入行数与列数:" << endl;
	cin >> row >> col;
	float** enterMatrix;
	enterMatrix = (float**)malloc(row * sizeof(float*));
	for (int i = 0; i < row; i++)
		enterMatrix[i] = (float*)malloc(col * sizeof(float));
	cout << "输入你的矩阵:" << endl;
	for (int i = 0; i < row; i++)
	{
   
		for (int j = 0; j < col; j++)
		{
   
			cin >> enterMatrix[i][j];
		}
	}
	m.col = col;
	m.row = row;
	m.matrix = enterMatrix;
	return m;
}

Matrix Create2DArrayDefault(int row_col)
{
   
	Matrix m;
	float** enterMatrix;
	enterMatrix = (float**)malloc(row_col * sizeof(float*));
	for (int i = 0; i < row_col; i++)
		enterMatrix[i] = (float*)malloc(row_col * sizeof(float));
	for (int i = 0; i < row_col; i++)
	{
   
		for (int j = 0; j < row_col; j++)
		{
   
			enterMatrix[i][j] = 0;
		}
	}
	m.col = row_col;
	m.row = row_col;
	m.matrix = enterMatrix;
	return m;
}

// Function to get cofactor of A[p][q] in temp[][]. n is current 
// dimension of A[][] 
void getCofactor(Matrix A, Matrix temp, int p, int q, int n)
{
   
	int i = 0, j = 0;

	// Looping for each element of the matrix 
	for (int row = 
  • 3
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值