Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2008

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

Search the Archive

Re: A Mathematica implementation of SolvOpt

  • To: mathgroup at smc.vnet.net
  • Subject: [mg88621] Re: A Mathematica implementation of SolvOpt
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
  • Date: Sat, 10 May 2008 06:51:43 -0400 (EDT)
  • Organization: The Open University, Milton Keynes, UK
  • References: <g00uq4$gi1$1@smc.vnet.net>

tommcd wrote:

[snip]

> For example I'd like a more efficient and elegant way to express
> Do[
>    deltax[[j]] = If[  g0[[j]] >= 0.0, h1*ddx, -h1*ddx]
> , {j,n}
> ];
> 
> which in Fortran 95 can be written very clearly as
> 
> Where(g0 >= 0.0)
>     g0 = h1*ddx
> ElseWhere
>     g0 = -h1*ddx
> End Where
> 
> where g0 can be any array of up to 7 dimensions, & any number of array
> assignments
> can appear in each section (not just the one shown here), moreover the
> 'Where' can itself
> be nested inside another where etc.. For now a construct which works
> for the 1D list above
> and avoids the do loop would be fine, though if there is a general
> method for masked array assignments in Mathematica I love to hear
> about it.

Tom,

You could use higher level built-in functions such as *Sign[]*, 
*DiracDelta[]*, *UnitStep[]*, etc., functions that automatically thread 
over lists and returned integer values in the range [-1, 1] (the actual 
values depend on the function used) for each element of the lists.

Here is an example with *Sign[]*

g0 = {{{1, -2}, {3, -4, 5}}, {{6, -7, -8, -9}, 10}};
h1 = 12;
ddx = 1/2;
deltax = h1*ddx*Sign[g0]

{{{6, -6}, {6, -6, 6}}, {{6, -6, -6, -6}, 6}}

Regards,
-- Jean-Marc


  • Prev by Date: issues with unit package
  • Next by Date: Re: Display commands in a package
  • Previous by thread: Re: A Mathematica implementation of SolvOpt
  • Next by thread: Manipulate Hints, Tips, Tricks