       Re: Evaluate, Replace, and Hold

• To: mathgroup at smc.vnet.net
• Subject: [mg77191] Re: Evaluate, Replace, and Hold
• From: Ray Koopman <koopman at sfu.ca>
• Date: Tue, 5 Jun 2007 06:50:54 -0400 (EDT)
• References: <f40gib\$65a\$1@smc.vnet.net>

```On Jun 4, 12:55 am, grenan... at gmail.com wrote:
> This is a newbie question. I have a parametric form of a model and I
> would like to evaluate it with different parameters on a list of
> values.
>
> model = a x + b;
>
> Different sets of parameters:
>
> p1 = {a->1, b->0};
> p2 = {a->1, b->1};
>
> x for which I'd like to evaluate the model:
>
> pts = Range;
>
> I would like to define a function to evaluate the model at pts using
> any of the sets of paramters:
>
> f[pts, p1]
> f[pts, p2]
>
> I would also like it to work for single points:
>
> f[1, p1]
> f[2, p1]
>
> I've tried various forms for a function definition that dont work. I
> can do the following for a particular set of parameters:
>
> Function[{x}, Evaluate[model /. p1]] /@ pts
>
> but how can I turn it into a function of also the parameters. The
> below doesn't work, for example:
>
> f[pts_, p_]:=Function[{x}, Evaluate[model /. p] ] /@ pts
>
> What I know is from descending the documentation tree (v6.0) starting
> from the examples in FindFit. I have a fundamental misunderstanding of
> replacement rules and delayed evaluation.
>
> Thanks.

In:= model = Function[{a,b,x}, a x + b];

In:= f[points_,params_] := model[a,b,points]/.params

In:= p1 = {a->1, b->0};
p2 = {a->1, b->1};
pts = Range;

In:= f[pts,p1]

Out= {1,2,3,4,5,6,7,8,9,10}

In:= f[pts,p2]

Out= {2,3,4,5,6,7,8,9,10,11}

```

• Prev by Date: Re: Very Strange Behaviour about something Very Simple
• Next by Date: Re: Very Strange Behaviour about something Very Simple
• Previous by thread: Re: Evaluate, Replace, and Hold
• Next by thread: Re: Evaluate, Replace, and Hold