MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: pattern

  • To: mathgroup at smc.vnet.net
  • Subject: [mg84350] Re: pattern
  • From: "David Park" <djmpark at comcast.net>
  • Date: Thu, 20 Dec 2007 00:02:40 -0500 (EST)
  • References: <3eb7b73d-e7dd-488e-abdc-0d0d1473258d@x69g2000hsx.googlegroups.com> <fkanuj$dlh$1@smc.vnet.net>

Here is an example using a general pattern specification that also includes 
a default value for the matrix:

matfunc[mat : {{_, _}, {_, _}} : {{1, 2}, {3, 4}}] := mat + mat.mat

mat is the name of the pattern.
{{_, _}, {_, _}}  is the pattern
{{1, 2}, {3, 4}} is the default value

and these are all separated by colons. If you don't want a default value 
leave off the last colon and matrix.

It now accepts a 2x2 matrix.

matfunc[{{.5, -1}, {.33, 4.5}}]
{{0.42, -6.}, {1.98, 24.42}}

It does not accept any nonmatching argument.

matfunc[3]
matfunc[3]

And with no argument it uses the default value.

matfunc[]
{{8, 12}, {18, 26}}

-- 
David Park
djmpark at comcast.net
http://home.comcast.net/~djmpark/


<orelang at gmail.com> wrote in message news:fkanuj$dlh$1 at smc.vnet.net...
>I want to define a function that accepts only one argument - a 2x2
> matrix and not any more.
>
> Is it possible?
>
> orelang 



  • Prev by Date: Re: Trouble with double factorial and an infinite product
  • Next by Date: Re: Button Question
  • Previous by thread: Re: pattern
  • Next by thread: Problem with Out keeping the camera view direction