MathGroup Archive 2010

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

Search the Archive

Re: manipulate plot

  • To: mathgroup at smc.vnet.net
  • Subject: [mg107405] Re: [mg107378] manipulate plot
  • From: "David Park" <djmpark at comcast.net>
  • Date: Thu, 11 Feb 2010 08:20:42 -0500 (EST)
  • References: <9045316.1265886382517.JavaMail.root@n11>

Al,

I would hesitate to write a definition like y = m x. It doesn't really
define a function, it doesn't localize parameters and variables to the
function, and it assigns a value to y, which you may want later to use as a
symbol without a value. What happens if somewhere you assign a value to m,
or forgot that you did? It's not the best style. 

It might be more work to write full functional definitions, but it is much
better controlled. It is worth the rather minor extra effort. You could use
SubValues to contain the parameters and then easily write derivatives with
respect to the x variable. So here is one of your examples plotting the
function and its derivative.

f1[a_, b_][x_] := E^((-a + b) x) 

Manipulate[
 Plot[{f1[a, b][x], f1[a, b]'[x]}, {x, 0, 1},
  Frame -> True,
  Axes -> False,
  PlotRange -> {-1.2, 3.2}],
 {a, 0, 1, Appearance -> "Labeled"},
 {b, 0, 1, Appearance -> "Labeled"}]  

I used a Frame without Axes to keep junk off the curves. I also used a fixed
PlotRange that accommodated the variation in the curves. Dynamic plots
should usually be against a fixed background, otherwise it can be very
confusing to the viewer. The same thing with Animation.


David Park
djmpark at comcast.net
http://home.comcast.net/~djmpark/  


From: you can call me al [mailto:misterraum at gmail.com] 


Hi all,
   Often after arriving at the result of some calculation in
Mathematica I have an expression in many variables and would like to
plot the function inside of a manipulate box so that I can observe the
effect of changing the parameters.  To make the discussion here more
concrete let's say I have

y = f(x,a,b)

A natural thing to try to do is something like:

Manipulate[Plot[y,{x,0,1}],{a,0,1},{b,0,1},....]

This of course fails to produce output seemingly because Mathematica
can't understand that f is actually an expression in the variables
x,a, and b.  It seems that the only way to get what I'm after is to go
through a lot of syntactic acrobatics geared at turning the results of
my calculations (which are usually just algebraic expressions) into
some sort of function definition.  This is generally a huge pain in
the ass and also tends to clutter and obfuscate the notebook that I'm
working in.  So....

When I'D LIKE to do this:

y = m x;
Manipulate[Plot[y,{x,0,1}],{{m,1},0,2}];


I MUST INSTEAD do either:

Manipulate[Plot[m x,{x,0,1},PlotRange->{0,2}],{{m,1},0,2}]

-OR-

y = Function[{m,x},m x];
Manipulate[Plot[y[m,x],{x,0,1},PlotRange->{0,2}],{{m,1},0,2}]

-OR-

y[m_,x_] := m x;
Manipulate[Plot[y[m,x],{x,0,1},PlotRange->{0,2}],{{m,1},0,2}]


or god knows what else...

In the example above the problem doesn't seem so bad but when the
expressions become larger functions of more variables and/or I'm
plotting more than one function then the constructs above start to get
unweildly and I start really wondering why there is no support for me
to type something like:

Manipulate[Plot[{f1,f2,f3},{x,0,1}],{a,0,1},{b,0,1}]


RATHER THAN:

Manipulate[Plot[{Exp[-(a-b)*x],Exp[-a*x]Cos[2*Pi*b*x],Exp[-
a*x]*Sin[2*Pi*b*x]},{x,0,1}],{a,0,1},{b,0,1}]

-OR-

f1 = Function[{a,b,x},Exp[-(a-b)*x]];
f2 = Function[{a,b,x},Exp[-a*x]Cos[2*Pi*b*x]];
f3 = Function[{a,b,x},Exp[-a*x]Cos[2*Pi*b*x]];
Manipulate[Plot[f1[a,b,x],f2[a,b,x],f3[a,b,x]},{x,0,1}],{a,0,1},{b,
0,1}]

-OR-

f1[a_,b_,x_] = Exp[-(a-b)*x];
f2[a_,b_,x_] = Exp[-a*x]Cos[2*Pi*b*x];
f3[a_,b_,x_] = Exp[-a*x]Cos[2*Pi*b*x];
Manipulate[Plot[f1[a,b,x],f2[a,b,x],f3[a,b,x]},{x,0,1}],{a,0,1},{b,
0,1}]


I've often wondered if there is something I don't know about this.  If
there are any tricks out there to simplify the use of the
Manipulate[Plot[{my_algebraic_results},{x,0,1}],my_parameters]
construct i'd really love to hear them.  I think the Manipulate
functionality is VERY attractive but i'm always VERY frustrated that I
usually have to bend over backwards to operate it in anything but the
simplest context.

Thanks in advance,

hopeful




  • Prev by Date: Re: manipulate plot
  • Next by Date: Re: hi, how can i accomplish this densityplot?
  • Previous by thread: Re: manipulate plot
  • Next by thread: How to scope PopupMenu values in a DynamicModule?