       Re: clarification. Re: one liner for a function?

• To: mathgroup at smc.vnet.net
• Subject: [mg45991] Re: clarification. Re: one liner for a function?
• From: "Peltio" <peltio at twilight.zone>
• Date: Mon, 2 Feb 2004 05:20:26 -0500 (EST)
• References: <bvg11r\$qn6\$1@smc.vnet.net>
• Reply-to: "Peltio" <peltioNOSP at Miname.com.invalid>
• Sender: owner-wri-mathgroup at wolfram.com

```"sean kim" wrote

sol = NDSolve[{Derivative[a][t] == -0.1*a[t]*x[t],
Derivative[b][t] == -0.05*b[t]*y[t], Derivative[x][t] ==
-0.1*a[t]*x[t] + 0.05*b[t]*y[t], Derivative[y][t] ==
0.1*a[t]*x[t] - 0.05*b[t]*y[t], a == 1, b == 1,
x == 1, y == 0}, {a, b, x, y}, {t, 0, 250}][];

>(* i can't figure out how to make a function for this one*)
>Show[GraphicsArray [{{pa, pb}, {px, py}}], ImageSize-> 500]

I wrote this before reading this last post, but perhaps you could see some
use in it, nonetheless. Here's my approach: I'd use a procedure to extract
the functions from DSolve's output. While I'm at it I will apply to every
solution a function that changes it into its plot.

plots=toValues[sol,Plot[#[t],{t,0,250},DisplayFunction->Identity]&];

And then I'd use partition (or any other list manipulation command)to
arrange the list of plots the way I'd like to see shown by GraphicsArray:

Show[GraphicsArray[Partition[plots, 2]]]

(you can put everything on a single line, if you wish).

I did not assign the plots to any variable, though, since that was not
necessary to plot the array of graphics. But if you want to have that too
you can use MapThread. I used Array to make things simpler, but you might
extract the names from the list of solution and then apply your
name-generating function, I guess.
This will give the same graphics array as before.
Show[GraphicsArray[Partition[{p, p, p, p}, 2]]]

Hope this helps,
Peltio

PS
Oh, yes!
I almost forgot the procedure toValues (no one-liner, then : ) ):

toValues[li_, fun_:Identity] := Module[
{newli, vars, sols},
sols = First[Dimensions[li]]; vars = Last[Dimensions[li]];
newli = li /. (_ -> v_) -> fun[v];
If[vars == 1, newli = Flatten[newli]];
If[sols == 1, First[newli], newli]
]

It extracts the solutions from a list of rules (the structure it gives to
the new list is based on the behaviour I wanted from Solve's solutions)
applying a function fun to each of them. You might also want to modify
the line
newli = li /. (_ -> v_) -> fun[v];
to make it look like something like
newli = li /. (a_ -> v_) -> Set[buildname[a],fun[v]];
(where buildname is a procedure like the one you wrote that builds a simbol
with the last letter taken from the lhs of the rule).
But this needs a little experimenting to make it work, I guess.

```

• Prev by Date: Dropping Higher Order Terms (from an earlier post)
• Next by Date: Re: clarification. Re: one liner for a function?
• Previous by thread: Dropping Higher Order Terms (from an earlier post)
• Next by thread: Re: clarification. Re: one liner for a function?