Last change
on this file was
17,
checked in by zhangj, 11 years ago
|
To have a stable version on the server.
|
-
Property svn:executable set to
*
|
File size:
1.2 KB
|
Line | |
---|
1 | function 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? |
---|
9 | s1 = size(sp1); |
---|
10 | s2 = size(sp2); |
---|
11 | if (length(s1)>2) || (length(s2)>2) |
---|
12 | error 'Matrix multiplication is only defined for vectors and simple arrays.' |
---|
13 | end |
---|
14 | |
---|
15 | if (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 | |
---|
50 | else |
---|
51 | error 'sp1 and sp2 are of incompatible sizes for .* operation.' |
---|
52 | |
---|
53 | end |
---|
54 | |
---|
55 | |
---|
56 | |
---|
57 | |
---|
58 | |
---|
Note: See
TracBrowser
for help on using the repository browser.