MathGroup Archive 2011

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

Search the Archive

Re: strange error

  • To: mathgroup at
  • Subject: [mg122326] Re: strange error
  • From: David Bailey <dave at>
  • Date: Tue, 25 Oct 2011 06:17:43 -0400 (EDT)
  • Delivered-to:
  • References: <j7u562$t8q$>

On 22/10/2011 11:16, Klemen Dovrtel wrote:
> Hello everybody,
> I defined a simple function that is composed of three functions, each for different range of argument/variable. The function was composed using If[] conditions. The problem is that i can't FindRoot of this composed function. I get an error "the function value is not a list of numbers with dimensions {1}", which is not true. Any idea how can i solve this?
> Mathematica print screen:
> Best Regards
> Klemen

The problem is that your function 'evaluates' even when its argument is 
not a number (remember that Mathematica can do algebra as well as 
numerics). The following version will fix this:

Test[m_?NumericQ] := Module[{ret},
    If[m <= 100, ret = 2 m];
    If[100 <= m <= 200, ret = 200 + 1 (m - 100)];
    If[200 < m, ret = 300 + 0.5 (m - 200)];

BTW, why not post a link to a notebook containing a problem, rather than 
an image, which requires typing back into a notebook?

David Bailey

  • Prev by Date: Geometric series for matrices
  • Next by Date: Re: Integral points on elliptic curves
  • Previous by thread: Re: strange error
  • Next by thread: Defining a variable from an error message (NDSolve::ndsz)