| Register | FAQ | Calendar | Search | Today's Posts | Mark Forums Read |
|
#1
| |||
| |||
| I'm a complete beginner to APL, and I had the following question: Suppose I have a 16x16 matrix of values. How would I set each value in the matrix (starting in the second row) equal to the sum of the matrix element directly above it, and the element to the top-left of it? Essentially, m[x;y]=m[x;y-1]+m[x-1;y-1] But I'm not sure how to express that in APL. I've tried entering just that in APL (with proper symbols, of course), but it doesn't work because x and y are arrays, and I need to access only two single elements of the matrix. |
|
#2
| |||
| |||
| On Dec 24, 6:19*am, Jimmy Miller <CaptainThun...@gmail.com> wrote: > I'm a complete beginner to APL, and I had the following question: > > Suppose I have a 16x16 matrix of values. *How would I set each value > in the matrix (starting in the second row) equal to the sum of the > matrix element directly above it, and the element to the top-left of > it? *Essentially, > > m[x;y]=m[x;y-1]+m[x-1;y-1] > > But I'm not sure how to express that in APL. *I've tried entering just > that in APL (with proper symbols, of course), but it doesn't work > because x and y are arrays, and I need to access only two single > elements of the matrix. I'm a little confused. You state 'matrix element directly above it', which to me would be m[x-1,y]. Also, it isn't completely clear to me the meaning of 'the element to the top-left of it'. Lance |
|
#3
| |||
| |||
| On Dec 24, 3:13 pm, Lance <Lanc...@gmail.com> wrote: > On Dec 24, 6:19 am, Jimmy Miller <CaptainThun...@gmail.com> wrote: > > > I'm a complete beginner to APL, and I had the following question: > > > Suppose I have a 16x16 matrix of values. How would I set each value > > in the matrix (starting in the second row) equal to the sum of the > > matrix element directly above it, and the element to the top-left of > > it? Essentially, > > > m[x;y]=m[x;y-1]+m[x-1;y-1] > > > But I'm not sure how to express that in APL. I've tried entering just > > that in APL (with proper symbols, of course), but it doesn't work > > because x and y are arrays, and I need to access only two single > > elements of the matrix. > > I'm a little confused. You state 'matrix element directly above it', > which to me would be m[x-1,y]. Also, it isn't completely clear to me > the meaning of 'the element to the top-left of it'. > > Lance (1 0↓m)←2+/0,¯1 0↓m ⍝ should do what you asked but the first row and column might not be what you want. |
|
#4
| |||
| |||
| In article <4de20ca0-f5e8-44ee-be1e-43ce7b422eaf@j20g2000hsi.googlegroups.com>, Jimmy Miller <CaptainThunder@gmail.com> wrote: >I'm a complete beginner to APL, and I had the following question: > >Suppose I have a 16x16 matrix of values. How would I set each value >in the matrix (starting in the second row) equal to the sum of the >matrix element directly above it, and the element to the top-left of >it? Essentially, > >m[x;y]=m[x;y-1]+m[x-1;y-1] > >But I'm not sure how to express that in APL. Two possibilities: 1. In a modern APL, something like 16 {x + 0, -1 <drop> x} \ topvector 2. In primitive APL (e.g. APL\360), some thinking shows that there's a magic matrix M, where the result is M +.* topvector. Analysis gets M as a form of Pascal's Triangle, so it can be generated as a 1-liner. Seth |
|
#5
| |||
| |||
| Try : (0,[1]0,1 1 drop M)+(0,[1]1 0 drop M)+M If that is (simply) what you mean ? e.g. Matrix "M" 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 RESULT of above operation 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 18 21 24 27 30 33 36 39 42 45 48 51 54 57 60 63 50 69 72 75 78 81 84 87 90 93 96 99 102 105 108 111 82 117 120 123 126 129 132 135 138 141 144 147 150 153 156 159 114 165 168 171 174 177 180 183 186 189 192 195 198 201 204 207 146 213 216 219 222 225 228 231 234 237 240 243 246 249 252 255 178 261 264 267 270 273 276 279 282 285 288 291 294 297 300 303 210 309 312 315 318 321 324 327 330 333 336 339 342 345 348 351 242 357 360 363 366 369 372 375 378 381 384 387 390 393 396 399 274 405 408 411 414 417 420 423 426 429 432 435 438 441 444 447 306 453 456 459 462 465 468 471 474 477 480 483 486 489 492 495 338 501 504 507 510 513 516 519 522 525 528 531 534 537 540 543 370 549 552 555 558 561 564 567 570 573 576 579 582 585 588 591 402 597 600 603 606 609 612 615 618 621 624 627 630 633 636 639 434 645 648 651 654 657 660 663 666 669 672 675 678 681 684 687 466 693 696 699 702 705 708 711 714 717 720 723 726 729 732 735 |
|
#6
| |||
| |||
| Great holiday puzzle! My take on this is: For every cell C, make a sum of the cell "just above C" and the cell "just left diagonally above" C. Place the sum in C" So, I make the assumption "top left" here means "left diagonally above", and NOT M[1;1] in all cases. As the problem is stated, the first row and the first column becomes special cases: the first row is left intact, and the first column (apart from the first row) is just downshifted one step (I suppose...?). The challenge (if any) may have been to correctly interpret the requirements. Now, that would NEVER happen in a real world situation, right?... ![]() Anyway, here is my attempt, using basically the same mix of dropping and catenating as others have suggested: M (original matrix): 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 M[1;],[1](1 drop M[;1]),0 1 drop (1 0 drop M)+(1 1 drop M),0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 17 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 33 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 49 99 101 103 105 107 109 111 113 115 117 119 121 123 125 127 65 131 133 135 137 139 141 143 145 147 149 151 153 155 157 159 81 163 165 167 169 171 173 175 177 179 181 183 185 187 189 191 97 195 197 199 201 203 205 207 209 211 213 215 217 219 221 223 113 227 229 231 233 235 237 239 241 243 245 247 249 251 253 255 129 259 261 263 265 267 269 271 273 275 277 279 281 283 285 287 145 291 293 295 297 299 301 303 305 307 309 311 313 315 317 319 161 323 325 327 329 331 333 335 337 339 341 343 345 347 349 351 177 355 357 359 361 363 365 367 369 371 373 375 377 379 381 383 193 387 389 391 393 395 397 399 401 403 405 407 409 411 413 415 209 419 421 423 425 427 429 431 433 435 437 439 441 443 445 447 225 451 453 455 457 459 461 463 465 467 469 471 473 475 477 479 Good luck using APL. APL takes the interactive approach to the level where it becomes an "immersive experience". |
![]() |
| Thread Tools | |
| Display Modes | |
In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.