Re: Monitoring status of dynamic calculation
- To: mathgroup at smc.vnet.net
- Subject: [mg103511] Re: [mg103506] Monitoring status of dynamic calculation
- From: Leonid Shifrin <lshifr at gmail.com>
- Date: Sat, 26 Sep 2009 06:11:47 -0400 (EDT)
- References: <200909251151.HAA13931@smc.vnet.net>
Hi Hugh,
Using your approach with indexed variables, I can suggest the following:
ClearAll[x, n, a, y, status];
n = 100;
a = Table[{i, x[i]}, {i, n}];
Do[x[i] = RandomReal[], {i, n}];
Do[y[i] = x[i], {i, n}];
status :=
If[And @@ Table[x[i] == y[i], {i, n}], "Current", "Out-of-date"]
Row[{Button["Mean", b = Mean[a[[All, 2]]]; Do[y[i] = x[i], {i, n}];],
"Mean =
", Dynamic[b], " Status = ", Dynamic[status]}]
Test:
x[1] = 2
for many variables, it may however be a little more efficient to use a list
as
a dynamic variable and index into individual elements:
ClearAll[x, n, a, y, status];
n = 100;
x = RandomReal[{0, 1}, n];
y = x;
a = Table[{i, x[[i]]}, {i, n}];
status := If[x == y, "Current", "Out-of-date"]
Row[{Button["Mean", b = Mean[x]; y = x;], "Mean =
", Dynamic[b], " Status = ", Dynamic[status]}]
Test:
x[[1]] = 1
Hope this helps.
Regards,
Leonid
On Fri, Sep 25, 2009 at 3:51 PM, Hugh Goyder
<h.g.d.goyder at cranfield.ac.uk>wrote:
> I have a notebook with many (possibly 100) dynamic variables. I do a
> calculation using these variables and get a result. If I change one of
> my dynamic variables then the results of the calculation are no longer
> correct and I need to do the calculation again. What I need is a
> method for identifying the status of the calculation. Is it current
> and correct or has one of the variables changed and it is now out-of-
> date?
>
> I give a toy example below where pressing a button corresponds to
> doing the calculation and setting a status flag to current. If I
> change one of the dynamic variables then I want the status to change
> to out-of-date. I give an input field with a dynamic with a second
> argument which enables me to change the status. This works but my
> problem is that I have many ways of changing the dynamic variables and
> I cannot associate each with a two argument dynamic. I thus need a
> general way of checking to see if a variable has changed and if so
> updating the status. Is this possible?
>
> Thanks
> Hugh Goyder
>
> (divide the cell where line spaces occur)
>
> ClearAll[x];
> n=10;
> a=Table[{i,x[i]},{i,n}];
> Status="Out-of-date";
>
>
> TableForm[{#[[1]],Dynamic[#[[2]]]}&/@a]
>
>
> Do[x[i]=RandomReal[],{i,n}];
>
>
> Row[{Button["Mean",b=Mean[a[[All,2]]];Status="Current"],"Mean =
> ",Dynamic[b]," Status = ",Dynamic[Status]}]
>
>
> InputField[Dynamic[x[1],(x[1]=#;Status="Out-of-date")&]]
>
>
> x[2]=2
>
>
- References:
- Monitoring status of dynamic calculation
- From: Hugh Goyder <h.g.d.goyder@cranfield.ac.uk>
- Monitoring status of dynamic calculation