Re: An Array of Equation Parameters
- To: mathgroup at smc.vnet.net
- Subject: [mg59909] Re: An Array of Equation Parameters
- From: Peter Pein <petsie at dordos.net>
- Date: Thu, 25 Aug 2005 06:33:46 -0400 (EDT)
- References: <dehiud$c0j$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
acvwilson at gmail.com schrieb:
> This seems like a fairly easy problem in other languages but I can't
> figure out how to do it in Mathematica.
>
> I am trying to set up an array of equation parameters, where each entry
> in the array is a list of parameters for a function. I also don't know
> how to get values out of a list to plug into the function. If anyone
> knows how to solve this problem please help me out.
>
> Thanks,
> Asa
>
Hi Asa,
you will most propably have to apply Sequence to the listentry when
calling your function:
simple example:
f[x_, a_, b_] := a*x + b;
f takes x as variable and a and b as parameters.
params = Table[N[Round[20*Random[] - 10]/10, 1], {5}, {2}]
-> {{-0.4, -0.7}, {0.4, 0.7}, {-0.9, 0}, {0.4, 0.8}, {0.6, 0.4}}
Plot[Evaluate[f[x, Sequence @@ #1]& /@ params], {x, -1, 1}];
plots for all parameter sets.
It can become annoying to type Sequence again and again. If possible,
define your function to take the parameters as list:
g[x_, {a_, b_}] := a*x + b;
To plot f for the first and the third set of parameters type:
Plot[Evaluate[g[x, #1]& /@ params[[{1, 3}]]], {x, -1, 1}];
and as last example let's have a look at the last set of params:
gLast[x_]=g[x,Last[params]]
(* ignore the warning *)
-> 0.4 + 0.6 x
hope this helps a bit,
Peter
--
Peter Pein, Berlin
GnuPG Key ID: 0xA34C5A82
http://people.freenet.de/Peter_Berlin/