0
$\begingroup$

In the following code how can I keep the DynamicModule from computing values if the input values are not all filled? If I don't specify default values it will show the code used to compute the values instead of blank values.

Thanks.

backingAgreementValue[w_, σ_, 
  a_] := σ /Sqrt[2 π] Exp[ -(w - a)^2/(2 σ^2)] + 
  w CDF[NormalDistribution[0, 1], (w - a)/σ]

DynamicModule[{w = 40, σ = 600, a = 0, n = 100, horseCut = 0.5,
   backingValue, expectation, backerValue, horseValue, 
  horseExpectationPercentage, values}, 
 Deploy[Style[
   Panel[Grid[
     Transpose[{{Style["Mean", Blue], 
        Style["Standard Deviation", Blue], Style["Threshold", Blue], 
        Style["N", Blue], Style["Player Cut", Blue], 
        Style["Backing Agreement Value", Orange], 
        Style["Expectation", Orange], Style["Player Value", Orange], 
        Style["Player Expectation Percentage", Orange], 
        Style["Backer Value", Darker[Magenta]]}, {InputField[
         Dynamic[w], Number], InputField[Dynamic[σ], Number], 
        InputField[Dynamic[a], Number], 
        InputField[Dynamic[n], Number], 
        InputField[Dynamic[horseCut], Number],
        Dynamic[
         Style[backingValue = 
           backingAgreementValue[expectation, σ Sqrt[n], a] // 
            N, If[backingValue >= 0, Darker[Green], Red]]],
        Dynamic[
         Style[expectation = w n // N, 
          If[expectation >= 0, Darker[Green], Red]]],
        Dynamic[
         Style[horseValue = horseCut  backingValue // N, 
          If[horseValue >= 0, Darker[Green], Red]]],
        Dynamic[
         Style[horseExpectationPercentage = 
           horseCut backingValue/expectation // N, 
          If[horseExpectationPercentage >= 0.5, Darker[Green], Red]]],
        Dynamic[
         Style[backerValue = (expectation -  
              backingValue + (1 - horseCut) backingValue) // N, 
          If[backerValue >= 0, Darker[Green], Red]]]}}], 
     Alignment -> Left], ImageMargins -> 10], 
   DefaultOptions -> {InputField -> {ContinuousAction -> True, 
       FieldSize -> {{5, 30}, {1, Infinity}}}}]], 
 SaveDefinitions -> True]
$\endgroup$
6
  • $\begingroup$ SaveDefinitions is not an option for DynamicModule $\endgroup$ Aug 18, 2013 at 11:22
  • $\begingroup$ Thanks but how does this help with my initial question? $\endgroup$
    – dabd
    Aug 18, 2013 at 11:26
  • $\begingroup$ @MikeHoneychurch In Version 9 SaveDefinitions is an option of DynamicModule. SaveDefinitions /. Options[DynamicModule, SaveDefinitions] gives False. Sure, it is not documented, but a lot is not documented ... $\endgroup$ Aug 18, 2013 at 12:53
  • $\begingroup$ @RolfMertig ok. I have V8 on this computer and work with 8 most of the time $\endgroup$ Aug 18, 2013 at 12:56
  • $\begingroup$ @MikeHoneychurch I never use M8 anymore. M9 is really better for DynamicModule, CDF's and all that jazz. $\endgroup$ Aug 18, 2013 at 12:59

1 Answer 1

1
$\begingroup$

Wrap a test around the visible code. If the test passes then display the calculation otherwise display a e.g. spacer:

If[NumberQ[σ]&&NumberQ[n]& ...etc,
Dynamic[Style[
  backingValue = 
   backingAgreementValue[expectation, σ Sqrt[n], a] // N, 
  If[backingValue >= 0, Darker[Green], Red]]],
Spacer[0]
]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.