Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2009

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

Search the Archive

Re: Re: Manipulating list of functions

  • To: mathgroup at smc.vnet.net
  • Subject: [mg96847] Re: [mg96802] Re: [mg96316] Manipulating list of functions
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Thu, 26 Feb 2009 07:54:06 -0500 (EST)
  • Reply-to: hanlonr at cox.net

Functions must have arguments to be evaluated. Corrections plus some bells and whistles:

Manipulate[Block[
  {initialinvestment, nbrshares, profit, totalofholding, funcList},
  initialinvestment := 100000;
  nbrshares[buyprice_] := initialinvestment/buyprice;
  profit[buyprice_] := (finalprice - buyprice)*nbrshares[buyprice];
  totalofholding[buyprice_] := profit[buyprice] + initialinvestment;
  funcList := 
   Tooltip[#[x], #] & /@ {nbrshares, profit, totalofholding};
  Plot[Evaluate[funcList], {x, 4, 7},
   Epilog -> {Text[#[initialprice], {initialprice, #[initialprice]},
        {Sign[initialprice - 5.5], -2}] & /@
      {nbrshares, profit,
        totalofholding},
     Red, AbsolutePointSize[3],
     Point[{initialprice, #[initialprice]} & /@
       {nbrshares, 
        profit, totalofholding}]},
   Axes -> False,
   Frame -> True,
   FrameLabel -> {Style["Buy Price", 12]},
   PlotRange -> {0, 650000},
   ImageSize -> 500]],
 {{initialprice, 5.5, "Buy Price"}, 4, 7, 0.01},
 {{finalprice, 20}, 16, 24, 1}]


Bob Hanlon

---- Syd Geraghty <sydgeraghty at me.com> wrote: 

=============
Hi all,

we recently had a thread regarding manipulating a list of functions  
which worked fine:-

Manipulate[Block[{funcA, funcB, funcC, funcList},
   funcA[z_] := Sin[z + a];
   funcB[z_] := Cos[z + b];
   funcC[z_] := funcA[z] + funcB[z];
   funcList = #[x] & /@ {funcA, funcB, funcC};
   Plot[Evaluate[funcList], {x, 1, 10}, Axes -> False, Frame ->  
True]], {a, 0,
   Pi}, {b, 0, Pi}]

I have tried what I thought would be a trivial a variant of this for  
very simple functions:

Manipulate[
  Block[{initialinvestment, nbrshares, profit, totalofholding,  
funcList},
   initialinvestment := 100000;
   nbrshares[buyprice_] := initialinvestment/buyprice;
   profit[buyprice_] := (finalprice - buyprice)*nbrshares;
   totalofholding := profit + initialinvestment;
   funcList := #[x] & /@ {nbrshares, initialinvestment, profit,  
totalofholding};
   Plot[Evaluate[funcList], {x, 4, 7}, Axes -> False, Frame -> True,
    PlotRange -> {0, 650000}]], {finalprice, 16, 24, 1}]

However I only get the nbrshares plotted, after several attempts I  
cannot get the desired output and would appreciate advice as to why  
the simpler function specifications lead to failure.

It appears that unless the functions all contain explicit references  
such as to "z" in the first working example then they are omitted.


Thanks in advance ... Syd

Syd Geraghty B.Sc, M.Sc.

sydgeraghty at mac.com

Mathematica 7.0.0 for Mac OS X x86 (64 - bit) (21st November, 2008)
MacOS X V 10.5.6
MacBook Pro 2.33 GHz Intel Core 2 Duo  2GB RAM




  • Prev by Date: Re: Counting Categories
  • Next by Date: Re: Counting Categories
  • Previous by thread: Re: Manipulating list of functions
  • Next by thread: Re: Manipulating list of functions