mtimes.m

来自「张量分析工具」· M 代码 · 共 63 行

M
63
字号
function C = mtimes(A,B)%MTIMES Multiplies two tenmat objects.%%  C = MTIMES(A,B) computes the product of A and B. The result is a%  TENMAT object and can be transformed into a tensor.%%  C = MTIMES(A,B) is called for the syntax 'A * B' when A or B is a%  TENMAT object.  %%   See also TENMAT.%%MATLAB Tensor Toolbox.%Copyright 2007, Sandia Corporation. % This is the MATLAB Tensor Toolbox by Brett Bader and Tamara Kolda. % http://csmr.ca.sandia.gov/~tgkolda/TensorToolbox.% Copyright (2007) Sandia Corporation. Under the terms of Contract% DE-AC04-94AL85000, there is a non-exclusive license for use of this% work by or on behalf of the U.S. Government. Export of this data may% require a license from the United States Government.% The full license terms can be found in tensor_toolbox/LICENSE.txt% $Id: mtimes.m,v 1.10 2007/01/10 01:27:31 bwbader Exp $% Handle scalar inputif ~isa(B,'tenmat') && numel(B) == 1    C = A;    C.data = C.data * B;    return;endif ~isa(A,'tenmat') && numel(A) == 1    C = B;    C.data = C.data * A;    return;end% Handle matrix inputif ~isa(A,'tenmat')    A = tenmat(A,1);endif ~isa(B,'tenmat')    B = tenmat(B,1);end% Error checkif size(A,2) ~= size(B,1)      error(['Size mismatch: Number of columns in A is not equal to' ...	   ' the number of rows in B']);endtsiz = [A.tsize(A.rindices) B.tsize(B.cindices)];if ~isempty(tsiz)    C = tenmat;    C.tsize = tsiz;    C.rindices = 1:length(A.rindices);    C.cindices = (1:length(B.cindices)) + length(A.rindices);    C.data = A.data * B.data;else    C = A.data * B.data;end

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?