|
[Date Index]
[Thread Index]
[Author Index]
Re: Ploting a changing constant
- To: mathgroup at smc.vnet.net
- Subject: [mg64779] Re: [mg64740] Ploting a changing constant
- From: "David Park" <djmp at earthlink.net>
- Date: Thu, 2 Mar 2006 19:27:52 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
Mary Beth,
y[a_,x_] will work for your purposes. But if you think of the function
really being a function of x and a is a parameter, then y[a_][x_] (not
y[x_][a_]) separates the parameter from the variable. And, as I said in the
posting, you can then simply write the derivative as f[a]'[x]. But it is
just a matter of convenience and whether you want to differentiate between
'parameters' and 'variables'.
Such definitions, by the way, are stored in SubValues of f.
David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/
From: Mary Beth Mulcahy [mailto:Mary.Mulcahy at colorado.edu]
To: mathgroup at smc.vnet.net
Thanks for your response. I was curious if you wouldn't mind saying exactly
how y[x_, a_] is different from y[x_][a_] (note placement of brackets). How
does Mathematica interpret them differently? I somehow picked up the habit of
always defining my functions as the first example and haven't had any trouble.
In a similar example someone else sent me I tried both y[x_, a_] and y[x_]
[a_]. They gave the same result, so maybe there isn't a difference?
Thanks.
Mary Beth
Quoting David Park <djmp at earthlink.net>:
> Mary Beth,
>
> Plot allows a list of functions to plot. This can be generated by Table
but
> you must Evaluate the Table statement.
>
> y[x_, a_] := a x
>
> Plot[Table[y[x, a], {a, 10, 50, 10}] // Evaluate, {x, 0, 33}];
>
> I would like to call 'a' a parameter and I would tend to define such a
> (different) function in the following manner.
>
> Clear[y]
> y[a_][x_] := x^a
>
> Then you can easily write the derivative of the function as...
>
> y[2]'[x]
> 2 x
>
> If you wanted to plot a series of curves with different values of a, but
not
> necessarily evenly spaced, then you could use MapThread. Here is an
example.
>
> Plot[MapThread[y[#][x] &, {{0, 0.2, 0.5, 1, 2, 5}}] // Evaluate, {x, 0,
1},
> Frame -> True];
>
> If you wanted to plot the derivatives then you could use...
>
> Plot[MapThread[y[#]'[x] &, {{0, 0.2, 0.5, 1, 2, 5}}] // Evaluate, {x, 0,
1},
> PlotRange -> {0, 4},
> Frame -> True];
>
--
Department of Chemistry and Biochemistry
University of Colorado
Chemistry 76
Boulder, CO 80309-0215
(303) 492-0579
Prev by Date:
Re: Ploting a changing constant
Next by Date:
Re: Ploting a changing constant
Previous by thread:
Re: Ploting a changing constant
Next by thread:
Re: Ploting a changing constant
|