Deconvolution/1D: Difference between revisions

→‎{{header|REXX}}: added the REXX computer programming language.
m (→‎{{header|Perl 6}}: fixed 'trim_system')
(→‎{{header|REXX}}: added the REXX computer programming language.)
Line 1,090:
#<array '#(16 1) #[-3 -6 -1 8 -6 3 -1 -9 -9 3 -2 5 2 -2 -7 -1]>
</lang>
 
=={{header|REXX}}==
<lang rexx>/*REXX pgm performs deconvolution of two arrays: deconv(g,f)=h and deconv(g,h)=f */
call make@ 'H', "-8 -9 -3 -1 -6 7"
call make@ 'F', "-3 -6 -1 8 -6 3 -1 -9 -9 3 -2 5 2 -2 -7 -1"
call make@ 'G', "24 75 71 -34 3 22 -45 23 245 25 52 25 -67 -96 96 31 55 36 29 -43 -7"
call show@ 'H' /*display the elements of array H. */
call show@ 'F' /* " " " " " F. */
call show@ 'G' /* " " " " " G. */
call deco@ 'G', "F", 'X' /*deconvolution of G and F ───► X */
call test@ 'X', "H" /*test: is array H equal to array X?*/
call deco@ 'G', "H", 'Y' /*deconvolution of G and H ───► Y */
call test@ 'F', "Y" /*test: is array F equal to array Y?*/
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
deco@: parse arg $1,$2,$R /*obtain the arguments. */
f#=@.$2.? + 1; g#=@.$1.? + 1 /*get size of array 1&2.*/
@.$R.?=g# - f# /*size of return array. */
do n=0 to g#-f# /*define return array. */
@.$R.n=@.$1.n /*define RETURN element.*/
if n<f# then L=0 /*define the variable L.*/
else L=n - f# + 1 /* " " " " */
if n>0 then do i=L to n-1; _=n-i /*define elements > 0. */
@.$R.n=@.$R.n - @.$R.i * @.$2._ /*compute " " " */
end /*i*/ /* [↑] subtract product.*/
@.$R.n=@.$R.n / @.$2.0 /*divide array element. */
end /*n*/; return
/*──────────────────────────────────────────────────────────────────────────────────────*/
make@: parse arg $,z; @.$.?=words(z) - 1 /*obtain args; set size.*/
do j=0 to @.$.?; @.$.j=word(z,j+1) /*define array element. */
end /*j*/; return /*array starts at unity.*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
show@: parse arg $,z,_; do j=0 to @.$.? /*obtain the arguments. */
_=strip(_ @.$.j) /*create array list. */
end /*j*/ /* [↑] build the list. */
say 'array' $": "_; return /*show the list; return*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
test@: parse arg $1,$2; do j=0 to max(@.$1.?, @.$2.?) /*obtain the arguments. */
if @.$1.j=@.$2.j then iterate /*create array list. */
say "***error*** arrays" $1 ' and ' $2 "aren't equal."
end /*j*/; return /* [↑] build the list.*/</lang>
{{out|output|text=&nbsp; when using the default internal inputs:}}
<pre>
array H: -8 -9 -3 -1 -6 7
array F: -3 -6 -1 8 -6 3 -1 -9 -9 3 -2 5 2 -2 -7 -1
array G: 24 75 71 -34 3 22 -45 23 245 25 52 25 -67 -96 96 31 55 36 29 -43 -7
</pre>
 
=={{header|Tcl}}==