       Re: Mantain unevaluated

• To: mathgroup at smc.vnet.net
• Subject: [mg14601] Re: Mantain unevaluated
• From: "Allan Hayes" <hay at haystack.demon.co.uk>
• Date: Mon, 2 Nov 1998 01:51:08 -0500
• References: <71bjc0\$pn0@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```Guillermo de Paz wrote in message <71bjc0\$pn0 at smc.vnet.net>...
>I'm using Mathematica to obtain the differential equations of some
>mechanical systems and to integrate them numerically. When constructing
>the equations I need to invert a matrix. This matrix is not very big
>(lets say 8x8) but the elements al very long trigonometric expressions,
>the inverse takes a long time. By the other side, it is possible that
>for some values of the dependent variables the rank of the matrix is
>not complete, and the size of the problem decreases. For these reasons
>I would like to have unevaluated this inverse until the numerical
>function NDSolve uses it (not to compute symbolically the matrix, but
>compute it numerically inside NDSolve in each integration step).
>I have done some attempts with := and with Compile, but I cant avoid the
>symbolic  computation of the inverse. Could somebody help me?
>
>Guillermo de Paz
>e-mail: guipaz at dali.eis.uva.es
>
>
Guillermo,

Suggestion:

With
mat = {{Sin[x], Cos[x]}, {x, x^2}};

Define an variant of Inverse that evaluates only if the matrix is
numeric.

InverseN[mat_?(MatrixQ[#, NumberQ] &)] := Inverse[mat];

Then we get

InverseN[mat]

InverseN[{{Sin[x], Cos[x]}, {x, x^2}}]

But if x has a numerical value, say

x = 1.2;

we get

InverseN[mat]

{{1.58711, -0.399377}, {-1.3226, 1.02726}}

Allan

---------------------
Allan Hayes
Mathematica Training and Consulting
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565

```

• Prev by Date: Re: spaces in notebook
• Next by Date: Discontinuity of theta functions
• Previous by thread: Re: spaces in notebook
• Next by thread: RE: Mantain unevaluated