MathGroup Archive 2009

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

Search the Archive

Re: mathematica newbie trouble

  • To: mathgroup at smc.vnet.net
  • Subject: [mg99298] Re: [mg99276] mathematica newbie trouble
  • From: DrMajorBob <btreat1 at austin.rr.com>
  • Date: Sat, 2 May 2009 05:58:34 -0400 (EDT)
  • References: <200905010952.FAA02056@smc.vnet.net>
  • Reply-to: drmajorbob at bigfoot.com

Variable scope. In your first version, you have both global a, b, and c  
(used to calculate s) and local a, b, and c (parameters in k). They're not  
the same, so the function doesn't depend on its arguments.

In the second version, which DOES work, the RHS is evaluated immediately  
(without scoping).

(That requires a, b, and c to be undefined at the time that s and k are  
defined, of course.)

Bobby

On Fri, 01 May 2009 04:52:31 -0500, Guapo <yangshuai at gmail.com> wrote:

> i wrote the following mathematica code:
>
> s := (a + b + c)/2;
> k[a_, b_, c_] := Sqrt[s (s - a) (s - b) (s - c)];
> k[3, 4, 5]
> k[5, 9, 12]
>
> when run it, i can't get the write answer. but i change setDelayed(:=)
> to set(=), everything works ok
>
> s = (a + b + c)/2;
> k[a_, b_, c_] = Sqrt[s (s - a) (s - b) (s - c)];
> k[3, 4, 5]
> k[5, 9, 12]
>
> i did a google search for the difference of set and setDelayed,
> however, i still can't understand it for the upper described problem,
> could anyone explain it? great thanks.
>



-- 
DrMajorBob at bigfoot.com


  • Prev by Date: Re: interactive 3d graphic in a palette?
  • Next by Date: Re: How do I send the palette behind other windows?
  • Previous by thread: mathematica newbie trouble
  • Next by thread: Re: mathematica newbie trouble