Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.postscript > #1247 > unrolled thread
| Started by | luser- -droog <mijoryx@yahoo.com> |
|---|---|
| First post | 2013-02-09 11:27 -0800 |
| Last post | 2013-02-10 12:00 -0700 |
| Articles | 4 — 3 participants |
Back to article view | Back to comp.lang.postscript
three by three and two by two rode the six hundred luser- -droog <mijoryx@yahoo.com> - 2013-02-09 11:27 -0800
Re: three by three and two by two rode the six hundred luser- -droog <mijoryx@yahoo.com> - 2013-02-09 12:41 -0800
Re: three by three and two by two rode the six hundred John Reiser <jreiserfl@comcast.net> - 2013-02-10 10:48 -0800
Re: three by three and two by two rode the six hundred Don Lancaster <don@tinaja.com> - 2013-02-10 12:00 -0700
| From | luser- -droog <mijoryx@yahoo.com> |
|---|---|
| Date | 2013-02-09 11:27 -0800 |
| Subject | three by three and two by two rode the six hundred |
| Message-ID | <f4c62c70-c7fc-479c-8b1e-cfbe8be59e96@googlegroups.com> |
Here are two versions of a function to compute 2x2 or 3x3 determinants.
%!
/signalerror where{pop}{/signalerror/.error load def}ifelse
/det {
dup length 1 index 0 get length ne { /det cvx /typecheck signalerror } if
dup length 2 eq {
aload pop exch aload pop 3 2 roll aload pop % a b c d
4 3 roll mul 3 1 roll % ad b c
mul sub % ad-bc
}{
dup 0 get 0 get % M m00
[ 2 index dup 1 get 1 2 getinterval exch % M m00 [ m1,1-2 M
2 get 1 2 getinterval % M m00 [ m1,1-2 m2,1-2
] det mul % M m00*det(m1-2,1-2)=A
1 index 1 get 0 get % M A m10
[ 3 index dup 0 get 1 2 getinterval exch % M A m10 [ m0,1-2 M
2 get 1 2 getinterval % M A m10 [ m0,1-2 m2,1-2
] det mul sub % M A-B
1 index 2 get 0 get % M A-B m20
[ 3 index dup 0 get 1 2 getinterval exch % M A-B m20 [ m0,1-2 M
1 get 1 2 getinterval % M A-B m20 [ m0,1-2 m1,1-2
] det mul add % M A-B+C
exch pop % A-B+C
} ifelse
} def
/elem { % M i j
3 1 roll get exch get % M_i_j
} def
/det {
dup length 1 index 0 get length ne { /det cvx /typecheck signalerror } if
1 dict begin /M exch def
M length 2 eq {
M 0 0 elem
M 1 1 elem mul
M 0 1 elem
M 1 0 elem mul sub
}{
M length 3 eq {
M 0 0 elem
%[ [ M 1 1 elem M 1 2 elem ] [ M 2 1 elem M 2 2 elem ] ] det
M 1 1 elem
M 2 2 elem mul
M 1 2 elem
M 2 1 elem mul sub
mul
M 0 1 elem
%[ [ M 1 0 elem M 1 2 elem ] [ M 2 0 elem M 2 2 elem ] ] det
M 1 0 elem M 2 2 elem mul
M 1 2 elem M 2 0 elem mul sub
mul sub
M 0 2 elem
%[ [ M 1 0 elem M 1 1 elem ] [ M 2 0 elem M 2 1 elem ] ] det
M 1 0 elem M 2 1 elem mul
M 1 1 elem M 2 0 elem mul sub
mul add
}{ /det cvx /rangecheck signalerror } ifelse
} ifelse
end
} def
[toc] | [next] | [standalone]
| From | luser- -droog <mijoryx@yahoo.com> |
|---|---|
| Date | 2013-02-09 12:41 -0800 |
| Message-ID | <23a94eff-39bd-47f8-8150-5986f63bf270@googlegroups.com> |
| In reply to | #1247 |
On Saturday, February 9, 2013 1:27:42 PM UTC-6, luser- -droog wrote:
> Here are two versions of a function to compute 2x2 or 3x3 determinants.
>
A little less ugly. mat.ps available at http://code.google.com/p/xpost/downloads/detail?name=mat.ps
(mat.ps)run
/elem { % M i j
3 1 roll get exch get % M_i_j
} def
/det {
dup length 1 index 0 get length ne { /det cvx /typecheck signalerror } if
1 dict begin /M exch def
M length 2 eq {
M 0 0 elem
M 1 1 elem mul
M 0 1 elem
M 1 0 elem mul sub
}{
M length 3 eq {
M aload pop cross dot
}{ /det cvx /rangecheck signalerror } ifelse
} ifelse
end
} def
[toc] | [prev] | [next] | [standalone]
| From | John Reiser <jreiserfl@comcast.net> |
|---|---|
| Date | 2013-02-10 10:48 -0800 |
| Message-ID | <XqqdnfvTSO_QdorM4p2dnAA@giganews.com> |
| In reply to | #1248 |
> M length 3 eq {
> M aload pop cross dot
That's very close to being written in APL.
--
[toc] | [prev] | [next] | [standalone]
| From | Don Lancaster <don@tinaja.com> |
|---|---|
| Date | 2013-02-10 12:00 -0700 |
| Message-ID | <anq93dF8hlqU1@mid.individual.net> |
| In reply to | #1248 |
On 2/9/2013 1:41 PM, luser- -droog wrote:
> On Saturday, February 9, 2013 1:27:42 PM UTC-6, luser- -droog wrote:
>> Here are two versions of a function to compute 2x2 or 3x3 determinants.
>>
>
> A little less ugly. mat.ps available at http://code.google.com/p/xpost/downloads/detail?name=mat.ps
>
>
> (mat.ps)run
>
> /elem { % M i j
> 3 1 roll get exch get % M_i_j
> } def
>
> /det {
> dup length 1 index 0 get length ne { /det cvx /typecheck signalerror } if
> 1 dict begin /M exch def
> M length 2 eq {
> M 0 0 elem
> M 1 1 elem mul
> M 0 1 elem
> M 1 0 elem mul sub
> }{
> M length 3 eq {
> M aload pop cross dot
> }{ /det cvx /rangecheck signalerror } ifelse
> } ifelse
> end
> } def
>
Gauss Jordan reduction is vastly better than determinents for most
equation solving.
< http://www.tinaja.com/glib/gaussjor.pdf >
--
Many thanks,
Don Lancaster voice phone: (928)428-4073
Synergetics 3860 West First Street Box 809 Thatcher, AZ 85552
rss: http://www.tinaja.com/whtnu.xml email: don@tinaja.com
Please visit my GURU's LAIR web site at http://www.tinaja.com
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.postscript
csiph-web