source: MML/trunk/machine/SOLEIL/common/toolbox/SymbolicPolynomials/SymbolicPolynomials/@sympoly/mtimes.m @ 4

Last change on this file since 4 was 4, checked in by zhangj, 10 years ago

Initial import--MML version from SOLEIL@2013

File size: 1.2 KB
Line 
1function sp=mtimes(sp1,sp2)
2% sympoly/mtimes: Matrix multiplication of sympoly objects or scalars
3% usage: sp=sp1*sp2;
4%
5% arguments:
6%  sp,sp1,sp2   - sympoly objects or numeric scalars or a numeric array
7
8% are they of compatible sizes?
9s1 = size(sp1);
10s2 = size(sp2);
11if (length(s1)>2) || (length(s2)>2)
12  error 'Matrix multiplication is only defined for vectors and simple arrays.'
13end
14
15if (s1(2) == s2(1)) || (numel(sp1)==1) || (numel(sp2)==1)
16  % they are compatible
17 
18  if (numel(sp1) == 1) && (numel(sp2) == 1)
19    % both are scalars. Just use .*
20    sp = sp1.*sp2;
21   
22  elseif (numel(sp1) == 1) && (numel(sp2) > 1)
23    % sp1 is a scalar, but not sp2
24    sp = sympoly(sp2);
25    for i = 1:numel(sp2)
26      sp(i) = sp1.*sp2(i);
27    end
28
29  elseif (numel(sp1) > 1) && (numel(sp2) == 1)
30    % sp2 is a scalar, but not sp1
31    sp = sympoly(sp1);
32    for i = 1:numel(sp1)
33      sp(i) = sp1(i).*sp2;
34    end
35   
36  elseif (numel(sp1) > 1) && (numel(sp2) > 1)
37    % both are arrays.
38    sp = sympoly(zeros(s1(1),s2(2)));
39
40    for i = 1:s1(1)
41      for j = 1:s2(2)
42        for k = 1:s1(2)
43          sp(i,j) = sp(i,j) + sp1(i,k).*sp2(k,j);
44        end
45      end
46    end
47   
48  end
49 
50else
51  error 'sp1 and sp2 are of incompatible sizes for .* operation.'
52 
53end
54
55
56
57
58
Note: See TracBrowser for help on using the repository browser.