矩阵运算 相加,相减,乘标量,相乘

练习下矩阵的基本运算:O(∩_∩)O~

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication4
{
    class MyMatrix3
    {
        int m11, m12, m13;
        int m21, m22, m23;
        int m31, m32, m33;

        //矩阵相加
        public MyMatrix3 AddMatrix3(MyMatrix3 m1,MyMatrix3 m2)
        {
            MyMatrix3 newMatrix3 = new MyMatrix3();

            newMatrix3.m11 = m1.m11 + m2.m11;
            newMatrix3.m12 = m1.m12 + m2.m12;
            newMatrix3.m13 = m1.m13 + m2.m13;

            newMatrix3.m21 = m1.m21 + m2.m21;
            newMatrix3.m22 = m1.m22 + m2.m22;
            newMatrix3.m23 = m1.m23 + m2.m23;

            newMatrix3.m31 = m1.m31 + m2.m31;
            newMatrix3.m32 = m1.m32 + m2.m32;
            newMatrix3.m33 = m1.m33 + m2.m33;

            return newMatrix3;
        }

        //矩阵相加
        public MyMatrix3 SubMatrix3(MyMatrix3 m1, MyMatrix3 m2)
        {
            MyMatrix3 newMatrix3 = new MyMatrix3();

            newMatrix3.m11 = m1.m11 - m2.m11;
            newMatrix3.m12 = m1.m12 - m2.m12;
            newMatrix3.m13 = m1.m13 - m2.m13;

            newMatrix3.m21 = m1.m21 - m2.m21;
            newMatrix3.m22 = m1.m22 - m2.m22;
            newMatrix3.m23 = m1.m23 - m2.m23;

            newMatrix3.m31 = m1.m31 - m2.m31;
            newMatrix3.m32 = m1.m32 - m2.m32;
            newMatrix3.m33 = m1.m33 - m2.m33;

            return newMatrix3;
        }

        //矩阵和标量相乘
        public MyMatrix3 ScalarMultiply(MyMatrix3 a,int scale)
        {
            MyMatrix3 newMatrix3 = new MyMatrix3();
            newMatrix3.m11 = a.m11 * scale;
            newMatrix3.m12 = a.m12 * scale;
            newMatrix3.m12 = a.m12 * scale;

            newMatrix3.m21 = a.m21 * scale;
            newMatrix3.m22 = a.m22 * scale;
            newMatrix3.m23 = a.m23 * scale;

            newMatrix3.m21 = a.m21 * scale;
            newMatrix3.m22 = a.m22 * scale;
            newMatrix3.m23 = a.m23 * scale;

            return newMatrix3;
        }

        //矩阵相乘
        public MyMatrix3 ScalarMatrix3(MyMatrix3 a,MyMatrix3 b)
        {
            MyMatrix3 newMatrix3 = new MyMatrix3();

            newMatrix3.m11 = a.m11 * b.m11 + a.m12 * b.m21 + a.m13 * b.m31;
            newMatrix3.m12 = a.m11 * b.m12 + a.m12 * b.m22 + a.m13 * b.m32;
            newMatrix3.m13 = a.m11 * b.m13 + a.m12 * b.m23 + a.m13 * b.m33;

            newMatrix3.m21 = a.m21 * b.m11 + a.m22 * b.m21 + a.m23 * b.m31;
            newMatrix3.m22 = a.m21 * b.m12 + a.m22 * b.m22 + a.m23 * b.m32;
            newMatrix3.m23 = a.m21 * b.m13 + a.m22 * b.m23 + a.m23 * b.m33;

            newMatrix3.m31 = a.m31 * b.m11 + a.m32 * b.m21 + a.m33 * b.m31;
            newMatrix3.m32 = a.m31 * b.m12 + a.m32 * b.m22 + a.m33 * b.m32;
            newMatrix3.m33 = a.m31 * b.m13 + a.m32 * b.m23 + a.m33 * b.m33;

            return newMatrix3;
        }
    }
}
时间: 2024-08-17 15:32:43

矩阵运算 相加,相减,乘标量,相乘的相关文章

js面试题--------JS中数字和字符,布尔类型相加相减问题

JS中数字和字符相加相减问题 <html lang="en"> <head> <meta charset="utf-8" /> <title></title> </head> <body> </body> </html> <script type="text/javascript"> var a = 100; var b = &

C语言:十字链表的相加相减

#include<stdio.h> #include<stdlib.h> #define N 100 typedef struct node { int row, col; int v; struct node *r, *d; }*link; typedef struct crosslist { link rowhead[N], colhead[N]; int rows, cols, nums; }*list; int i, j; list init(list cl); list

JS当前日期相加相减

function DateAddORSub(interval,type,number) { /* * 功能:实现Script的Date加减功能. * 参数:interval,字符串表达式,表示要添加的时间间隔. * 参数:number,数值表达式,表示要添加的时间间隔的个数. * 参数:type,加减类型. * 返回:新的时间对象. * var newDate =DateAddORSub("d","+",5); */ var date = new Date(); s

JS中小数相加相减时出现很长的小数点的解决方式

1.问题: 平时写的代码中会出现这种情况,parseFloat(11.3-10.1) 运行的结果依然是1.200000000000001 代码示例: var arr = [0.0111,11.002,0.3,1.5,1.61] var total = 0 arr.forEach(item =>{ total += item }) console.log(total) 返回的结果---  14.423100000000002,这种情况就不合常理. 2.解决方案: 这里有一种可行的解决方法,应用到M

python 变量 不断 相加 or 相减的简便写法

相加: 相减: 原文地址:https://www.cnblogs.com/kaibindirver/p/9865397.html

图像算术运算——相加、相减、与、或、异或、非

一.函数简介 1.add—图像矩阵相加 函数原型:cv2.add(src1, src2, dst=None, mask=None, dtype=None) src1:图像矩阵1 src1:图像矩阵2 dst:默认选项 mask:默认选项 dtype:默认选项 2.subtract—图像矩阵相减 函数原型:cv2.subtract(src1, src2, dst=None, mask=None, dtype=None) src1:图像矩阵1 src1:图像矩阵2 dst:默认选项 mask:默认选

javascript小数相减会出现一长串的小数位数的原因

javascript小数相减会出现一长串的小数位数的原因 <script> var a='38.8'; var b='6.8'; alert(parseFloat(a)-parseFloat(b)); var a=134.22; var b=6; alert(a*b); </script> 以上代码为什么产生一长串小数位出来,虽然比较精确,可没必要呀. 这个和数据结构有关系,整数型自动转换成正型计算,小数型直接转成double型计算.这是在内存中运算的时候必须这样,你该知道计算机只

基于Qt的OpenGL可编程管线学习(15)- 颜色加深、颜色减淡、想家相减

1.颜色加深 shader //颜色加深 uniform sampler2D U_MainTexture; uniform sampler2D U_SubTexture; varying vec2 M_coord; void main() {         vec4 blendColor = texture2D(U_SubTexture, M_coord);         vec4 baseColor = texture2D(U_MainTexture, M_coord);         

oracle 日期相减 转载

转自 http://hi.baidu.com/juanjuan_66/blog/item/cf48554c9331fbe6d62afc6a.html oracle日期相减2012-02-10 12:18--MONTHS_BETWEEN(date2,date1) 给出date2-date1的月份 SQL> select months_between('19-12月-1999','19-3月-1999') mon_between from dual; MON_BETWEEN -----------