Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #12413 > unrolled thread

Cannot calculate with Dynamic variables

Started byReinhard Simonovits <Reinhard.Simonovits@uni-graz.at>
First post2012-11-22 00:51 +0000
Last post2012-11-24 07:30 +0000
Articles 2 — 2 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  Cannot calculate with Dynamic variables Reinhard Simonovits <Reinhard.Simonovits@uni-graz.at> - 2012-11-22 00:51 +0000
    Re: Cannot calculate with Dynamic variables "Rolf.Mertig@gmail.com" <rolf.mertig@gmail.com> - 2012-11-24 07:30 +0000

#12413 — Cannot calculate with Dynamic variables

FromReinhard Simonovits <Reinhard.Simonovits@uni-graz.at>
Date2012-11-22 00:51 +0000
SubjectCannot calculate with Dynamic variables
Message-ID<k8jsv3$5pi$1@smc.vnet.net>
Hi,

I have a problem with Dynamic variables.

This is a prototype of a grading scheme. In reality it is bigger. The  
10 pts  in initPtsPartAcome from the school.

The output cell should be deployed as a CDF file for the teacher. The 
teacher enters the points of the students and gets a final mark.

I have two questions.

1) How can I limit the InputField to allow for integer numbers between 0 
and 10?  If I enter anything else, say a negative number or a symbol,  
it should be cleared automatically.

2) In  "Why don't the calculations work?" you see expressions with 
Dynamic variables which I need to work with. What is wrong? What is the 
solution?

DynamicModule[ {mark4 = 1/3,
   mark3 = 0.51,
   mark2 = 0.68,
   mark1 = 0.80,
   initPtsPartA = {
     {10, 8, 10, 6},
     {10, 5, 10, 5},
     {10, 7, 10, 1}},
   initPtsStudent, initPtsSchool, initPtsPartSum, numTable,
   SchoolAPts, StudentAPts, StudentMinAchieved
   },

  numTable[x_, y_ /; OddQ[y]] := initPtsPartA[[x, y]];
  numTable[x_, y_ /; EvenQ[y]] :=
   InputField[Dynamic@initPtsPartA[[x, y]], Number,
    ContinuousAction -> True, FieldSize -> 1];


  initPtsPartSum[x_, y_, col_] :=
   Dynamic@Total[initPtsPartA[[x ;; y, col]]];


  SchoolAPts = (Total[initPtsPartA[[1 ;; 3, #]]] &) /@ {1, 3};
  StudentAPts = (initPtsPartSum[1, 3, #] &) /@ {2, 4};


  Column[{Grid[
     Append[ Array[numTable, {3, 4}], (initPtsPartSum[1, 3, #] &) /@
       Range[4]]],

    {"Just Testing Values:", initPtsPartSum[1, 3, 1],
     initPtsPartSum[1, 3, 2], initPtsPartSum[1, 3, 3],
     initPtsPartSum[1, 3, 4], "Student Pts only:", StudentAPts},

    {"Why don't the calculations work?",
     Dynamic[5*initPtsPartSum[1, 3, 2] + 10],
     Dynamic[initPtsPartSum[1, 3, 4] > 30],
     Dynamic[ Total[(initPtsPartSum[1, 3, #] &) /@ Range[4]]  ],
     Dynamic[(Total@StudentAPts)]/(Total@SchoolAPts)},

    {"Why don't the calculations work?",
     StudentMinAchieved =
      Dynamic[(StudentAPts[[1]]/SchoolAPts[[1]] >
          mark4) && (StudentAPts[[2]]/SchoolAPts[[2]] > mark4)]}

    }]

  ]


Liebe Grüße, Best wishes, Reinhard

-- 
*********************************************************
              Dr. Reinhard Simonovits
Handelsakademie  |  Karl Franzens University
Math Department  |  Inst. for Mathematics
Grazbachgasse 71 |  Heinrichstrasse 36
               A-8010 Graz, Austria

Email: Reinhard.Simonovits@uni-graz.at
************************************************************

[toc] | [next] | [standalone]


#12451

From"Rolf.Mertig@gmail.com" <rolf.mertig@gmail.com>
Date2012-11-24 07:30 +0000
Message-ID<k8pt2n$itn$1@smc.vnet.net>
In reply to#12413
Dear Reinhard,
something like this will work.
However, it is kind of difficult to enter 10 (you have to be fast, or
click back
into the InputField after typing the 1).
So I would suggest to use PopupMenu instead.

Rolf Mertig

DynamicModule[{mark4 = 1/3, mark3 = 0.51, mark2 = 0.68, mark1 = 0.80,
  initPtsPartA = {{10, 8, 10, 6}, {10, 5, 10, 5}, {10, 7, 10, 1}},
  initPtsStudent, initPtsSchool, initPtsPartSum, numTable, SchoolAPts,
   StudentAPts, StudentMinAchieved},
 numTable[x_, y_ /; OddQ[y]] := initPtsPartA[[x, y]];
 numTable[x_, y_ /; EvenQ[y]] :=
  InputField[Dynamic[initPtsPartA[[x, y]],
    If[0 < # <= 10, initPtsPartA[[x, y]] = #, 0] &

    ], Number, ContinuousAction -> True, FieldSize -> 2];
 initPtsPartSum[x_, y_, col_] :=
  Setting[Dynamic@Total[initPtsPartA[[x ;; y, col]]]];
 SchoolAPts = (Total[initPtsPartA[[1 ;; 3, #]]] &) /@ {1, 3};
 StudentAPts = (initPtsPartSum[1, 3, #] &) /@ {2, 4};
 Dynamic@Column[{Grid[
     Append[Array[numTable, {3, 4}], (initPtsPartSum[1, 3, #] &) /@
       Range[4]]], {"Just Testing Values:", initPtsPartSum[1, 3, 1],
     initPtsPartSum[1, 3, 2], initPtsPartSum[1, 3, 3],
     initPtsPartSum[1, 3, 4], "Student Pts only:",
     StudentAPts}, {"seems to work now",
     5*initPtsPartSum[1, 3, 2] + 10, initPtsPartSum[1, 3, 4] > 30,
     Total[(initPtsPartSum[1, 3, #] &) /@
       Range[4]], (Total@StudentAPts)/(Total@
        SchoolAPts)}, {"seems to work now",
     StudentMinAchieved = (StudentAPts[[1]]/SchoolAPts[[1]] >
         mark4) && (StudentAPts[[2]]/SchoolAPts[[2]] > mark4)}}]]

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web