[Date Index]
[Thread Index]
[Author Index]
Re: how to build pattern for a square matrix of reals?
*To*: mathgroup at smc.vnet.net
*Subject*: [mg98592] Re: how to build pattern for a square matrix of reals?
*From*: sagrailo at gmail.com
*Date*: Mon, 13 Apr 2009 03:36:50 -0400 (EDT)
*References*: <grhp95$mj7$1@smc.vnet.net> <grkgmm$6kq$1@smc.vnet.net>
On Apr 12, 9:46 am, DrMajorBob <btre... at austin.rr.com> wrote:
> You called l a "lower diagonal vector" and u an "upper diagonal vector" --
> neither of which makes any sense. Only matrices, not vectors, can be upper
> or lower diagonal.
>
> I also noticed that you want 0 (an integer) to be treated as if it were
> Real.
>
> So here's a rendition of your "TridiagonalSolve":
>
> tridiagonal[___] := False
> tridiagonal[lower : {0 | 0., __Real}, d : {__Real},
> upper : {__Real, 1 | 1.}, b : {__Real}] /;
> Equal @@ Length /@ {lower, d, upper, b} := True
>
> Notice I'd never, EVER use "l" as a variable name, as it's
> indistinguishable from "1" for many of us. I used the "lower" and "upper"
> names because you're thinking of them that way, even though vectors can't
> physically BE lower or upper.
>
> And here's a replacement for the second line of code, where I would NOT
> redefine the built-in Solve:
>
> realQ[0] = True;
> realQ[x_] := MatchQ[x, _Real]
> realQ[_] = False;
> commensurable[a_ /; MatrixQ[a, realQ], b : {__Real}] /;
> Union@Dimensions@a == {Length@b} := True
> commensurable[__] = False;
>
> Bobby
>
>
>
> On Sat, 11 Apr 2009 02:52:47 -0500, <sagra... at gmail.com> wrote:
> > Once again: big thanks to all who replied! I think I'm able now to
> > fully get what I wanted.
>
> > I guess it would be better if I explained initially what is all about:
> > I have some simple Fortran routines for solving tri-diagonal, and then
> > regular, system of linear equations, that I'm wrapping, through
> > Mathlink, for use from Mathematica. I want Mathematica to do arguments
> > checking for me, and this could be achieved through specifying
> > corresponding patterns for functions signature in the MathLink
> > template file.
>
> > So, my functions are:
> > TridiagonalSolve[l, d, u, b] - for tridiagonal solver
> > Solve[A, b] - for regular solver
> > If the dimension of system is n in both cases, then here:
> > l - lower diagonal vector, of size n, with first element set to 0
> > d - diagonal vector, of size n
> > u - upper diagonal vector, of size n, with last element set to 0
> > b - right-side vector, of size n
> > A - matrix of the system, of size nxn
>
> > So, I want to check that dimensions of all vectors match, for
> > tridiagonal solver function, and also that vector l has 0 as first,
> > and vector u has 0 as last element. Also, for regular solver
> > function, I want to check that dimensions of system matrix, and the
> > length of the right-side vector match. Of course, I also want to
> > check that A is matrix of reals, and that l, d,u and b are vectors of
> > reals. So here are final patterns I came up with (these seem to work
> > fine, but I'd appreciate any further suggestions on improvement):
>
> > TridiagonalSolve[l_/;(VectorQ[l,MatchQ[#,_Real]&]&&l[[1]]
> > ==0),d_/;VectorQ[d,MatchQ[#,_Real]&],u_/;(VectorQ[u,MatchQ[#,_Real]&]
> > &&u[[-1]]==0),b_/;VectorQ[b,MatchQ[#,_Real]&]]/;Length[l]==Length[d]
> > ==Length[u]==Length[b]:="OK"
>
> > Solve[A_/;(MatrixQ[A,MatchQ[#,_Real]&]&&Equal@@Dimensions
> > [A]),b_/;VectorQ[b,MatchQ[#,_Real]&]]/;Dimensions[A][[2]]==Length
> > [b]:="OK"
>
> > Regards.
>
> --
> DrMajor... at bigfoot.com
Thanks for comments.
As for names used, I have these routines in a package of mine, and I
use
different names anyway, so I haven't noticed name clashing issue with
built-in "Solve"; I used above names just as an example.
As for "lower/upper tridiagonal vector": indeed terms are meaningless,
and I apologize for this too - it is one of these occasions when
non-native English speaker translates terms from his own language
verbatim.
As for using or not the name "l" as an argument/variable name - I
consider this nitpicking these days. It could have been argued back
then in the time of terminals and small resolution fonts, but today
with
my Mathematica or Emacs font, these characters look different, and
more
importantly, if you put "1" in the place of "l" above, Mathematica
won't
italicize, nor color it, so it's quite distinguishable.
Finally - the most important note: Google interface, that I'm using
for
sending, is breaking lines on its own, so before eventually trying to
cut-and-paste expressions I wrote in my previous message, please just
remove *all* blanks within them.
Regards.
Prev by Date:
**How to evaluate a notebook programmatically?**
Next by Date:
**Uninstalling Mathematica from Linux**
Previous by thread:
**Re: Re: how to build pattern for a square matrix of reals?**
Next by thread:
**Hyperlinks**
| |