Re: Manipulating list of functions
- To: mathgroup at smc.vnet.net
- Subject: [mg96331] Re: [mg96276] Manipulating list of functions
- From: "David Park" <djmpark at comcast.net>
- Date: Wed, 11 Feb 2009 05:25:32 -0500 (EST)
- References: <23853518.1234264854681.JavaMail.root@m02>
Istvan,
Many problems in Mathematica could be avoided if all the variables and
parameters of a function were included within the function definition and
not left 'hanging loose'.
It also helps a lot to calculate, define and test required functions outside
of Plot and Manipulate statements.
So I would do your calculation this way.
funcA[a_][z_]:=Sin[z+a];
funcB[a_][z_]:=Cos[z+a];
funcC[a_][z_]:=0;
Manipulate[
Plot[{funcA[a][x],funcB[b][x],funcC[0][x]},{x,1,10},Axes->False,Frame->True]
,
{a,0,1},
{b,0,1}]
There, I actually typed the list into the Plot statement. If we wanted to
precompute the list with different parameters for the functions it becomes
more convoluted.
Clear[funcA,funcB,funcC,funcList];
funcA[a_,b_][z_]:=Sin[z+a];
funcB[a_,b_][z_]:=Cos[z+b];
funcC[a_,b_][z_]:=0;
funcList[a_,b_][x_]=#[a,b][x]&/@{funcA,funcB,funcC}
{Sin[a+x],Cos[b+x],0}
Manipulate[
Plot[funcList[a,b][x]//Evaluate,{x,1,10},Axes->False,Frame->True],
{a,0,1},
{b,0,1}]
David Park
djmpark at comcast.net
http://home.comcast.net/~djmpark/
From: replicatorzed at gmail.com [mailto:replicatorzed at gmail.com]
Dear Group,
I have the following code:
Manipulate[
funcA[z_] := Sin[z + a];
funcB[z_] := Cos[z + b];
funcC[z_] := 0;
funcList = #[x] & /@ {funcA, funcB, funcC};
Plot[funcList, {x, 1, 10}, Axes -> False, Frame -> True],
{a, 0, 1},
{b, 0, 1}
]
It returns the Manipulate panel correctly. What annoys me is the cell
bracket of it that is constantly highlighted, probably because there
is some calculation going on even when I do not move any of the
sliders, due to some function-definitions. I'm afraid I do not fully
understand the cause of it. Nor do I know how to overcome it. Also
what should I do, if I want to move the funcA, funcB, funcC
definitions outside of Manipulate?
Thank you in advance
Istvan