Tell me more ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

When I open the file containing the following code I get a series of error messages. Once I evaluate the cell with the code the error messages disappear. What is Mathematica doing when it opens a file, or how can avoid creating this problem for myself in the future?

 econmagic1[ ds_, di_, ss_, si_  ] := (
  (* begin equilibrium calculation *)

 A = { { 1, - 1 ds }, { 1, - ss } };
  CC = Inverse[ A ].{ di, si };

  Manipulate[
   (* begin grid layout*)
   Grid[{

     (* begin first row *)
     {Show[

       (* begin initial supply curve *)

   Plot[ ( 1 / ss ) ( x - si ), {x, 0, Part[ CC, 1] }, 
    PlotStyle -> { Red, Dashed },      
    PlotLegends -> { "Initial Supply Set"}],

       (* begin initial demand curve *)

   Plot[ ( 1 / ds ) x + (  - di / ds) , {x, 0, di },  
    PlotStyle -> Dashed,  PlotLegends -> { "Initial Demand Set"} ],

       (* begin demand curve *)

   Plot[ ( 1 / ds ) ( x - et ) + (  - di / ds) , {x, 0, 
     di + et},  PlotLegends -> { "Demand Set"} ],

       (* begin supply curve *)

   Plot[ ( 1 / ss ) ( x - si ), {x, 0, 
     Part[ Inverse[{ { 1, - 1 ds }, { 1, - ss } } ].{ di + et, 
        si }, 1 ]}, PlotStyle -> Red, 
    PlotLegends -> { "Supply Set"}],

       (* begin horizontal for equilibrium *)

   Plot[Part[ 
     Inverse[{ { 1, - 1 ds }, { 1, - ss } } ].{ di + et, si }, 
     2 ],  {x, 0, 
     Part[ Inverse[{ { 1, - 1 ds }, { 1, - ss } } ].{ di + et, 
        si }, 1 ]},  PlotStyle -> { Dashed, Thick } ],

       (* begin filling for consumer surplus *)

   Plot[{  ( 1 / ds ) ( x - et ) + (  - di / ds), 
     Part[ Inverse[{ { 1, - 1 ds }, { 1, - ss } } ].{ di + et, 
        si }, 2 ] }, {x, 0, 
     Part[ Inverse[{ { 1, - 1 ds }, { 1, - ss } } ].{ di + et, 
        si }, 1 ]}, Filling -> 1 -> {2}, 
    FillingStyle -> Directive[ Opacity[ 0.1 ], Blue ] ],

       (* begin filling for producer surplus *)

   Plot[{  Part[ 
      Inverse[{ { 1, - 1 ds }, { 1, - ss } } ].{ di + et, si }, 
      2 ],  ( 1 / ss ) ( x - si ) }, {x, 0, 
     Part[ Inverse[{ { 1, - 1 ds }, { 1, - ss } } ].{ di + et, 
        si }, 1 ] }, Filling -> 1 -> {2}, 
    FillingStyle -> Directive[ Opacity[ 0.1 ], Red ] ],

       (* begin equilibrium point *)

   ListPlot[{ { 
      Part[ Inverse[{ { 1, - 1 ds }, { 1, - ss } } ].{ di + et, 
         si }, 1 ], 
      Part[ Inverse[{ { 1, - 1 ds }, { 1, - ss } } ].{ di + et, 
         si }, 2 ] } }, PlotStyle -> Black, 
    PlotLegends -> { "Equilibrium Point" }],

       (* begin dashed lines for market equilibrium *)     

   Graphics[{ Dashed, 
     Line[{ { 
        Part[ Inverse[{ { 1, - 1 ds }, { 1, - ss } } ].{ di + et, 
           si }, 1 ], 0 }, { 
        Part[ Inverse[{ { 1, - 1 ds }, { 1, - ss } } ].{ di + et, 
           si }, 1 ], 
        Part[ Inverse[{ { 1, - 1 ds }, { 1, - ss } } ].{ di + et, 
           si }, 2 ]}}] }],

       AxesOrigin -> { 0, 0 }, 
   PlotRange -> { { 0, di + 10 }, { 0, (  - di / ds) + 10 }},   
   AxesLabel -> { "Quantity", "Price"}, ImageSize -> Large
   ]}, (* End Show *)

     (* begin second row *)
     { Grid[{

        (* 
    second row first column *)
        {"QD Price Intercept:" TraditionalForm[ - ( di + et ) / ds ],

         (* second row second column *)

     "QD Quantity Intercept:" TraditionalForm[ di + et ] },

        (* 
    third row first column *)
            {"QS Price Intercept:" TraditionalForm[ - si / ss ],

         (* third row second column *)

     "The equilibrium point is:"     TraditionalForm[ { 
        Part[ Inverse[{ { 1, - 1 ds }, { 1, - ss } } ].{ di + et, 
           si }, 1 ], 
        Part[ Inverse[{ { 1, - 1 ds }, { 1, - ss } } ].{ di + et, 
           si }, 2 ] } ] },

        (*  fourth row first column *)    
      {"Consumer Surplus:" TraditionalForm[( 
         1 / 2 ) ( (- di / ds ) - 
          Part[ Inverse[{ { 1, - 1 ds }, { 1, - ss } } ].{ 
             di + et, si }, 2 ])  Part[ 
         Inverse[{ { 1, - 1 ds }, { 1, - ss } } ].{ di + et, 
           si }, 1 ] ],

         (* fourth row second column *)

     "Producer Surplus:" If[

           (*  Does the Supply Curve Intersect the Price Axis *)
           ( - si / ss ) >= 0,

           (*  Supply Curve Intersects Price Axis *)

       TraditionalForm[ .5 ( 
          Part[ Inverse[{ { 1, - 1 ds }, { 1, - ss } } ].{ 
              di + et, si }, 2 ] - ( - si / ss  ) ) ( 
          Part[ Inverse[{ { 1, - 1 ds }, { 1, - ss } } ].{ 
             di + et, si }, 1 ] )],

           (* Supply Curve Does Not Intersect Price Axis *)
       TraditionalForm[ 0.5  ( Part[ 
            Inverse[{ { 1, - 1 ds }, { 1, - ss } } ].{ di + et, 
              si }, 1 ] -  si  ) ( 
          Part[ Inverse[{ { 1, - 1 ds }, { 1, - ss } } ].{ 
             di + et, si }, 2 ] )]

       ] }
     },
   Alignment -> Left, Frame -> All, Spacings -> { 4, 1 } ]
   }
   }, Alignment -> Left],
   { { et, 0 },  -4.5, 25 } ]
   )
share|improve this question
1  
If you indent every line of code by four or more spaces, the formatting of your question would be fixed. Also, you could post the error messages - perhaps these contain vital clues... – cormullion Jan 17 at 12:56
1  
Welcome to Mathematica.SE! It is not unusual for dynamic code to throw messages until evaluated / initialized. – Yves Klett Jan 17 at 13:30
Nothing happens when I run your code. No output and no errors. It will help if you do this: Select the cell, then COPY AS TEXT, then paste it in the question above, then select it all again and choose the code button at the top to make it look code in here. This way one can copy it and run it all as one cell. – Nasser Jan 17 at 13:34
You also put Manipulate inside a function, but did not give instructions or show how it was called. (normally manipulate does not go inside a function, since it takes the input from the control variables (slides, checkboxes, etc...) so I am not quit sure now what you are trying to do. – Nasser Jan 17 at 13:40
3  
I suspect that at least some of the error messages will go away if the OP adds the option SaveDefinitions -> True to his Manipulate expression. – m_goldberg Jan 17 at 15:36
show 2 more comments

1 Answer

You are missing SaveDefinitions->True in your Manipulate. Therefore, when the notebook is opened, the functions in the calls to Plot are undefined and it pinks until you evaluate and restore the definitions.

share|improve this answer
+1, but I had some strange things happen when using SaveDefinitions->True and do not like to use it as I really do not understand it well. I prefer to simply put all function definitions in the Initialization :> section. – Nasser Jan 18 at 6:57
Hi Nasser, upon your indirect suggestion I added the following to the end of my Manipulate Initialization :> { A[ ds, ss ] := { { 1, - 1 ds }, { 1, - ss } }, CC[ di, si ] := Inverse[ A ].{ di, si } } after deleting the A and CC that appear in the beginning. This solves my problem. I am not exactly sure why it works but it does. Many Thanks!! – Robert Kennedy Jan 20 at 22:13

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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