[Date Index]
[Thread Index]
[Author Index]
Re: Function of list of functions
*To*: mathgroup at smc.vnet.net
*Subject*: [mg104107] Re: Function of list of functions
*From*: Bob Hanlon <hanlonr at cox.net>
*Date*: Mon, 19 Oct 2009 07:13:26 -0400 (EDT)
*Reply-to*: hanlonr at cox.net
Your approach is tailored to a specific case. Recommend that you take a more generalized approach.
L = Array[a, {3, 3}];
FuncTestList[n_, v_] := L[[n, v]]
FunRes[v_] := Table[FuncTestList[i, v], {i, 1, 3}]
These two definitions can be replaced by a single definition that does not depend on the specific array nor a specific array length. Use either of these two definitions
FunRes2[a_?MatrixQ, n_Integer?Positive] :=
Flatten[a[[All, {n}]]] /; n <= Length[a[[1]]]
or equivalently
FunRes3[a_?MatrixQ, n_Integer?Positive] :=
Transpose[a][[n]] /; n <= Length[a[[1]]]
Verifying that each gives the same results as your definitions for your specific matrix
And @@ Table[FunRes[n] == FunRes2[L, n] == FunRes3[L, n],
{n, 3}]
True
For an array with arbitrary dimensions
L = Array[a, {RandomInteger[{3, 15}],
RandomInteger[{3, 10}]}];
And @@ Table[FunRes2[L, n] == FunRes3[L, n],
{n, Length[L[[1]]]}]
True
Bob Hanlon
---- Andrey <oradev at rambler.ru> wrote:
=============
On Oct 17, 3:03 pm, David Bailey <d... at removedbailey.co.uk> wrote:
> Andrey wrote:
> > Hello!
> > May be anybody can help me. So, I have this:
>
> > L = {{1, 2, 3}, {1, 2, 3}, {1, 2, 3}};
> > Fun1[t_] := ListPlot[L[[1, t]]];
> > Fun2[t_] := ListPlot[L[[2, t]]];
> > Fun3[t_] := ListPlot[L[[3, t]]];
>
> > FunRes[t_] := {Fun1[t], Fun2[t], Fun3[t]};
>
> > Everything is ok, BUT if I want to add element to list of FunRes[t_]
> > in loop, I have an error? so I mean this:
>
> > FunRes[t_] := {};
> > For[i = 1, i <= 3, i++,
> > {Subscript[Fun, i][t_] := ListPlot[L[[i, t]]],
> > AppendTo[FunRes[t], Subscript[Fun, i][t]]}]
>
> > Please, help me, where I am wrong?
>
> It is very hard to figure out what you want to achieve here. Here are a
> few thoughts:
>
> Let's start with a list where we can tell what we are plotting:
>
> L = {{1, 2, 3}, {10, 20, 30}, {100, 200, 300}};
>
> This will plot the second sublist:
>
> ListPlot[L[[2]]]
>
> Here is a function that will plot the n'th sublist:
>
> fun[n_] := ListPlot[L[[n]]]
>
> e.g.
>
> fun[3]
>
> Note that in your code FunRes[t] evaluates a function, so it makes
> absolutely no sense to use AppendTo on the result!
>
> Tell us what you really want to do, and someone will tell you how to do i=
t!
>
> BTW, it is highly recommended that you don't use variable names that
> start with a capital letter (unless you use a special character further
> in the name) to avoid confusion with Mathematica's symbols.
>
> David Baileyhttp://www.dbaileyconsultancy.co.uk
Thank you everybody for your replays. Sorry for my english. I wanted
this, and it is works:
L = {{1, 2, 3}, {1, 2, 3}, {1, 2, 3}};
FuncTestList[n_, v_] := L [[n, v]]
FunRes[v_] := Table[FuncTestList[i, v], {i, 1, 3}]
Prev by Date:
**Re: Volume integration pb**
Next by Date:
**Re: Point on sphere greatest distance from given**
Previous by thread:
**Re: Function of list of functions**
Next by thread:
**Generic Mapping Tools and Mathematica**
| |