Services & Resources / Wolfram Forums / MathGroup Archive

MathGroup Archive 2001

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

Search the Archive

RE: variables versus functions

  • To: mathgroup at
  • Subject: [mg28814] RE: [mg28797] variables versus functions
  • From: "David Park" <djmp at>
  • Date: Mon, 14 May 2001 01:33:06 -0400 (EDT)
  • Sender: owner-wri-mathgroup at


If all you wanted to do is use FindRoot on that particular expression, then
both methods are equivalent. But if you are not totally certain of all you
want to do with these expressions, then defining functions leaves the door
open to more variations.

A = Cos[x];
B = ArcTan[x];
FindRoot[A == B, {x, Pi/2}]
{x -> 0.8165412261934498}

Clear[A, B];
A[x_] := Cos[x];
B[x_] := ArcTan[x];

Now you can do things like the following.

FindRoot[A[y] == B[y + 0.1], {y, Pi/2}]
{y -> 0.7715169115729875}

f[y_] := 0.2 + 0.9*y
FindRoot[A[f[y]] == B[f[y] - 0.1], {y, Pi/2}]
{y -> 0.7353827191649621}

Defining functions with formal parameters is usually the better path to
take, even though you can often get by without it. I'm interested in seeing
other answers you may get on this question.

David Park
djmp at

> From: Julian Sweet [mailto:jsweet at]
To: mathgroup at
> 	How is it different to define a variable such as A=Cos[x]
> versus a function  A[x_]:=Cos[x] ?
> Furthermore, what If I define two functions  A[x_]:=Cos[x] and
> B[x_]=ArcTan[x]?  How would FindRoot[A==B,{x,pi/2}]  treat this
> differently than if I just used variable definitions for A & B?
> e-mail response appreciated: jsweet at

  • Prev by Date: RE: column * row ??
  • Next by Date: Re: Decimal math bug?
  • Previous by thread: Re: variables versus functions
  • Next by thread: don't understand #