镜像matrix在matlab里怎么做呢?
答案:3 悬赏:60 手机版
解决时间 2021-04-09 15:03
- 提问者网友:我没有何以琛的痴心不悔
- 2021-04-09 09:13
镜像matrix在matlab里怎么做呢?
最佳答案
- 五星知识达人网友:神也偏爱
- 2021-04-09 09:26
这个要用function做。
1.设num=0; flag=0; 后如果是n阶矩阵的话设为1到n(i=1:n),而num是要等于i的。设b=2,则在loop用到j=1:n.
2.当i和j是一样的(i=j), data(i,j)=1,flag也是1。
3。当 flag=0,那么data(i,j)=num; num=num-1;
4。当 flag==1,data(i,j)=b;而 b=b+1;
1.设num=0; flag=0; 后如果是n阶矩阵的话设为1到n(i=1:n),而num是要等于i的。设b=2,则在loop用到j=1:n.
2.当i和j是一样的(i=j), data(i,j)=1,flag也是1。
3。当 flag=0,那么data(i,j)=num; num=num-1;
4。当 flag==1,data(i,j)=b;而 b=b+1;
全部回答
- 1楼网友:神的生死簿
- 2021-04-09 11:16
a = flipdim(a,1); % Flips the rows of a
a = flipdim(a,2); % Flips the columns of a
EDIT: An additional little trick... if for whatever reason you have to flip BOTH dimensions of a 2-D array, you can either call FLIPDIM twice:
a = flipdim(flipdim(a,1),2);
or call ROT90:
a = rot90(a,2); % Rotates matrix by 180 degrees
- 2楼网友:第四晚心情
- 2021-04-09 10:07
matlab里的'/'不完全等于矩阵除法。
你可以用help mrdivide看一下'/'的帮助:
>> help mrdivide
/ slash or right matrix divide.
a/b is the matrix division of b into a, which is roughly the
same as a*inv(b) , except it is computed in a different way.
more precisely, a/b = (b'\a')'. see mldivide for details.
就是说a/b可以大致看成a*inv(b),但用的是另一种方法。更确切的讲a/b = (b'\a')'。
那再看看'\'(左除或者反除)是什么东东。
>> help mldivide
\ backslash or left matrix divide.
a\b is the matrix division of a into b, which is roughly the
same as inv(a)*b , except it is computed in a different way.
if a is an n-by-n matrix and b is a column vector with n
components, or a matrix with several such columns, then
x = a\b is the solution to the equation a*x = b computed by
gaussian elimination. a warning message is printed if a is
badly scaled or nearly singular. a\eye(size(a)) produces the
inverse of a.
if a is an m-by-n matrix with m < or > n and b is a column
vector with m components, or a matrix with several such columns,
then x = a\b is the solution in the least squares sense to the
under- or overdetermined system of equations a*x = b. the
effective rank, k, of a is determined from the qr decomposition
with pivoting. a solution x is computed which has at most k
nonzero components per column. if k < n this will usually not
be the same solution as pinv(a)*b. a\eye(size(a)) produces a
generalized inverse of a.
就是说当a是n阶方阵b为n行的列向量时,x=a\b就是线性方程组a*x=b的解,算法是用高斯消去法。a\eye(size(a))产生的是方阵a的逆矩阵。
如果a是m*n的矩阵且m≠n,b是跟a行数(m行)相同的列向量时,x=a\b是非满秩的线性方程组a*x=b的解系,a的秩k由qr分解得出。如果k> a=pascal(3) %a赋值为3*3的方阵。
a =
1 1 1
1 2 3
1 3 6
>> b=[1:3]' % b是3*1的列向量。
b =
1
2
3
>> x=a\b % 用反除求ax=b的解,结果x是个列向量,注意是a\b不是b\a
x =
0
1
0
>> a*x % 验证一下a*x刚好等于b
ans =
1
2
3
>> x=b'/a' % 这回是正除了,不过b'是行向量,a'也倒一下,正除的时候就是b'/a'了,不是a'/b'了,结果x是个行向量
x =
0 1 0
>> x*a' % 验证一下,跟b'一样。
ans =
1 2 3
>> a=rand(3,4) % 这回重新赋值,a不是方阵了,是3*4的矩阵
a =
0.5298 0.3798 0.4611 0.0592
0.6405 0.7833 0.5678 0.6029
0.2091 0.6808 0.7942 0.0503
>> x=a\b % 实际上方程组没有唯一确定的解,而是无数解,所以解出来的是一个特解
x =
-1.5132
4.9856
0
-1.5528
>> a*x % 验证,跟b相等。
ans =
1.0000
2.0000
3.0000
>> a=rand(3,2) % 再看看3*2的矩阵,行数>列数的情况
a =
0.4154 0.0150
0.3050 0.7680
0.8744 0.9708
>> x=a\b
x =
1.8603
1.5902
>> a*x % 验证一下,嗯?怎么不等于b了?
ans =
0.7966
1.7886
3.1704
% 为什么呢?因为方程数(行数)太多,未知数(列数)个数太少,2个未知数,用2个线性无关的方程就可以求确定的解了,现在方程多了,不能同时满足所有方程,所以实际上是无解,只不过matlab里用的是一个最小二乘意义上的近似解,所以验证时不等,只是尽可能近似的满足所有方程。
另外,团idc网上有许多产品团购,便宜有口碑
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯