|
28 | 28 | #<p> |
29 | 29 | # <[param m number of rows]> |
30 | 30 | # <[param n number of columns]> |
31 | | -# <[param x initial value of every element]> |
| 31 | +# <[param x initial value of every element (defaults to 0)]> |
32 | 32 | # <[returns a <tt>m</tt> x <tt>n<tt> matrix with <tt>x</tt> everywhere]> |
33 | 33 | #</p> |
34 | | -procedure m_constant(m,n,x:0.0) |
| 34 | +procedure m_constant(m,n,x:0) |
35 | 35 | local A |
36 | 36 | /n := m |
37 | 37 |
|
|
44 | 44 | # Creates a m x n matrix with ones on the diagonal and zeros everywhere else |
45 | 45 | # <[param m number of rows]> |
46 | 46 | # <[param n number of columns]> |
47 | | -# <[param zero (<i>optional</i>) can be used in place of <tt>0.0</tt>]> |
48 | | -# <[param one (<i>optional</i>) can be used in place of <tt>1.0</tt>]> |
| 47 | +# <[param zero (<i>optional</i>) can be used in place of <tt>0</tt>]> |
| 48 | +# <[param one (<i>optional</i>) can be used in place of <tt>1</tt>]> |
49 | 49 | # <[returns <tt>m</tt>X<tt>n</tt> identify matrix]> |
50 | 50 | #</p> |
51 | | -procedure m_identity(m,n, zero:0.0,one:1.0) |
| 51 | +procedure m_identity(m,n, zero:0,one:1) |
52 | 52 | local A, i |
53 | 53 | /n := m |
54 | 54 |
|
@@ -106,17 +106,18 @@ end |
106 | 106 | # <[param M1 first matrix]> |
107 | 107 | # <[param M2 second matrix]> |
108 | 108 | # <[param op binary operation to invoke]> |
| 109 | +# <[param zero (<i>optional</i>) can be used in place of <tt>0</tt>]> |
109 | 110 | # <[returns <tt>M1 op M2</tt>, with <tt>op</tt> defaulting to |
110 | 111 | # <tt>proc("+",2)</tt>]> |
111 | 112 | #</p> |
112 | | -procedure m_binop(M1, M1, op) |
| 113 | +procedure m_binop(M1, M1, op, zero:0) |
113 | 114 | local R, i, j |
114 | 115 | /op := ::proc("+", 2) |
115 | 116 |
|
116 | 117 | if (*M1 ~= *M2) | (*M1[1] ~= *M2[1]) then |
117 | 118 | ::runerr(500, "nonequal matrix dimensions to m_binop") |
118 | 119 |
|
119 | | - R = m_constant(*M1, *M1[1]) |
| 120 | + R = m_constant(*M1, *M1[1],zero) |
120 | 121 | every (i := 1 to *M1, j := 1 to *M1[1]) do |
121 | 122 | R[i,j] := invokeFcn(op,M1[i,j],M2[i,j]) |
122 | 123 | return R |
@@ -148,14 +149,15 @@ end |
148 | 149 | # Generic unary operation across a matrix. |
149 | 150 | # <[param M matrix]> |
150 | 151 | # <[param op unary operation to invoke]> |
| 152 | +# <[param zero (<i>optional</i>) can be used in place of <tt>0</tt>]> |
151 | 153 | # <[returns <tt>op M</tt>, with <tt>op</tt> defaulting to |
152 | 154 | # <tt>proc("-",1)</tt>]> |
153 | 155 | #<p> |
154 | | -procedure m_unaryop(M, op) |
| 156 | +procedure m_unaryop(M, op, zero:0) |
155 | 157 | local R, i, j |
156 | 158 | /op := ::proc("-", 1) |
157 | 159 |
|
158 | | - R = m_constant(*M, *M[1]) |
| 160 | + R = m_constant(*M, *M[1], zero) |
159 | 161 | every (i := 1 to *M, j := 1 to *M[1]) do |
160 | 162 | R[i,j] := invokeFcn(op, M[i,j]) |
161 | 163 | return R |
@@ -185,7 +187,7 @@ procedure m_multiply(M1, M2, addident:0, addfcn, mulfcn) |
185 | 187 | if (*M1[1] ~= *M2) then |
186 | 188 | ::runerr(500, "incompatible matrix dimensions to m_multiply") |
187 | 189 |
|
188 | | - R := m_constant(*M1, *M2[1]) |
| 190 | + R := m_constant(*M1, *M2[1], addident) |
189 | 191 | every (i := 1 to *R, j := 1 to *R[1]) do { |
190 | 192 | R[i,j] := addident |
191 | 193 | every k := 1 to *M2 do |
|
204 | 206 | # by overriding various functions and constants used internally. |
205 | 207 | #</p> |
206 | 208 | procedure m_lupDecomposition(M, subfcn, mulfcn, divfcn, |
207 | | - invertMetric, addident:0.0, mulident:1.0) |
| 209 | + invertMetric, addident:0, mulident:1) |
208 | 210 | local n, i, b, k, k2, p, j, L, U |
209 | 211 | /subfcn := ::proc("-", 2) |
210 | 212 | /mulfcn := ::proc("*", 2) |
|
252 | 254 | # Additional optional arguments allow you to customize the operation |
253 | 255 | # by overriding various functions and constants used internally. |
254 | 256 | #</p> |
255 | | -procedure m_lupSolve(L,U,p,b,addfun,subfun,mulfun,divfun,addident:0.0) |
| 257 | +procedure m_lupSolve(L,U,p,b,addfun,subfun,mulfun,divfun,addident:0) |
256 | 258 | local n, i, j, y, x |
257 | 259 | /addfun := ::proc("+", 2) |
258 | 260 | /subfun := ::proc("-", 2) |
@@ -346,7 +348,7 @@ procedure m_write(args[]) # Matrices and output files |
346 | 348 | case ::type(arg) of { |
347 | 349 | "file": outfile := arg |
348 | 350 | "list": { # Assume it's a matrix! |
349 | | - every i := !M do { |
| 351 | + every i := !arg do { |
350 | 352 | every ::writes(outfile, !i," ") |
351 | 353 | ::write(outfile) |
352 | 354 | } |
|
0 commit comments