矩阵运算 [英] Matrices operations

查看:76
本文介绍了矩阵运算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下问题,我只想知道是否应该使用指针.谢谢你

设计并实现一个Matrixtype类,该类可以存储任意大小的矩阵.重载运算符+-*以执行加,减和乘法.

如果您告诉我如何在类中编写构造函数.

解决方案

如果它们必须具有任意大小",则分配必须是动态的,因此您拥有使用(至少在类内部)指针.
但是,指针可以由处理所有分配/取消分配事务的某些其他库类在内部进行管理,例如std::vector.

由于矩阵可以是任意大小",因此可以通过以下方式构造:
-构造一个零尺寸矩阵"(无效),以便稍后对其进行初始化(例如,通过分配结果)
-构造一个大小矩阵"(标量),给出一个可选的值,该值不能为零
-根据给定的大小构造矩阵(可以填充zeore,也可以使其等于单位矩阵(如果平方),等等)和可选的常数数组(用作初始化程序)


i have the following problem i just want to know if i should use pointers . thank you

Design and implement a class Matrixtype that can store a matrix of any size . overload the operators + - * to perform addition , subtraction and multiplication .

if you please tell me how to write the constructor in the class .

解决方案

If they must have "any size" than the allocation must be dynamic, and hence you have to use (at least internally of the class) pointers.
But pointers can be managed internally by some other library class that handle all the allocation /deallocation stuff, like std::vector.

Since the matrix can be "any size", you can construct in some ways:
- Construct a "zero sized matrix" (invalid) letting it be initialized later (for example, by assigning a result)
- Construct a "one sized matrix" (scalar) given an optional value defailting to zero
- Construct matrix given its size (you can fill up with zeores, or making it an identity matrix, if squared etc.) and a optional constant array of constants (that act as an initializer)


这篇关于矩阵运算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆