Mathematica 9 is now available
Student Support Forum
-----
Student Support Forum: 'Problems with replacement rules inside functions' topicStudent Support Forum > General > "Problems with replacement rules inside functions"

Next Comment >Help | Reply To Topic
Author Comment/Response
Kate Ross
09/03/10 2:59pm

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!

URL: ,

Subject (listing for 'Problems with replacement rules inside functions')
Author Date Posted
Problems with replacement rules inside functions Kate Ross 09/03/10 2:59pm
Re: Problems with replacement rules inside func... yehuda ben-s... 09/05/10 08:47am
Re: Re: Problems with replacement rules inside ... Kate Ross 09/08/10 11:26am
Next Comment >Help | Reply To Topic