> -----Original Message-----
> From: Tom Aldenberg [SMTP:Tom.Aldenberg at rivm.nl]
To: mathgroup at smc.vnet.net
> Sent: Friday, July 07, 2000 6:11 AM
> To: mathgroup at smc.vnet.net
> Subject: [mg24287] Do loop var in deferred assignment
>
>
>
> Dear All,
>
> I am surprised to learn that in
>
> Do[degradation[i][t_]:=kdegrad[i]*concentration[i][t]
> ,{i,10}]
>
> i in the rhs is not evaluated. Removing the colon works. However, I need
> delayed
> assignments for putting this in a dynamical system. How can I define:
>
> degradation[1][t_]:=kdegrad[1]*concentration[1][t],
> degradation[2][t_]:=kdegrad[2]*concentration[2][t], etc.?
>
> Best regards,
> Tom Aldenberg
>
[Hartmut Wolf]
Hello Tom,
did you try that Set ("removing the colon") did not work in your dynamical
system? If not you possibly have to search for a conceptional error there.
To get the evaluated i into the rhs you have several options, one is
Block[{t}, Do[degradation[i][t_] =
kdegrad[i]*concentration[i][t], {i, 10}]]
Information["degradation", LongForm -> False]
SubValues[degradation]
another one to Evaluate the rhs:
Remove[degradation]
Block[{t},
Do[degradation[i][t_] :=
Evaluate[kdegrad[i]*concentration[i][t]], {i, 10}]]
Information["degradation", LongForm -> False]
SubValues[degradation]
and yet another one
Remove[degradation]
(degradation[#][t_] := kdegrad[i]*concentration[#][t]) & /@ Range[10];
Information["degradation", LongForm -> False]
SubValues[degradation]
In this last version you do not need Block to protect the pattern variable
at the rhs. Although the Information for Set is different from the other two
cases (I don't not know where this "information" is hidden -- and would be
very pleased if someone could tell me!), yet the SubValues are the same, and
this is decisive for evaluation.
Kind regards,
Hartmut