MathGroup Archive 2004

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

Search the Archive

RE: Re: problems with FindRoot: what worked with 4.2 does not work with 5.0

  • To: mathgroup at smc.vnet.net
  • Subject: [mg47421] RE: [mg47380] Re: problems with FindRoot: what worked with 4.2 does not work with 5.0
  • From: "kimsj" <kimsj at mobile.snu.ac.kr>
  • Date: Sun, 11 Apr 2004 04:44:00 -0400 (EDT)
  • Reply-to: <kimsj at mobile.snu.ac.kr>
  • Sender: owner-wri-mathgroup at wolfram.com

> FindRoot[temp[x]==5,{x,8}]
Or just

  FindRoot[test[x]==5,{x,8}]

since we have defined test[x_] but not temp[x_] in this case.

Br,
- James Sungjin Kim (kimsj at mobile.snu.ac.kr) 
-----Original Message-----
From: Gareth J. Russell [mailto:gjr2008 at columbia.edu] 
To: mathgroup at smc.vnet.net
Subject: [mg47421] [mg47380] Re: problems with FindRoot: what worked with 4.2 does not
work with 5.0

In <c4u3gg$9l6$1 at smc.vnet.net> Edgar Dachs wrote:
> 
> I have written a Mathematica program called PET (Petrological 
> elementary  tools) for Mathematica (Dachs, 1998, Computers & 
> Geosciences, 24/3: 219-235) und worked out a  new version that I 
> tested with Mathematica version 4.2. With 5.0, I now  find problems 
> that several of my functions do not work any more,  obviously do to 
> changes that have been employed between 4.2 and 5.0  concerning 
> FindRoot. Below is a little test-function that illustrates the problem: 
> the  return-value of the function depends on the value of x, as in the 
> much  more complex petrological functions that I have written, where 
> calculations depend e.g. on the value of the temperature.
> 
> test[x_] := Module[{y},
> If[x > 0, y = x + 1];
> If[x <= 0, y = x - 1];
> Return[y]
>]
> With 4.2 FindRoot (using two startin values for x) could have been 
> used  to solve for a special value, e.g.
>
> FindRoot[test[x] == 5, {x, {8, 9}}]
> 
> with the obvious result: {x -> 4.}
> 
> With 5.0 the call
> 
> FindRoot[test[x] == 5, {x, 9}]
> 
> (only one starting value can be specified with 5.0) yields the error 
> message: FindRoot::nlnum "the function value {..} is not a list of 
> numbers with dimension {1} at {x} = {9}
> 
> I would be grateful if someone could help me solving this problem, at 
> the moment I don't know what to do, but it looks like a compatibility 
> problem between Mathematica versions 4.2 and 5.0.
> 
> Thanks in advance,
> 
> Dr. Edgar Dachs
> Department of Mineralogy
> University Salzburg
> Austria

Edgar,

I'm not sure why it worked in v4 and failed in v5, but your coding of 
the If statement is a bit unorthodox. If you rewrite thus:

test[x_] := Module[{y},
    y = If[x > 0, x + 1, x - 1];
    Return[y]
]    ]

It works.

In[34]:=
FindRoot[temp[x]==5,{x,8}]

Out[34]=
{x->4.}

This particular piece of code could, of course, be written

test[x_] := If[x > 0, x + 1, x - 1]

Gareth Russell
Columbia University



  • Prev by Date: Re: Adding hyperlinks to help browser files in function::usage
  • Next by Date: RE: Re: Why do two equivalent expression give different answers?
  • Previous by thread: Re: problems with FindRoot: what worked with 4.2 does not work with 5.0
  • Next by thread: NDelaySolve, NDelayDSolve