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: [mg88612] Re: A Mathematica implementation of SolvOpt
  • From: Ray Koopman <koopman at sfu.ca>
  • Date: Fri, 9 May 2008 07:18:04 -0400 (EDT)
  • References: <g00uq4$gi1$1@smc.vnet.net>

On May 9, 12:34 am, tommcd <TCMcDerm... at gmail.com> wrote:
> Hi,
> I recently uploaded a Mathematica implementation of SolvOpt
> (an implementation of Shor's r algorithm for the minimization of
> nonlinear, possibly non-smooth objective functions) tohttp://www.mathematica-users.org/webMathematica/wiki/wiki.jsp?pageNam...
> The main package is SolvOpt.m, with shorTest.m and the notebook
> SolvOptTest.nb being for demonstration purposes.
> The original (Fortran, C, and other) implementations and documentation
> are available athttp://www.uni-graz.at/imawww/kuntsevich/solvopt/
>
> As this is my 1st mathematica package (I've only ever used notebooks
> interactively before) I'd
> appreciate any suggestions or constructive criticism, especially with
> regard to efficiency and style.
>
> 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.
>
> Regards,
>
> Tom

deltax = h1*ddx*(2*UnitStep[g0] - 1)

will do the whole vector. If you want only elements 1...n then use

deltax[[1;;n]] = h1*ddx*(2*UnitStep[g0[[1;;n]]] - 1)

or

deltax[[Range@n]] = h1*ddx*(2*UnitStep[g0[[Range@n]]] - 1)


  • Prev by Date: Re: TreePlots and GraphPlots
  • Next by Date: PlotLegend not working properly in my Mathematica 6
  • Previous by thread: Re: A Mathematica implementation of SolvOpt
  • Next by thread: Re: A Mathematica implementation of SolvOpt