1.矩阵相加

两个同型矩阵做加法,就是对应的元素相加。

#include<iostream>
using namespace std;
int main(){
int a[3][3]={{1,2,3},{6,5,4},{4,3,2}};
int b[3][3]={{4,3,2},{6,5,4},{1,2,3}};
int c[3][3]={0,0,0,0,0,0,0,0,0};
int i,j;
cout<<"Array A:"<<endl;
for(i=0;i<3;i++){
for(j=0;j<3;j++){
c[i][j]+=a[i][j];//实现相加操作1
cout<<"\t"<<a[i][j];//输出矩阵A
}
cout<<endl;
}
cout<<endl;
cout<<"Array B:"<<endl;
for(i=0;i<3;i++){
for(j=0;j<3;j++){
c[i][j]+=b[i][j];//实现矩阵操作2
cout<<"\t"<<b[i][j];//输出矩阵B
}
cout<<endl;
}
cout<<endl;
cout<<"Array C:"<<endl;
for(i=0;i<3;i++){
for(j=0;j<3;j++){
cout<<"\t"<<c[i][j];//输出矩阵C
}
cout<<endl;
}
cout<<endl;
return 0; }

2.实现矩阵的转置

#include<iostream>
using namespace std;
int main(){
int a[3][2]={{4,3},{6,5},{1,2}};
int b[2][3]={0,0,0,0,0,0};
int i,j;
cout<<"Array A:"<<endl;
for(i=0;i<3;i++){
for(j=0;j<2;j++){
cout<<"\t"<<a[i][j];//输出矩阵A
b[j][i]=a[i][j];//进行转置操作
}
cout<<endl;
}
cout<<endl;
cout<<"Array B:"<<endl;
for(i=0;i<2;i++){
for(j=0;j<3;j++){
cout<<"\t"<<b[i][j];
}
cout<<endl;
}
cout<<endl;
return 0; }

3.实现矩阵的相乘

一个m行n列的矩阵可以和n列k行的矩阵相乘,得到一个m行k列的矩阵

#include<iostream>
using namespace std;
int main(){
int a[3][2]={{4,3},{6,5},{1,2}};
int b[2][3]={{1,2,3},{6,5,4}};
int c[3][3]={0,0,0,0,0,0,0,0,0};
int i,j,k,l;
cout<<"Array A:"<<endl;
for(i=0;i<3;i++){
for(j=0;j<2;j++){
cout<<"\t"<<a[i][j];//输出矩阵A
}
cout<<endl;
}
cout<<endl;
cout<<"Array B:"<<endl;
for(i=0;i<2;i++){
for(j=0;j<3;j++){
cout<<"\t"<<b[i][j];//输出矩阵B
}
cout<<endl;
}
cout<<endl;
cout<<"Array C:"<<endl;
for(i=0;i<3;i++){
for(j=0;j<3;j++){
for(k=0;k<2;k++){
c[i][j]+=a[i][k]*b[k][j];//实现相乘操作
}
cout<<"\t"<<c[i][j];//输出矩阵C
}
cout<<endl;
}
cout<<endl;
return 0; }

4.求矩阵中的鞍点

在矩阵中行中最大,列中最小的元素就是我们要求的鞍点

#include<iostream>
using namespace std;
int main(){
int a[3][4]={{3,2,13,1},{8,7,10,5},{12,11,14,9}};
int i,j,k,ad,q=0;
bool tag;
for(i=0;i<3;i++){
for(j=0;j<4;j++){
cout<<"\t"<<a[i][j];
}
cout<<endl;
}
cout<<endl;
for(i=0;i<3;i++){
ad=a[i][0];
tag=true;
for(j=1;j<4;j++){
if(ad<a[i][j]){
k=j;
}//先选出行中最大
}
for(j=0;j<3;j++){
if(a[i][k]>a[j][k]){
tag=false;
};//再选出列中最小
}
cout<<endl;
if(tag==true){
cout<<"鞍点是第"<<(i+1)<<"行,第"<<(k+1)<<"列的"<<a[i][k]<<endl;
q++;
}
}
if(q==0){
cout<<"没有一个鞍点~"<<endl;
}
cout<<endl;
return 0; }

C++实现矩阵的相加/相称/转置/求鞍点的更多相关文章

  1. 矩阵的f范数及其求偏导法则

    转载自: http://blog.csdn.net/txwh0820/article/details/46392293 矩阵的迹求导法则   1. 复杂矩阵问题求导方法:可以从小到大,从scalar到 ...

  2. 矩阵的 Frobenius 范数及其求偏导法则

    cr:http://blog.csdn.net/txwh0820/article/details/46392293 一.矩阵的迹求导法则   1. 复杂矩阵问题求导方法:可以从小到大,从scalar到 ...

  3. 关于matlab矩阵卷积conv2和傅里叶变换求卷积ifft2的关系

    先定义两个矩阵 a = [1 2 3 5 ; 4 7 9 5;1 4 6 7;5 4 3 7;8 7 5 1] %a矩阵取5*4 b = [1 5 4; 3 6 8; 1 5 7]   %b矩阵如多数 ...

  4. 螺旋矩阵O(1)根据坐标求值

    传送门 洛谷2239 •题意 从矩阵的左上角(第11行第11列)出发,初始时向右移动: 如果前方是未曾经过的格子,则继续前进,否则右转: 重复上述操作直至经过矩阵中所有格子. 根据经过顺序,在格子中依 ...

  5. golang 矩阵乘法、行列式、求逆矩阵

    package matrix import ( "math" "github.com/astaxie/beego" ) type Matrix4 struct ...

  6. 矩阵的frobenius范数及其求偏导法则

    例子: http://www.mathchina.net/dvbbs/dispbbs.asp?boardid=4&Id=3673

  7. hdu 1005 Number Sequence(矩阵连乘+二分快速求幂)

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1005 代码: #include<iostream> #include<stdio.h&g ...

  8. C语言算法---求鞍点

    题目:有一个3X4矩阵,要求输出其鞍点(行列均最大的值),以及它的行号和列号. int a[3][4] = {{123,94,-10,218},                          {3 ...

  9. [zt]矩阵求导公式

    今天推导公式,发现居然有对矩阵的求导,狂汗--完全不会.不过还好网上有人总结了.吼吼,赶紧搬过来收藏备份. 基本公式:Y = A * X --> DY/DX = A'Y = X * A --&g ...

随机推荐

  1. JavaUtil_10_joda-time_用法入门

    二.参考资料 1. Joda-Time 2.jodaTime 的使用说明 3.强大易用的日期和时间库 Joda Time

  2. BEC listen and translation exercise 12

    More than 220 cities now have air quality monitoring systems and 42 others will have systems in plac ...

  3. Office 2007在安装过程中出错

    1, 可能是因为c:\program files\common files\microsoft Shared\web server Extensions\40\bin目录下缺少Fp4autl.dll, ...

  4. ThinkPHP中的find和select的区别

    ThinkPHP作为PHP中应用广泛又好用的框架,能比较快速的开发MVC架构的管理系统,获得了大量的应用.但是在ThinkPHP中select()和find()方法有什么区别呢? 事实上find()返 ...

  5. BZOJ - 1036 树的统计Count (树链剖分+线段树)

    题目链接 #include<bits/stdc++.h> using namespace std; typedef long long ll; ,inf=0x3f3f3f3f; ],mx[ ...

  6. 455. Assign Cookies Add to List

    Assume you are an awesome parent and want to give your children some cookies. But, you should give e ...

  7. NetCore博客

    NetCore外国一些高质量博客 https://www.cnblogs.com/fancunwei/p/9605627.html 前言 我之前看.netcore一些问题时候,用bing搜索工具搜到了 ...

  8. java06-数组动手动脑

    1.阅读QiPan.java示例程序了解如何利用二维数组和循环语句绘制五子棋盘. 定义了一个私有的二维数组作为棋盘.并定义了长度.之后打印符号使之连接起来作为棋盘在控制台显示.建立缓冲区用来读取输入的 ...

  9. webpack学习(一)—— 入门

    ,我们通常采用的是组件化开发方式,这样就会对应有很多个js文件,而打包工具的出现则是为了正确处理这些js文件的依赖关系,并生成一个最终的文件,这样,我们最后只需要加载打包以后的文件就可以了,而无须加载 ...

  10. bzoj 3202 [Sdoi 2013] 项链 —— 置换+计数

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=3202 参考了博客: https://www.cnblogs.com/zhoushuyu/p/ ...