PL/I CAN 14
From: robin (robin_v_at_bigpond.mapson.com)
Date: 12/31/03
- Previous message: Greg Lindahl: "Re: Complex IF statements"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 31 Dec 2003 07:56:07 GMT
> 14. CANT provide generic matrix function support for ALL operations shown
> with matching outputs.
FALSE. THIS HAS BEEN DEMONSTRATED TO FRANK TWICE BEFORE, IN TWO VERSIONS.
demo_SOME_matrix_operations:
proc options (main);
dcl n fixed binary;
do n = 5 to 3 by -1;
if n > 3 then iterate;
begin;
dcl a(n,n) fixed binary,
d(n) fixed bin defined a(1sub, 1sub),
at(n,n) fixed bin defined a(2sub, 1sub),
ut (n*(n+1)/2) fixed bin defined a(n*(1sub-1)-1sub*(1sub-1)/2+2sub)),
(i, j, w value (2) ) fixed bin;
a = reshape ((i do i = 1 to n*n), (n,2));
put (a);
put skip edit ( 'matrix a', a) (r(f91));
put skip edit ( 'transpose a', at) (r(f91));
put skip edit ( 'upper triangle a' ) (r(f92));
put skip edit (ut) (r(f93)); /* output upper triangle no explicit loops * /
put skip edit ( 'diagonal d= ', d ) (r(f92));
put skip edit ( 'dot product d x a(:,1)= ', dot_product(d,a(*,1)) ) (r(f94));
put skip edit ( 'matrix multiply d x a= ', matmul(d,a) ) (r(f92));
put skip edit ( 'sum, product matrix a= ', sum(a), ', ', prod(a) ) (r(f94));
f91: format (a, skip, 2((n)(f(0),X(1)), skip),(n)(f(0),X(1)));
f92: format (a,(n)(f(0),X(1)));
f93: format ((n) f(w), col(w+1), (n-1) f(w), col(2*w+1), f(w), (n-2) f(w), col(3*w+1),
(n-3) f(w), col(4*w+1), f(w));
f94: format (2(a,f(0)));
end;
end;
end;
> ! -----------------------
> program demo_SOME_matrix_operations
> integer,allocatable :: d(:), a(:,:)
> do n = 5,3,-1
> if (n /= 3) cycle ! skip a(5,5), a(4,4) outputs
> allocate (d(n), a(n,n))
> a = reshape( [(i,i=1,n*n)], [n,2]) ! init. 2d array with 1:n*n
> forall (i=1:n) d(i) = a(i,i) ! get diagonal
> write (*,91) 'matrix a', a
> write (*,91) 'transpose a', transpose(a)
> write (*,92) 'upper triangle a'
> write (*,93) (a(i:,i),i=1,n) ! output upper triangle 1 loop
> write (*,92) 'diagonal d= ', d
> write (*,94) 'dot product d x a(:,1)= ', dot_product(d,a(:,1))
> write (*,92) 'matrix multiply d x a= ', matmul(d,a)
> write (*,94) 'sum, product matrix a= ', sum(a),', ',product(a)
> end do
> 91 format (a/,<n>(<n>I2/))
> 92 format (a,<n>(I0,1x))
> 93 format (<i*2-2>x,<n+1-i>I2)
> 94 format (2(a,I0))
> end program
> Outputs:
> matrix a
> 1 2 3
> 4 5 6
> 7 8 9
> transpose a
> 1 4 7
> 2 5 8
> 3 6 9
> upper triangle a
> 1 2 3
> 5 6
> 9
> diagonal d= 1 5 9
> dot product d x a(:,1)= 38
> matrix multiply d x a= 38 83 128
> sum, product matrix a= 45, 362880
- Previous message: Greg Lindahl: "Re: Complex IF statements"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]