Re: Create and use a set of values for variables
- To: mathgroup at smc.vnet.net
- Subject: [mg107526] Re: [mg107519] Create and use a set of values for variables
- From: DrMajorBob <btreat1 at austin.rr.com>
- Date: Tue, 16 Feb 2010 03:51:22 -0500 (EST)
- References: <201002151049.FAA28378@smc.vnet.net>
- Reply-to: drmajorbob at yahoo.com
Clear[y]
y[rules : {__Rule}, x_] := y[x] /. rules
y[x_] = a x^2 + b x + c;
vars1 = {b -> d + e, c -> 2 f, a -> d^2, d -> 1, e -> 4, f -> 6};
vars2 = {b -> d + e, c -> 2 f, a -> d^2, d -> 2, e -> 3, f -> 7};
vars3 = {b -> d + e, c -> 2 f, a -> d^2, d -> 5, e -> 5, f -> 1};
y[vars1, x]
2 f + (d + e) x + d^2 x^2
or...
Clear[y]
y[x_] = a x^2 + b x + c;
y[x] /. vars1
2 f + (d + e) x + d^2 x^2
or...
Clear[y]
y[rules : {__Rule}][x_] := y[x] /. rules
y[x_] /; FreeQ[x, Rule] = a x^2 + b x + c;
y[vars1][x]
2 f + (d + e) x + d^2 x^2
Bobby
On Mon, 15 Feb 2010 04:49:09 -0600, Menl <szegersnl at gmail.com> wrote:
> Hi,
>
> I try to find a method of doing the following in Mathematica.
>
> I have some function y[x_]=a x^2 + b x + c
> Now I want some list which hold values for a, b and c. that are
> dependend on some lower level values d, e and f.
>
> vars1=[{d=1, e=4, f=6},{b=d+e, c=2f, a = d^2}]
> vars2=[{d=2, e=3, f=7},{b=d+e, c=2f, a = d^2}]
> vars3=[{d=5, e=5, f=1},{b=d+e, c=2f, a = d^2}]
>
> and use these sets with the original function when I need it.
>
> This line will not work as intended of course but I hope it makes it
> clear what I try to do. The key is I would like to not evaluate these
> values outside this vars, so the original function stays unevaluated.
>
> Something like this I tried to do with either the functions Block or
> With, but both evaluate the values for a, b and c. I would like to make
> several such sets of variables without evaluating them so I can use them
> as desired, to plot the original function with several sets of vars.
>
--
DrMajorBob at yahoo.com
- References:
- Create and use a set of values for variables
- From: Menl <szegersnl@gmail.com>
- Create and use a set of values for variables