如何用矩阵内积公式的迹计算内积

您还未登陆,请登录后操作!
编写一个Matlab函数,用于计算两个矩阵的积(两个矩阵作为输入参数,不能使用矩阵乘运算符)。
,用于计算两个矩阵的积(两个矩阵作为输入参数,不能使用矩阵乘运算符)。
function C=ji(A,B)
[M N]=size(A);
[m n]=size(B);
error('前者列数与后者行数不同,无法相乘!');
D(p,q,t)=A(p,t)*B(t,q);
C(p,q)=sum(D(p,q,:));
大家还关注&& 查看话题
矩阵每个元素取平方,能否用矩阵初等运算实现?
刚才忽然想到这个问题。
以向量为例,g=(g1,g2,g3,...,gn),H=(g1^2,g2^2,...,gn^2),其中g1, g2...gn都是一个数值
在matlab里,显然H=g.^2
那能不能用类似于g的+-*/(矩阵操作符)达到这个效果?
这东西叫做 Schur积,在OPencv中有定义,同一位置的元素直接相乘就是。
也可自定义一个函数。 矩阵也可以.* : Originally posted by feixiaolin at
这东西叫做 Schur积,在OPencv中有定义,同一位置的元素直接相乘就是。
也可自定义一个函数。 good : Originally posted by Hsienming at
矩阵也可以.* 这个不算矩阵的初等运算吧,matlab这种做法我也知道,只想看看有没有别的表示途径。CGAffineTransformMake(a,b,c,d,tx,ty)
矩阵运算的原理 - 不积跬步 无以至千里 不积小流 无以成江海 - ITeye技术网站
博客分类:
CGAffineTransformMake(a,b,c,d,tx,ty)
ad缩放bc旋转tx,ty位移,基础的2D矩阵
x=ax+cy+tx
y=bx+dy+ty
1.矩阵的基本知识:
struct CGAffineTransform
CGFloat a, b, c,
CGFloat tx,};
CGAffineTransform CGAffineTransformMake (CGFloat a,CGFloat b,CGFloat c,CGFloat d,CGFloat tx,CGFloat ty);
为了把二维图形的变化统一在一个坐标系里,引入了齐次坐标的概念,即把一个图形用一个三维矩阵表示,其中第三列总是(0,0,1),用来作为坐标系的标准。所以所有的变化都由前两列完成。
以上参数在矩阵中的表示为:
运算原理:原坐标设为(X,Y,1);
[aX + cY + tx
bX + dY + ty
通过矩阵运算后的坐标[aX + cY + tx
bX + dY + ty
1],我们对比一下可知:
第一种:设a=d=1, b=c=0.
[aX + cY + tx
bX + dY + ty
可见,这个时候,坐标是按照向量(tx,ty)进行平移,其实这也就是函数
CGAffineTransform CGAffineMakeTranslation(CGFloat tx,CGFloat ty)的计算原理。
第二种:设b=c=tx=ty=0.
[aX + cY + tx
bX + dY + ty
可见,这个时候,坐标X按照a进行缩放,Y按照d进行缩放,a,d就是X,Y的比例系数,其实这也就是函数
CGAffineTransform CGAffineTransformMakeScale(CGFloat sx, CGFloat sy)的计算原理。a对应于sx,d对应于sy。
第三种:设tx=ty=0,a=cos?,b=sin?,c=-sin?,d=cos?。
[aX + cY + tx
bX + dY + ty
1] = [Xcos? - Ysin?
Xsin? + Ycos?
可见,这个时候,?就是旋转的角度,逆时针为正,顺时针为负。其实这也就是函数
CGAffineTransform CGAffineTransformMakeRotation(CGFloat angle)的计算原理。angle即?的弧度表示。
2.利用上面的变换写一个UIImage矩阵变换的例子:
下面是一个关于image的矩阵运算的例子,无外乎是运用以上三种变换的组合,达到所定义的效果
//UIImageOrientation的定义,定义了如下几种变换
typedef enum
UIImageOrientationUp,
// default orientation
UIImageOrientationDown,
// 180 deg rotation
UIImageOrientationLeft,
// 90 deg CCW
UIImageOrientationRight,
// 90 deg CW
UIImageOrientationUpMirrored,
// as above but image mirrored along other axis. horizontal flip
UIImageOrientationDownMirrored,
// horizontal flip
UIImageOrientationLeftMirrored,
// vertical flip
UIImageOrientationRightMirrored, // vertical flip
} UIImageO
//按照UIImageOrientation的定义,利用矩阵自定义实现对应的变换;
-(UIImage *)transformImage:(UIImage *)aImage
CGImageRef imgRef = aImage.CGI
CGFloat width = CGImageGetWidth(imgRef);
CGFloat height = CGImageGetHeight(imgRef);
CGAffineTransform transform = CGAffineTransformI
CGRect bounds = CGRectMake(0, 0, width, height);
CGFloat scaleRatio = 1;
CGFloat boundH
UIImageOrientation orient = aImage.imageO
switch(UIImageOrientationLeftMirrored)
case UIImageOrientationUp:
transform = CGAffineTransformI
case UIImageOrientationUpMirrored:
transform = CGAffineTransformMakeTranslation(width, 0.0);
transform = CGAffineTransformScale(transform, -1.0, 1.0); //沿y轴向左翻
case UIImageOrientationDown:
transform = CGAffineTransformMakeTranslation(width, height);
transform = CGAffineTransformRotate(transform, M_PI);
case UIImageOrientationDownMirrored:
transform = CGAffineTransformMakeTranslation(0.0, height);
transform = CGAffineTransformScale(transform, 1.0, -1.0);
case UIImageOrientationLeft:
boundHeight = bounds.size.
bounds.size.height = bounds.size.
bounds.size.width = boundH
transform = CGAffineTransformMakeTranslation(0.0, width);
transform = CGAffineTransformRotate(transform, 3.0 * M_PI / 2.0);
case UIImageOrientationLeftMirrored:
boundHeight = bounds.size.
bounds.size.height = bounds.size.
bounds.size.width = boundH
transform = CGAffineTransformMakeTranslation(height, width);
transform = CGAffineTransformScale(transform, -1.0, 1.0);
transform = CGAffineTransformRotate(transform, 3.0 * M_PI / 2.0);
case UIImageOrientationRight: //EXIF = 8
boundHeight = bounds.size.
bounds.size.height = bounds.size.
bounds.size.width = boundH
transform = CGAffineTransformMakeTranslation(height, 0.0);
transform = CGAffineTransformRotate(transform, M_PI / 2.0);
case UIImageOrientationRightMirrored:
boundHeight = bounds.size.
bounds.size.height = bounds.size.
bounds.size.width = boundH
transform = CGAffineTransformMakeScale(-1.0, 1.0);
transform = CGAffineTransformRotate(transform, M_PI / 2.0);
[NSException raise:NSInternalInconsistencyException format:@"Invalid image orientation"];
UIGraphicsBeginImageContext(bounds.size);
CGContextRef context = UIGraphicsGetCurrentContext();
if (orient == UIImageOrientationRight || orient == UIImageOrientationLeft) {
CGContextScaleCTM(context, -scaleRatio, scaleRatio);
CGContextTranslateCTM(context, -height, 0);
CGContextScaleCTM(context, scaleRatio, -scaleRatio);
CGContextTranslateCTM(context, 0, -height);
CGContextConcatCTM(context, transform);
CGContextDrawImage(UIGraphicsGetCurrentContext(), CGRectMake(0, 0, width, height), imgRef);
UIImage *imageCopy = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return imageC
/library/ios/documentation/GraphicsImaging/Conceptual/drawingwithquartz2d/dq_affine/dq_affine.html
浏览: 1152564 次
来自: China
/2014/08/noti ...
[15/5/25 下午2:57:19] Cactus: Ext ...
这些任务可能会耗费一到两秒的时间,可以考虑将其交由父级应用(p ...
注意:Apple Watch上界面对象与对应的视图之间的通信有 ...
如果您想改变一组界面控制器,请在初始界面控制器的init方法中 ...您所在的位置: &
如何得到两个矩阵的Hadamard积
如何得到两个矩阵的Hadamard积
张长富 等译
清华大学出版社
《数据结构(C语言版):1000个问题与解答》第1章数组,数组是C语言提供的最基本的数据结构。本小节为大家介绍如何得到两个矩阵的Hadamard积。
1.41& 如何得到两个矩阵的Hadamard积
如果两个矩阵具有相同的维数,那么除了正常的矩阵乘法之外,还有另一种乘法,称为Hadamard积或Entrywise积。m×n阶的两个矩阵的Hadamard积定义为:
A?B也是一个m×n矩阵。乘积矩阵中的每一个元素都是分量矩阵元素的乘积。也就是说,(A?B) [i][j] =A[i][j] * B[i][j]。
下面是一个示例。
Hadamard积
#include&&#include&&int&A[10][10]; &int&B[10][10]; &int&rows=0,cols=0; &int&Hadamard[10][10]; &void&scanmatrices() &{ &&&&int&i,j;&for(i=0;i;i++) &&&&for(j=0;j;j++) &&&&{ &&&&&&&printf("A[%d][%d]&=&",i+1,j+1); &&&&&&&scanf("%d",&A[i][j]); &&&&&&&printf("B[%d][%d]&=&",i+1,j+1); &&&&&&&scanf("%d",&B[i][j]); &&&&} &} &&void&displayHadamard() &{ &&&&int&i,j; &&&&for(i=0;i;i++) &&&&{ &&&&&&&for(j=0;j;j++) &&&&&&&&&&printf("%d",A[i][j]*B[i][j]); &&&&&&&&&&printf("\n"); &&&&} &} &&int&main() &{ &&&&printf("Enter&number&of&rows&:"); &&&&scanf("%d",&rows); &&&&printf("Enter&number&of&columns&:"); &&&&scanf("%d",&cols); &&&&scanmatrices(); &&&&displayHadamard(); &&&&return&0; &}&
【责任编辑: TEL:(010)】&&&&&&
关于&&&&&&的更多文章
很久很久以前,冬天爱上了夏天,可是他们始终不能相见,后来,他
本书描述了黑客用默默无闻的行动为数字世界照亮了一条道路的故事。
马克o桑布恩不仅带来了弗雷德的近况,更将追求卓越的
快乐的员工就一定能干吗?为什么满意度和绩效不一定相
思想决定行为,行为决定习惯,习惯决定性格,性格决定
本书是《网管员世界》杂志社推出的一本集知识性和实用性于一身的网络管理技术书籍,书中收集了《网管员世界》自创刊以来“故障诊
51CTO旗下网站}

我要回帖

更多关于 矩阵的内积 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信