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

MathGroup Archive 2010

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

Search the Archive

Problems with replacement rules inside functions

  • To: mathgroup at smc.vnet.net
  • Subject: [mg112215] Problems with replacement rules inside functions
  • From: Kate Ross <rosska2 at mcmaster.ca>
  • Date: Sun, 5 Sep 2010 05:26:56 -0400 (EDT)

Hi!

I am working on a problem that involves fitting a Mathematica calculation to
some data. To do this, I am trying to create a function (called
"spinwavecalc") that contains all of the necessary calculations based on the
input parameters J1 through J4. The end of this function calculates the
square of the difference between the calculation and the data.
I want to put this function into NMinimize like so:

NMinimize(spinwavecalc, {J1,J2,J3,J4});

spinwavecalc is a large function so I will show you the sorts of problems
I'm having with the simple example below:

test3 := (Print[J1]; J1 + J2 + J3 + J4;);
test3 /. {J1 -> -0.1, J2 -> -0.1, J3 -> 0, J4 -> 0}

The output of this is "J1". The replacement rule does not seem to apply to
the Print command. My trouble is in understanding when the replacement rule
will work and when it won't. If I remove the Print command, the output is as
expected (-0.2).

Any insights would be greatly appreciated!



  • Prev by Date: Re: Question about ArrayFlatten
  • Next by Date: Re: problem with RandomInteger
  • Previous by thread: Re: user-defined functions in KeyEventTranslations.tr
  • Next by thread: NDSolve -- indexing of dependent variable that is arbitrary list