{VERSION 2 3 "APPLE_PPC_MAC" "2.3" } {USTYLETAB {CSTYLE "Maple Input" -1 0 "Courier" 0 1 255 0 0 1 0 1 0 0 1 0 0 0 0 }{CSTYLE "2D Math" -1 2 "Times" 0 1 0 0 0 0 0 0 2 0 0 0 0 0 0 }{CSTYLE "2D Comment" 2 18 "" 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 } {PSTYLE "Normal" -1 0 1 {CSTYLE "" -1 -1 "" 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 }0 0 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }{PSTYLE "Text Output" -1 2 1 {CSTYLE "" -1 -1 "Courier" 1 10 0 0 255 1 0 0 0 0 0 1 3 0 0 }1 0 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }{PSTYLE "Heading 1" 0 3 1 {CSTYLE "" -1 -1 "" 1 18 0 0 0 0 0 1 0 0 0 0 0 0 0 }1 0 0 0 6 6 0 0 0 0 0 0 -1 0 }{PSTYLE "Heading 2" 3 4 1 {CSTYLE "" -1 -1 "" 1 14 0 0 0 0 0 0 0 0 0 0 0 0 0 } 0 0 0 -1 4 4 0 0 0 0 0 0 -1 0 }{PSTYLE "" 2 6 1 {CSTYLE "" -1 -1 "" 0 1 0 0 0 0 0 0 0 0 0 0 2 0 0 }0 0 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }{PSTYLE "Warning" 2 7 1 {CSTYLE "" -1 -1 "" 0 1 0 0 255 1 0 0 0 0 0 0 1 0 0 } 0 0 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }{PSTYLE "Error" 7 8 1 {CSTYLE "" -1 -1 "" 0 1 255 0 255 1 0 0 0 0 0 0 0 0 0 }0 0 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }{PSTYLE "Diagnostic" 7 9 1 {CSTYLE "" -1 -1 "" 0 1 64 128 64 1 0 0 0 0 0 0 0 0 0 }0 0 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }{PSTYLE "Maple Plo t" 0 13 1 {CSTYLE "" -1 -1 "" 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 }3 0 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }{PSTYLE "Fixed Width" 0 17 1 {CSTYLE "" -1 -1 "Courier" 1 10 0 0 0 0 0 0 0 0 0 0 3 0 0 }3 0 0 -1 -1 -1 0 0 0 0 0 0 17 0 }{PSTYLE "Title" 0 18 1 {CSTYLE "" -1 -1 "" 1 18 0 0 0 0 0 1 1 0 0 0 0 0 0 }3 0 0 -1 12 12 0 0 0 0 0 0 19 0 }{PSTYLE "Author" 0 19 1 {CSTYLE "" -1 -1 "" 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 }3 0 0 -1 8 8 0 0 0 0 0 0 -1 0 }{PSTYLE "" 17 256 1 {CSTYLE "" -1 -1 "" 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 }2 0 0 -1 -1 -1 0 0 0 0 0 0 -1 0 }} {SECT 0 {EXCHG {PARA 18 "" 0 "" {TEXT -1 40 "NelwinDecomp for Maple V. 4: Introduction" }}{PARA 19 "" 0 "" {TEXT -1 72 "24 Sep 1996 Ñ rev. 5 \+ Oct 1999\nEsben Sloth Andersen, esa@business.auc.dk\n" }}}{EXCHG {PARA 256 "" 0 "" {TEXT -1 48 "WARNING 1: The program do not work with Maple V!" }}{PARA 256 "" 0 "" {TEXT -1 338 "WARNING 2: You have to pr ess on all procedures\nto allow the system to function properl y.\nREMARK: In some cases you get an error message. If the\ntext follo wing the error message includes \"oops!\" or\nsimilar expressions, the n the errror message is the result\nof a deliberately wrong Maple stat ement. See the text\nabout how to react.\n" }}}{SECT 0 {PARA 3 "" 0 " " {TEXT -1 41 "The problem of decomposition in Maple V.4" }}{SECT 0 {PARA 4 "" 0 "" {TEXT -1 12 "Introduction" }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 585 "The basic heuristic in problem solving is \"divide and c onquer\". Unless we divide a complex simulation model into simple and \+ relatively independent components, we are likely to run into serious t rouble. Maple's primary means of decomposition are procedures (also ca lled functions). In the following we see how a Nelson and Winter model can be defined by means of a fairly large number of procedures (in co ntrast to SimpleNelwin where everything was included in a single proce dure). The procedure that (directly and indirectly) reintegrates all t he components is called StructuredNelwin." }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 587 "One problem with this decomposition is that at the begin ning of a Maple procedure, we have to declare which global variables w e want to change. All other variables that are changed within the proc edure are assumed to be local. This means that Maple makes a distinct ion between items that can only be accessed from within a given proced ure (local or private items) and items that can be accessed without re strictions (global or public items). Global items survive during a who le Maple session while local items disappear when control is returned \+ from the procedure in which they existed." }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 165 "In the present worksheet we shall make a compromise betw een decomposition of programs and easy access to simulation data by pl acing most variables in a single table." }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 61 "We start by setting the overall system in an adequate man ner:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 51 "restart;\ninterface (prettyprint=1);\nprintlevel := 3;" }}{PARA 2 "" 1 "" {TEXT -1 53 " \+ printlevel := 3" }}}}{SECT 0 {PARA 4 "" 0 "" {TEXT -1 42 "A (huge) table as a single global variable" }} {EXCHG {PARA 0 "" 0 "" {TEXT -1 372 "In an evolutionary model like Nel win and extensions thereof there is a very large number of variables, \+ constants, etc. that we want to access and/or modify from different pr oceduress. We also want to have access to these items for data analysi s and for saving to the harddisk (so that we can later inspect the dat a without having to do time consuming reruns of the model)." }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 423 "To simplify these uses of global \+ items we shall try out the following solution: all global items are st ored in a (huge) table declared as global. Maple tables can be conside red as a generalisation of the array structure. It holds an indexed co llection of elements. When we create an item, we give its indexes and \+ its value. Later the element can be retrieved by referring to its inde xes. Many types of indexes can be used. " }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 112 "The table is controlled by a table monitor (# 1) that st ores the data in the table and administers access to it." }}}{EXCHG {PARA 0 "> " 0 "`index/monitor`" {MPLTEXT 1 0 339 "`index/monitor1` := proc(indices,table) \nif not (type(op(1,indices),string) or type(op(1 ,indices),indexed)) then ERROR(`wrong first part of the index`); \n fi;\nif (nargs = 2) then \n if (assigned(table[op(indices)])) then t able[op(indices)];\n else ERROR(`not assigned`); \n fi;\nelse tabl e[op(indices)] := op(args[3..nargs]); \nfi;\nend:" }}}{EXCHG {PARA 0 " " 0 "" {TEXT -1 245 "Since the names of most of the variables and cons tants have to be enhanced with the name of the global table, we want t his name to be as invisible as possible and not to be confured with an y other names. We shall apply the name \"_\" (underscore)." }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 147 "We now define a procedure for initialisi ng the table with the name \"_\" and the index function \"monitor\". T hen we call the initialisation procedure." }}}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 58 "CreateTable := proc()\nglobal _;\n_ := table(monito r1);\nend:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "CreateTable() ;" }}{PARA 2 "" 1 "" {TEXT -1 25 "table(monitor1, [\n\n ])" }}}} {SECT 0 {PARA 4 "" 0 "" {TEXT -1 35 "The functioning of the global tab le" }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 196 "We now see how we can store and retrieve information. The first part of the index has to be a nam e (letter or mix of letters and integers). Only information that has b een stored can be retrieved. " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 17 "_[1,1,1] := 89.7;" }}{PARA 8 "" 1 "" {TEXT -1 56 "Error, (in ind ex/monitor1) wrong first part of the index" }}{PARA 9 "" 1 "" {TEXT -1 60 " executing statement: ERROR(`wrong first part of the index`)" } }{PARA 9 "" 1 "" {TEXT -1 63 " index/monitor1 called with arguments: [ 1, 1, 1], table, [89.7]" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 101 "Oops! The problem here was that the first part of the index was not a name. Let us make it correctly:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 17 "_[K,1,1] := 89.7;" }}{PARA 2 "" 1 "" {TEXT -1 55 " \+ _[K, 1, 1] := 89.7" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 61 "That was OK. But let us now try to make the error indirec tly:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 7 "K := 1;" }}{PARA 2 " " 1 "" {TEXT -1 49 " K := 1 " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 9 "_[K,1,1];" }}{PARA 8 "" 1 "" {TEXT -1 56 "Error, (in index/monitor1) wrong first part of the i ndex" }}{PARA 9 "" 1 "" {TEXT -1 60 " executing statement: ERROR(`wron g first part of the index`)" }}{PARA 9 "" 1 "" {TEXT -1 55 " index/mon itor1 called with arguments: [1, 1, 1], table" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 138 "Still the problem is that the first part of the index received by the Maple engine is not a name. Let us, therefore, restor e the name \"K\":" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 9 "K := 'K ';" }}{PARA 2 "" 1 "" {TEXT -1 49 " \+ K := K" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 17 "_[K,1,1] \+ := 89.7;" }}{PARA 2 "" 1 "" {TEXT -1 55 " \+ _[K, 1, 1] := 89.7" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 9 "_[K,1,1];" }}{PARA 2 "" 1 "" {TEXT -1 48 " \+ 89.7" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 9 "_ [K,2,1];" }}{PARA 8 "" 1 "" {TEXT -1 39 "Error, (in index/monitor1) no t assigned" }}{PARA 9 "" 1 "" {TEXT -1 43 " executing statement: ERROR (`not assigned`)" }}{PARA 9 "" 1 "" {TEXT -1 55 " index/monitor1 calle d with arguments: [K, 2, 1], table" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 17 "_[K,2,1] := 89.7;" }}{PARA 2 "" 1 "" {TEXT -1 55 " \+ _[K, 2, 1] := 89.7" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 9 "_[K,2,1];" }}{PARA 2 "" 1 "" {TEXT -1 48 " 89.7" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 17 "_[K,1,2] := 93.8;" }}{PARA 2 "" 1 "" {TEXT -1 55 " _[K, 1, 2] := 93.8" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 41 "for i from 1 to 2 do\nprint( _[K,1,i]);\nod;" }}{PARA 2 "" 1 "" {TEXT -1 48 " \+ 89.7" }}{PARA 2 "" 1 "" {TEXT -1 48 " \+ 93.8" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 80 "Now we can write a procedure that initialises the variabl es K and A for N firms:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 142 "Initialise := proc(N)\nglobal _;\nlocal i;\nfor i from 1 to N do\n \+ _[A,i,1] := 0.16;\n _[K,i,1] := 89.70;\nod;\nlprint(`Initialisation \+ OK`);\nend:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "Initialise(4 );" }}{PARA 6 "" 1 "" {TEXT -1 17 "Initialisation OK" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 9 "print(_);" }}{PARA 2 "" 1 "" {TEXT -1 223 "table(monitor1, [\n\n (K, 4, 1) = 89.70\n\n (A, 2, 1) = .16\n\n (K, 1, 2) = 93.8\n\n (K, 3, 1) = 89.70\n\n (A, 3, 1) = .16\n \n (K, 2, 1) = 89.70\n\n (A, 4, 1) = .16\n\n (K, 1, 1) = 89.7 0\n\n (A, 1, 1) = .16\n\n ])" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 187 "Remark that one value has survived from our earlier definition ((K, 1, 2) = 93.8). If we want to avoid such surprises, we have to cl ear the table (by a redefinition: _ := table(monitor);)" }}}{PARA 0 " " 0 "" {TEXT -1 18 " " }}}}{SECT 0 {PARA 3 "" 0 "" {TEXT -1 26 "A little on random numbers" }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 926 "Let us look at the results of this procedure as an examp le of random number generation. To secure that the result can be repro duced, we start by setting the \"_seed\", i.e. the system variable gov erning the outcome of the (pseudo) random number generation. The _seed is normally set to the last random number that has been generated by \+ Maple's internal system. But the user can define an initial value for \+ _seed. This initial value generates at deterministic sequence of numbe rs that behave as if they were produced randomly. This means that alth ough the sequence can be taken to represent the behaviour of a random \+ variable, the sequence can also be reproduced by giving the original _ seed to Maple's engine. In other words, since Maple's generation of ra ndom numbers is strictly deterministic, each run with the same initial _seed value will give exactly the same result, ceteris paribus (i.e. \+ with no parameter change, etc.)." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 7 "rand();" }}{PARA 2 "" 1 "" {TEXT -1 52 " \+ 427419669081" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 7 "rand();" }}{PARA 2 "" 1 "" {TEXT -1 52 " \+ 321110693270" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 7 "rand();" }}{PARA 2 "" 1 "" {TEXT -1 52 " \+ 343633073697" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 11 "_seed := 2:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 7 "rand();" }}{PARA 2 "" 1 "" {TEXT -1 52 " \+ 854839338162" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 11 "_seed := 2:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 7 "rand();" }}{PARA 2 "" 1 "" {TEXT -1 52 " \+ 854839338162" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 12 "_seed := 2 7:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 7 "rand();" }}{PARA 2 "" 1 "" {TEXT -1 52 " 540331065308 " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 12 "_seed := 27:" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 7 "rand();" }}{PARA 2 "" 1 "" {TEXT -1 52 " 540331065308" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 396 "Apart from the rand function, Map le's functions for producing random numbers are placed in the random p ackage within the stats package. This means that you can either call t hese functions by a long name or - after calling the package - by a sh ort name. Let us consider Maple's function for generating a sequence o f random numbers distributed according to a normal distribution with d efined mean (" }{XPPEDIT 18 0 "mu=2" "/%#muG\"\"#" }{TEXT -1 26 ") and standard deviation (" }{XPPEDIT 18 0 "sigma=.5" "/%&sigmaG$\"\"&!\"\" " }{TEXT -1 104 "). We start by the long name. Then we load the rando m package and make a few tries with the short name." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 31 "stats[random,normald[2,0.5]]();" }}{PARA 2 "" 1 "" {TEXT -1 51 " 2.44053 6751" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 20 "with(stats[random]) ;" }}{PARA 2 "" 1 "" {TEXT -1 198 "[beta, binomiald, cauchy, chisquare , discreteuniform, empirical, exponential, fratio, gamma,\n\n lapla ced, logistic, lognormal, negativebinomial, normald, poisson, students t, uniform,\n\n weibull]" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 17 "normald[2,0.5]();" }}{PARA 2 "" 1 "" {TEXT -1 51 " \+ 2.155756361" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 12 "_seed := 27:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 17 "normald[2,0.5]();" }}{PARA 2 "" 1 "" {TEXT -1 51 " \+ 1.513856966" }}}{PARA 0 "" 0 "" {TEXT -1 2 " " }}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 12 "_seed := 27:" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 17 "normald[2,0.5]();" }}{PARA 2 "" 1 "" {TEXT -1 51 " 1.51385 6966" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 165 "Finally we ask for five \+ random numbers determined by the same _seed. Remark that the first is \+ the same as before, while the others are (pseudo) randomly distributed ." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 12 "_seed := 27:" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 18 "normald[2,0.5](5);" }}{PARA 2 "" 1 "" {TEXT -1 77 " 1.513856966, 1.732695730, 1.24721 1154, 2.270571276, 2.961489731" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 111 "We also need random numbers distributed according to the Poisson \+ distribution (with the parameter lambda, here " }{XPPEDIT 18 0 "lambda =3" "/%'lambdaG\"\"$" }{TEXT -1 2 ")." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "poisson[3](5);" }}{PARA 2 "" 1 "" {TEXT -1 56 " \+ 5.0, 3.0, 2.0, 1.0, 0" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 117 "Finally we try in vain to obtain a series of uni formly distributed random numbers from 1 to 6 (like throwing a dice). " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 17 "uniform[1..6](5);" }} {PARA 8 "" 1 "" {TEXT -1 62 "Error, (in stats/parms/functions/uniform) invalid types in sum" }}{PARA 9 "" 1 "" {TEXT -1 30 " executing state ment: b := a+1" }}{PARA 9 "" 1 "" {TEXT -1 63 " locals defined as: a = 1. .. 6., b = b, status = status, x = x" }}{PARA 9 "" 1 "" {TEXT -1 72 " stats/parms/functions/uniform called with arguments: 5, [1 .. 6], false" }}{PARA 9 "" 1 "" {TEXT -1 86 " stats/functions/random called \+ with arguments: [uniform[1 .. 6]], [5], uniform[1 .. 6]" }}{PARA 9 "" 1 "" {TEXT -1 81 " stats[random,uniform[1 .. 6]] called with arguments : 5, topname(uniform[1 .. 6])" }}{PARA 9 "" 1 "" {TEXT -1 41 " uniform [1 .. 6] called with arguments: 5" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 190 "Oops! Here we encountered a grave error in the Maple system. Luck ily most of Maple's system is accessible to users, so we can correct t he error immediately (do not think about the details!)." }}}{SECT 0 {PARA 4 "" 0 "" {TEXT -1 42 "Correcting a bug in Maple's random packag e" }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 404 "Unfortunalely there is a bug in the Maple function for creating a uniform distribution. Therefore, we have to include a corrected version of a helping procedure relatin g to the uniform function. The new version of the procedure (`stats/pa rms/functions/uniform`) secures that the uniform distribution in Maple 's random function package works correctly. Just press . Do not bother about the details." }}}{EXCHG {PARA 0 "> " 0 "`stats/parms/fun ctions/uniform`" {MPLTEXT 1 0 1167 "`stats/parms/functions/uniform` := proc(xvalue, given, xcheck)\nlocal a, b, status, x;\noption system, r emember, \n`Copyright (c) 1993 by Waterloo Maple Inc. \nBug corrected \+ by ESA, 1 Sep 1996. Another bug concerning one real argument is still \+ present. In the one-argument case, only integers can be used`;\n\nif n ops(given) = 0 then a := evalf(0); b := evalf(1)\nelif nops(given[]) = 2 then \n a := evalf(op(1, given[])); b := evalf(op(2, given[]))\ne lif nops(given) = 1 then a := evalf(op(1, given[])); b := a + 1\nelse \+ \n status := 'abort';\n RETURN(status, \n [`requires two paramet ers (no parameters defaults to 0,1), received`, given])\nfi;\nif not type([a, b], list(numeric)) then\n status := 'FAIL';\n RETURN (status, [`unable to find evalf() of the bounds `, a, b])\nfi;\nif not (a < b) then\n status := 'abort';\n RETURN(status, [`right bound \+ must be greater than left bound, received`, a, b])\nfi;\nif not xch eck then x := xvalue\nelse\n x := evalf(xvalue);\n if not type(x, \+ numeric) then\n status := 'FAIL';\n RETURN(status, [`unabl e to find evalf() of argument, \n received`, xvalue])\n \+ fi\nfi;\nstatus := 1;\nstatus, [x, a, b]\nend:" }}}}{EXCHG {PARA 0 " " 0 "" {TEXT -1 31 "Now we try again with our dice:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 17 "uniform[1..6](5);" }}{PARA 2 "" 1 "" {TEXT -1 77 " 2.860190768, 3.619231213, 1.287895212, 2.93 8127176, 5.667342603" }}}}{SECT 0 {PARA 3 "" 0 "" {TEXT -1 28 "The ele ments of NelwinDecomp" }}{SECT 0 {PARA 4 "" 0 "" {TEXT -1 12 "Introduc tion" }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 255 "In the following formulat ion of functions and procedures, the classic Nelson and Winter model f amily has been formulated according to the paradigm of decomposed prog ramming that combines elements of structured programming and object-or iented programming. " }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 143 "The core of the program (or system of functions and procedures) is the transfo rmation of the state variables of a firm - its physical capital (" } {XPPEDIT 18 0 "K" "I\"KG6\"" }{TEXT -1 37 ") and its (reciprocal) prod uctivity (" }{XPPEDIT 18 0 "A=Q/K" "/%\"AG*&%\"QG\"\"\"%\"KG!\"\"" } {TEXT -1 3 "). " }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 246 "The mechanism of transformation from one state to the next includes both elements w ithin and beyond the individual firm, and the state transformation inc ludes both deterministic and probabilistic elements. Let us start to e xplore these elements. " }}}}{SECT 0 {PARA 4 "" 0 "" {TEXT -1 46 "Crea ting a global table and an individual firm" }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 144 "We start by making a slight change in the functions for \+ monitoring a table and for creating the global table. Then we call Cre ateTable function:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 253 "`ind ex/monitor2` := proc(indices,table) \nif not (type(op(1,indices),strin g) or type(op(1,indices),indexed)) then ERROR(`wrong first part of the index`); fi;\nif (nargs = 2) then table[op(indices)];\nelse table[op( indices)] := op(args[3..nargs]); \nfi;\nend:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 95 "CreateTable := proc()\nglobal _;\n_ := table(mon itor2);\n_[newFirm] := 0;\nRETURN(`Table OK`);\nend:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 14 "CreateTable();" }}{PARA 2 "" 1 "" {TEXT -1 50 " Table OK" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 9 "print(_);" }}{PARA 2 "" 1 "" {TEXT -1 42 "table(monitor2, [\n\n newFirm = 0\n\n ])" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 70 "Then we define a procedure for creating f irms and make our first firm:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 221 "CreateFirm := proc(capital,productivity)\nglobal _;\nlocal firm Key;\nfirmKey := _[newFirm] + 1;\n_[newFirm] := firmKey;\n_[K,firmKey, 1] := capital;\n_[A,firmKey,1] := productivity;\nRETURN(`Firm created. FirmKey`, firmKey);\nend:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 22 "CreateFirm(91.33,.16);" }}{PARA 2 "" 1 "" {TEXT -1 58 " \+ Firm created. FirmKey, 1" }}}{EXCHG {PARA 0 "> \+ " 0 "" {MPLTEXT 1 0 9 "print(_);" }}{PARA 2 "" 1 "" {TEXT -1 86 "table (monitor2, [\n\n (K, 1, 1) = 91.33\n\n (A, 1, 1) = .16\n\n ne wFirm = 1\n\n ])" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 64 "We now mak e another firm to allow for Schumpeterian competition:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 22 "CreateFirm(91.33,.16);" }}{PARA 2 " " 1 "" {TEXT -1 58 " Firm created. Fi rmKey, 2" }}}}{SECT 0 {PARA 4 "" 0 "" {TEXT -1 15 "Output decision" }} {EXCHG {PARA 0 "" 0 "" {TEXT -1 124 "The firm is now ready for making \+ its first decision. This concerns output. The decision-making rule is \+ simply that the firm " }{XPPEDIT 18 0 "i" "I\"iG6\"" }{TEXT -1 51 " pr oduces as much as possible in any given period (" }{XPPEDIT 18 0 "t" " I\"tG6\"" }{TEXT -1 17 "). The output is " }{XPPEDIT 18 0 "Q[i,t]" "&% \"QG6$%\"iG%\"tG" }{TEXT -1 47 " or, in relation to the global table, \+ _[Q,i,t]." }}}{EXCHG {PARA 0 "> " 0 "FirmOutput" {MPLTEXT 1 0 69 "Firm Output := proc(i,t)\nglobal _;\n_[Q,i,t] := _[A,i,t]*_[K,i,t];\nend:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 16 "FirmOutput(1,1);" }} {PARA 2 "" 1 "" {TEXT -1 49 " \+ 14.6128" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 16 "FirmOutput(2,1) ;" }}{PARA 2 "" 1 "" {TEXT -1 49 " \+ 14.6128" }}}}{SECT 0 {PARA 4 "" 0 "" {TEXT -1 38 "Industry-level supply and market price" }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 291 "Let u s now consider what happens in the short run at the market level. In t he Nelson and Winter model this is quite simple (because our analytica l interest is concentrated on other issues). First we find total suppl y. Then we find the market price in a market with unit elasticity of d emand:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 85 "Supply := proc(t) \nglobal _;\nlocal i;\n_[TQ,t] := add(_[Q,i,t], i=1.. _[newFirm]);\nen d:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 10 "Supply(1);" }}{PARA 2 "" 1 "" {TEXT -1 49 " 29.22 56" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 61 "Price := proc(t)\nglo bal _;\n_[P,t] := _[Revenue]/_[TQ,t];\nend:" }}}{EXCHG {PARA 0 "" 0 " " {TEXT -1 72 "Before we can find the price, we need to define the par ameter \"Revenue\":" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 17 "_[Re venue] := 67;" }}{PARA 2 "" 1 "" {TEXT -1 54 " \+ _[Revenue] := 67" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 9 "Price(1);" }}{PARA 2 "" 1 "" {TEXT -1 51 " \+ 2.292510676" }}}}{SECT 0 {PARA 4 "" 0 "" {TEXT -1 18 "Firm-level profits" }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 60 "We can n ow calculate the firm's profits per unit of capital." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 149 "Profit := proc(i,t)\nglobal _;\nlocal co sts, revenue;\ncosts := _[c] + _[r_in] + _[r_im];\nrevenue := _[P,t]*_ [A,i,t];\n_[pi,i,t] := revenue - costs;\nend:" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 211 "This function depends on three parameters. We give th em values taken from Nelson and Winter - but not adapted to the two-fi rm case. This means that we should not expect the model to be in an in itial equilibrium." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 51 "_[c] \+ := .16;\n_[r_in] := 0.00112;\n_[r_im] := 0.0223;" }}{PARA 2 "" 1 "" {TEXT -1 51 " _[c] := .16" }} {PARA 2 "" 1 "" {TEXT -1 54 " _[r_ in] := .00112" }}{PARA 2 "" 1 "" {TEXT -1 54 " \+ _[r_im] := .0223" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 25 "Profit(1,1); Profit(2,1);" }}{PARA 2 "" 1 "" {TEXT -1 51 " \+ .1833817082" }}{PARA 2 "" 1 "" {TEXT -1 51 " .1833817082" }}} {EXCHG {PARA 0 "" 0 "" {TEXT -1 187 "We see that each firm makes a pro fit in the initial period. However, let ud make a couple of new firms \+ of the same size as the two pervious ones, and consider the consequenc e for profits:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 45 "CreateFir m(91.33,.16); CreateFirm(91.33,.16);" }}{PARA 2 "" 1 "" {TEXT -1 58 " \+ Firm created. FirmKey, 3" }}{PARA 2 " " 1 "" {TEXT -1 58 " Firm created. Fi rmKey, 4" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 33 "FirmOutput(3,1) ; FirmOutput(4,1);" }}{PARA 2 "" 1 "" {TEXT -1 49 " \+ 14.6128" }}{PARA 2 "" 1 "" {TEXT -1 49 " \+ 14.6128" }}}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 10 "Supply(1);" }}{PARA 2 "" 1 "" {TEXT -1 49 " \+ 58.4512" }}}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 9 "Price(1);" }}{PARA 2 "" 1 "" {TEXT -1 51 " \+ 1.146255338" }}}{EXCHG {PARA 0 "> " 0 " " {MPLTEXT 1 0 37 "for i from 1 to 4 do Profit(i,1); od;" }}{PARA 2 " " 1 "" {TEXT -1 52 " -.00001914 59" }}{PARA 2 "" 1 "" {TEXT -1 52 " \+ -.0000191459" }}{PARA 2 "" 1 "" {TEXT -1 52 " \+ -.0000191459" }}{PARA 2 "" 1 "" {TEXT -1 52 " \+ -.0000191459" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 146 "With the set-up of new firms, the capacity of the i ndustry fits the fixed level of revenue in a way that profits become p ractically equal to zero." }}}}{SECT 0 {PARA 4 "" 0 "" {TEXT -1 35 "Se arch for and choice of technology" }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 123 "The simulation of innovation and imitation depends on Maple's ran dom nummer generators (see the section on random numbers)." }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 53 "A firm can obtain a new level of producti vity (a new " }{XPPEDIT 18 0 "A" "I\"AG6\"" }{TEXT -1 166 ") either in a direct (innovative) or in an indirect (imitative) way. The chances \+ of obtaining success depends on the firm's level of innovative R&D and imitative R&D." }}}{EXCHG {PARA 0 "> " 0 "Innovate" {MPLTEXT 1 0 137 "Innovation := proc(i,t)\nglobal _;\nlocal innoResearch;\ninnoResearch := _[r_in]*_[K,i,t];\n_[A_in,i,t] := InnoResult(i,t,innoResearch);\ne nd:" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 138 "The Innovation procedure \+ depends on a procedure (InnoResult) that we have not defined yet. Furt hermore, we have not specified the size of " }{XPPEDIT 18 0 "r[n]" "&% \"rG6#%\"nG" }{TEXT -1 126 ". Therefore, it is still too early to call the procedure. Or, rather, we obtain a symbolic result instead of a n umeric result:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 16 "Innovatio n(1,1);" }}{PARA 2 "" 1 "" {TEXT -1 59 " \+ InnoResult(1, 1, .1022896)" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 94 " Before we define the missing procedure and parameter, we define how a \+ firm makes an Imitation:" }}}{EXCHG {PARA 0 "> " 0 "Imitate" {MPLTEXT 1 0 131 "Imitation := proc(i,t)\nglobal _;\nlocal imiResearch;\nimiRes earch := _[r_im]*_[K,i,t];\n _[A_im,i] := ImiResult(i,t,imiResearch); \nend:" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 174 "Whether the results of the firm's innovative and imitative search are successful or unsucces sful, they can be used in determinining the technology applied in the \+ next period." }}}{EXCHG {PARA 0 "> " 0 "TechnoChoice" {MPLTEXT 1 0 95 "TechnoChoice := proc(i,t)\nglobal _;\n_[A,i,t+1] := max(_[A,i,t], _[A _in,i,t], _[A_im,i,t]);\nend:" }}}}{SECT 0 {PARA 4 "" 0 "" {TEXT -1 58 "\"Techno space\" for innovation and industry-level imitation" }} {EXCHG {PARA 0 "" 0 "" {TEXT -1 127 "To determine innovations and imit ations we need to be sure that the random package is loaded. Furthermo re, we define the _seed:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 32 "with(stats[random]): _seed := 1;" }}{PARA 2 "" 1 "" {TEXT -1 51 " \+ _seed := 1" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 247 "The space in which firms search for innovations can be constructed in different ways. Major alternatives depict science-b ased search and cumulative-technology search. Let us put both alternat ives into the definition of the procedure \"InnoResult\". " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 458 "InnoResult := proc(i,t,effort)\ngl obal _;\nlocal lambda, draws, mean,lnResult;\nlambda := _[d_in]*effort ;\ndraws := poisson[lambda]();\nif draws > 0 then\n if _[searchType] = cumulative then\n mean := ln(_[A,i,t]);\n lnResult := nor mald[mean,_[sigma_in]]();\n _[A_in,i,t] := exp(lnResult);\n els e\n mean := ln(_[A_mean,t]);\n lnResult := normald[mean,_[si gma_in]]();\n _[A_in,i,t] := exp(lnResult);\n fi;\nelse _[A_in, i,t] := 0;\nfi;\nend:" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 35 "The imit ation procedure is simpler:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 194 "ImiResult := proc(i,t,effort)\nglobal _;\nlocal lambda, draws;\nl ambda := _[d_im]*effort;\ndraws := poisson[lambda]();\nif draws > 0 th en\n _[A_im,i,t] := _[A_max,t];\nelse _[A_im,i,t] := 0;\nfi;\nend:" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 86 "We need to specify some paramet ers before these procedures can be called by the firms:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 28 "_[searchType] := cumulative;" }} {PARA 2 "" 1 "" {TEXT -1 59 " _[searchT ype] := cumulative" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 15 "_[d_i n] := 0.3;" }}{PARA 2 "" 1 "" {TEXT -1 52 " \+ _[d_in] := .3" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 15 "_[d_im] := 0.3;" }}{PARA 2 "" 1 "" {TEXT -1 52 " \+ _[d_im] := .3" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 19 "_[sigma_in] := 0.2;" }}{PARA 2 "" 1 "" {TEXT -1 54 " \+ _[sigma_in] := .2" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 58 "We also need to find the firm with the le ading technology:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 84 "Maximu m := proc(t)\nglobal _;\n_[A_max,t] := max(seq(_[A,i,t], i=1.._[newFir m]));\nend:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 11 "Maximum(1); " }}{PARA 2 "" 1 "" {TEXT -1 47 " \+ .16" }}}}{SECT 0 {PARA 4 "" 0 "" {TEXT -1 31 "Firms' innovation and imitation" }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 96 "The firms can no w try the innovative and imitative lotteries. We start with firm #1 in period 1:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 16 "Innovation(1, 1);" }}{PARA 2 "" 1 "" {TEXT -1 46 " \+ 0" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 68 "We were unlucky. \+ However, with another seed we obtain an innovation:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 29 "_seed := 21: Innovation(1,1);" }}{PARA 2 "" 1 "" {TEXT -1 51 " .18600565 42" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 15 "Imitation(1,1);" }} {PARA 2 "" 1 "" {TEXT -1 47 " \+ .16" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 32 "Innovation(2,1); \+ Imitation(2,1);" }}{PARA 2 "" 1 "" {TEXT -1 46 " \+ 0" }}{PARA 2 "" 1 "" {TEXT -1 47 " \+ .16" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 32 "Innovation(3,1); Imitation(3,1);" }}{PARA 2 "" 1 "" {TEXT -1 46 " 0" }}{PARA 2 "" 1 "" {TEXT -1 46 " 0 " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 32 "Innovation(4,1); Imitat ion(4,1);" }}{PARA 2 "" 1 "" {TEXT -1 46 " \+ 0" }}{PARA 2 "" 1 "" {TEXT -1 47 " \+ .16" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 175 " In this sequence the are three firms that obtain an imitation (with a \+ boring value) and one firm that obtain an innovation. This is reflecte d in the TechnoChoice of the firms:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 77 "TechnoChoice(1,1); TechnoChoice(2,1);\nTechnoChoice(3 ,1); TechnoChoice(4,1); " }}{PARA 2 "" 1 "" {TEXT -1 51 " \+ .1860056542" }}{PARA 2 "" 1 "" {TEXT -1 47 " .16" }}{PARA 2 "" 1 " " {TEXT -1 47 " .16" }} {PARA 2 "" 1 "" {TEXT -1 47 " \+ .16" }}}}{SECT 0 {PARA 4 "" 0 "" {TEXT -1 11 "New Capital" }} {EXCHG {PARA 0 "" 0 "" {TEXT -1 330 "Now we come to the investment pro cess. The ability to invest depends on the profits in the present peri od. Banks can improve the situation but are also using profits as thei r criteria. The willingness to invest depends on the expected mark-up \+ over costs in the next period (i.e. possibly using the new technology \+ in the estamate)." }}}{EXCHG {PARA 0 "> " 0 "MaxInvest" {MPLTEXT 1 0 168 "MaxInvest := proc(i,t)\nglobal _;\nif _[pi,i,t] <= 0 then _[loans ,i] := 0;\nelse _[loans,i] := _[b]*_[pi,i,t];\nfi;\n_[I_max,i,t] := _ [delta] + _[pi,i,t] + _[loans,i];\nend:" }}}{EXCHG {PARA 0 "> " 0 "Des iredInvest" {MPLTEXT 1 0 195 "DesiredInvest := proc(i,t)\nglobal _;\n_ [s,i,t] := _[Q,i,t]/_[TQ,t];\n_[rho,i] := _[c]/(_[P,t]*_[A,i,t+1]);\n_ [I_des,i,t] := _[delta] + 1 \n - _[eta]/(_[eta] - _[s, i,t])*_[rho,i];\nend:" }}}{EXCHG {PARA 0 "> " 0 "ChangeCapital" {MPLTEXT 1 0 185 "ChangeCapital := proc(i,t)\nglobal _;\nlocal Inv;\n_ [constraint,i,t] := min(_[I_des,i,t], _[I_max,i,t]);\nInv := max(0, _[ constraint,i,t]);\n_[K,i,t+1] := _[K,i,t]*(Inv + 1 - _[delta]);\nend: " }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 73 "Before we can run these proce dures we need to define some new parameters:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 12 "_[b] := 1.0;" }}{PARA 2 "" 1 "" {TEXT -1 51 " \+ _[b] := 1.0" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 17 "_[delta] := 0.03;" }}{PARA 2 "" 1 "" {TEXT -1 53 " _[delta] := .03" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 12 "_[eta] := 1;" }}{PARA 2 "" 1 "" {TEXT -1 51 " _[eta] := 1 " }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 55 "MaxInvest(1,1); Desired Invest(1,1); ChangeCapital(1,1);" }}{PARA 2 "" 1 "" {TEXT -1 51 " \+ .0299808541" }}{PARA 2 "" 1 "" {TEXT -1 51 " .029421419" }} {PARA 2 "" 1 "" {TEXT -1 51 " 9 1.27715820" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 55 "MaxInvest(2,1 ); DesiredInvest(2,1); ChangeCapital(2,1);" }}{PARA 2 "" 1 "" {TEXT -1 51 " .0299808541" }}{PARA 2 "" 1 "" {TEXT -1 51 " -.1332079 60" }}{PARA 2 "" 1 "" {TEXT -1 49 " \+ 88.5901" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 277 "For the first \+ firm the innovation means that the firm wants to invest, but investmen t is smaller than depreciation so capital becomes smaller. In the seco nd case mark-up is considered insufficient. Therefore no investment ta kes place, and capital decreases by the depreciation." }}}}{SECT 0 {PARA 4 "" 0 "" {TEXT -1 10 "Parameters" }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 122 "We have defined the parameters successively. Here is a p rocedure that contains them all. It makes parameter change easier:" }} }{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 373 "Parameters := proc()\nglob al _;\n_[b] := 1 ;\n_[c] := 0.16 ;\n_[del ta] := 0.03 ;\n_[Revenue] := 67 ;\n_[d_im] := \+ 0.3 ; \n_[d_in] := 0.3 ;\n_[eta] := 1 ; \n_[phi] := 0.05 ; \n_[r_im] := 0.00112 ;\n_[r_in] \+ := 0.0223 ;\n_[searchType]:= cumulative;\n_[sigma_in] := 0.2 ;\nend:" }}}}{SECT 0 {PARA 4 "" 0 "" {TEXT -1 41 "The evolution o f an industry in t periods" }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 132 "Now we can define a procedure that uses the specification of the individu al decisions etc. to simulate the evolution of an industry:" }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 511 "NelwinDecomp := proc(n,T,se ed)\nglobal _, _seed;\nlocal i,t;\nwith(stats[random]);\n_seed := seed ;\n_[newFirm] := 0;\nCreateTable();\nParameters();\nfor i from 1 to n \+ do\n CreateFirm(91.33,.16);\nod;\nfor t from 1 to T do\n for i fro m 1 to n do\n FirmOutput(i,t);\n od;\n Supply(t);\n Price(t );\n Maximum(t);\n for i from 1 to n do\n Innovation(i,t);\n \+ Imitation(i,t);\n TechnoChoice(i,t);\n Profit(i,t);\n \+ MaxInvest(i,t);\n DesiredInvest(i,t);\n ChangeCapital(i, t);\n od;\nod;\nend:" }}}}}{SECT 0 {PARA 3 "" 0 "" {TEXT -1 27 "Mode l run and data analysis" }}{SECT 0 {PARA 4 "" 0 "" {TEXT -1 40 "The ti me-consuming simulation excersises" }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 340 "We start by running the model for a relative low number of firms \+ and periods. The reason is that Maple is very slow compared to e.g. C+ +. Make the run and study the time it takes at your computer system. ( REMARK: At the moment the parameters are adapted to 4 firms.) In our f irst call we use the arguments: firms = 4, periods = 4, seed = 1." }}} {EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 20 "NelwinDecomp(4,4,1);" }} {PARA 2 "" 1 "" {TEXT -1 51 " 8 3.35282919" }}}}{SECT 0 {PARA 4 "" 0 "" {TEXT -1 28 "Procedures for da ta plotting" }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 185 "To ease the analys is of the results of evolutionary simulations, Andersen et al. (DRUIDI C) have made a series of helping procedures. Here are a couple for pl otting of time series data." }}}{SECT 0 {PARA 4 "" 0 "" {TEXT -1 60 "P rocedure that plots a time series for a firm-level variable" }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 337 "This procedure draws time series data fo r the firms of the industry. In order to allow simple comparisons acro ss time series for different variables, each firm is given a specific \+ colour that is the same in all plots. (The procedure can easily be ext ended with new features, like plotting over specific ranges of firms a nd periods, etc.)" }}}{EXCHG {PARA 0 "> " 0 "DrawVariable" {MPLTEXT 1 0 626 "DrawVariable := proc(var,firmno,periods)\nglobal peri,plotdata, text;\nlocal colour,tt,t,n,a,Num,Per;\noption `ES Andersen, Aalborg Un iversity, 1 Sep 96`;\nif nargs = 3 then\n Num := firmno;\n Per := \+ periods;\nelse\n Num := _[N];\n Per := _[T];\nfi;\nperi := seq(t, \+ t = 1..Per);\ncolour := seq('COLOUR'(HUE,n/Num), n=1..Num);\na:=NULL; \nfor n from 1 to Num do\n\011a := a, 'CURVES'([seq(MergeLists([peri[t t]],\n [_[var,n,tt]]),tt=1..Per)],colour[n],THICKNESS(2));\nod;\n \ntext := cat(`Variable `,var,` for `, Num, ` firms and `, Per, ` peri ods.`);\nplotdata := 'PLOT'(a, 'TITLE'(text), AXESSTYLE(NORMAL), AXEST ICKS(5,5));\nplotdata;\n\nend:" }}}}{SECT 0 {PARA 4 "" 0 "" {TEXT -1 57 "Function that helps the creation of a PLOT data structure" }} {EXCHG {PARA 0 "" 0 "" {TEXT -1 95 "This procedure performs a subtask \+ for the DrawVariable procedure, namely to create data points." }}} {EXCHG {PARA 0 "> " 0 "MergeLists" {MPLTEXT 1 0 527 "MergeLists := pro c(list1, list2)\nlocal LookUpItem,i;\noption `ES Andersen, Aalborg Uni versity, 24 Aug 96`;\n\n\011LookUpItem := proc(list1, list2, seriesnum ber)\n\011local listnumber;\n\011if type(seriesnumber, even) then\n \011\011listnumber := seriesnumber/2;\n\011\011RETURN(list1[listnumber ]);\n\011else\n\011\011listnumber := (seriesnumber-1)/2;\n\011\011RETU RN(list2[listnumber]);\n\011fi;\n\011end;\n\011\nif not nops(list1) = \+ nops(list2) then\n\011ERROR(`the number of elements in lists must be t he same`);\nfi;\n[seq(LookUpItem(list1, list2, i), \n\011\011\011\011i = 2..nops(list1)*2 + 1)];\011\nend:" }}}}{SECT 0 {PARA 4 "" 0 "" {TEXT -1 16 "Legend for plots" }}{EXCHG {PARA 0 "> " 0 "Legend" {MPLTEXT 1 0 449 "Legend := proc(N)\nglobal periods,plotdata,text;\nlo cal colour,i,n,a,b;\noption `ES Andersen, Aalborg University, 28 Aug 9 6`;\n\ncolour := seq('COLOUR'(HUE,n/N), n=1..N);\na:=NULL; b := NULL; \nfor n from 1 to N do\n\011a := a, 'CURVES'([[0,N-n],[10,N-n]],\n \+ colour[n],THICKNESS(2));\n b := b, 'TEXT'([11,N-n],`Firm `.n,FONT(TIME S,ROMAN,12));\nod;\n\ntext := cat(`Legend for `,N,` firms`);\nplotdata := 'PLOT'(a, b, 'TITLE'(text), AXESSTYLE(NONE));\nplotdata;\n\nend:" }}}}}{SECT 0 {PARA 4 "" 0 "" {TEXT -1 28 "Plots of core firm variables " }}{EXCHG {PARA 0 "" 0 "" {TEXT -1 135 "Let us make a new simulaton a nd analyse the results. We call \"StructuredNelwin\" with the argument s: firms = 4, periods = 16, seed = 17." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 22 "NelwinDecomp(4,16,17):" }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 150 "We now use the plot procedures to draw core variables fo r firms. To get a plot for all firms and all periods, simple give a va riable name as argument." }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 52 "DrawVariable(A,4,16); DrawVariable(constraint,4,16);" }}{PARA 13 "" 1 "" {INLPLOT "6)-%'CURVESG6%727$\"\"\"$\"#;!\"#7$\"\"#F)7$\"\"$F)7$\" \"%F)7$\"\"&F)7$\"\"'F)7$\"\"($\"+(ed+s\"!#57$\"\")$\"+VkUuF:7$\"#:F M7$F*FM-%'COLOURG6$%$HUEG#F(F1-%*THICKNESSG6#F--F$6%72F'7$F-$\"+=$R'H; F:7$F/Fhn7$F1$\"+0-qK>F:7$F3F\\o7$F5F\\o7$F7F\\o7$F9'Qe#F:7$FLFgo7$FP$\"+6x$Q%HF:7$F*F[p-FS6$ FU#F(F-FW-F$6%72F'7$F-$\"+fe!R=#F:7$F/Fep7$F1Fep7$F3Fep7$F5Fep7$F7Fep7 $F07\"F+7$F-$!*Lr0k\"F+7$F1$\"*#Q,gCFX7$F5$!)Lz@FF+7$F9$ \"'FJUF+7$F=$\")+77BF+7$FA$\")Fe3AF+7$FE$\")t/7HF+7$FI$!)[@*H#F+7$FM$ \"(F+7$F`o$!*&QLz:F+-Fdo6$Ffo#F1F5Fho-F$6%72F'F,F0F4F87$F=$!*39D5\"F+7$ FA$!*E`w0\"F+7$FE$!)$p`<*F+7$FI$!*]Zy]\"F+7$FM$!*27O:\"F+7$FQ$!)')z\"= *F+7$FU$!)wlEwF+7$FZ$!*f=pi\"F+7$Fhn$!*W&pBJF+7$F\\o$!*2(fmeF+7$F`o$!* :*f\"Q&F+-Fdo6$FfoF(Fho-%&TITLEG6#%PVariable~constraint~for~4~firms~an d~16~periods.G-%*AXESSTYLEG6#%'NORMALG-%*AXESTICKSG6$F9F9" 2 252 252 252 2 0 1 0 2 9 0 4 2 1.000000 45.000000 45.000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 21 "DrawVariable(K,4,16);" }}{PARA 13 "" 1 "" {INLPLOT "6 )-%'CURVESG6%727$\"\"\"$\"%L\"*!\"#7$\"\"#$\"',f))!\"%7$\"\"$$\")(RKf) !\"'7$\"\"%$\"+4DWN$)!\")7$\"\"&$\"+M#z`3)F:7$\"\"'$\"+dy\"G%yF:7$\"\" ($\"+@L`2wF:7$\"\")$\"+@tIztF:7$\"\"*$\"+,\"Gz:(F:7$\"#5$\"+e->VpF:7$ \"#6$\"+]X*[t'F:7$\"#7$\"+9x%G`'F:7$\"#8$\"+V#H4m'F:7$\"#9$\"+H%[**f'F :7$\"#:$\"+w*\\>S'F:7$\"#;$\"+x9*)4iF:-%'COLOURG6$%$HUEG#F(F7-%*THICKN ESSG6#F--F$6%72F'F,F17$F7$\"+\"RPoa)F:7$F<$\"+pAV!H)F:7$F@$\"+2sAX!)F: 7$FD$\"+)p&))*)zF:7$FH$\"+gBlEzF:7$FL$\"+b1o>zF:7$FP$\"+N-4#o(F:7$FT$ \"+)>vw^(F:7$FX$\"+ug..vF:7$Ffn$\"+%[n(3zF:7$Fjn$\"+\"3,?r)F:7$F^o$\"+ -*G*[$*F:7$Fbo$\"+N5Yo!*F:-Ffo6$Fho#F(F-Fjo-F$6%72F'7$F-$\"+S^#G8*F:7$ F2$\"+Dqf!3*F:7$F7$\"+jD2h\"*F:7$F<$\"+*3'oe!*F:7$F@$\"+/utA\"*F:7$FD$ \"+/guT#*F:7$FH$\"+#p(yz#*F:7$FL$\"+mm_O5!\"(7$FP$\"+m3V05Fet7$FT$\"+ \"ff1+\"Fet7$FX$\"+()RB05Fet7$Ffn$\"+G&y)45Fet7$Fjn$\"+D0.M6Fet7$F^o$ \"+()=w\"G\"Fet7$Fbo$\"+I!4LC\"Fet-Ffo6$Fho#F2F7Fjo-F$6%72F'F,F1F6F;F? FCFGFKFOFSFW7$Ffn$\"+$GioL'F:7$Fjn$\"+:kvYhF:7$F^o$\"+BPNifF:7$Fbo$\"+ 6J[$y&F:-Ffo6$FhoF(Fjo-%&TITLEG6#%GVariable~K~for~4~firms~and~16~perio ds.G-%*AXESSTYLEG6#%'NORMALG-%*AXESTICKSG6$F " 0 "" {MPLTEXT 1 0 10 "Legend(4);" }}{PARA 13 "" 1 "" {INLPLOT "6,-%'CURVESG6%7$7$\" \"!\"\"$7$\"#5F)-%'COLOURG6$%$HUEG#\"\"\"\"\"%-%*THICKNESSG6#\"\"#-F$6 %7$7$F(F67$F+F6-F-6$F/#F1F6F3-F$6%7$7$F(F17$F+F1-F-6$F/#F)F2F3-F$6%7$7 $F(F(7$F+F(-F-6$F/F1F3-%%TEXTG6%7$\"#6F)%'Firm~1G-%%FONTG6%%&TIMESG%&R OMANG\"#7-FO6%7$FRF6%'Firm~2GFT-FO6%7$FRF1%'Firm~3GFT-FO6%7$FRF(%'Firm ~4GFT-%&TITLEG6#%3Legend~for~4~firmsG-%*AXESSTYLEG6#%%NONEG" 2 252 252 252 2 0 1 0 2 9 0 1 2 1.000000 45.000000 45.000000 0 0 0 0 0 0 0 0 0 0 0 255 25 25 255 25 25 1 2 0 0 0 0 0 0 0 0 0 0 0 }}}{EXCHG {PARA 0 "" 0 "" {TEXT -1 121 "The DrawVariable procedure allows us to focus \+ on certain firms. For the state variables we can also get the T+1'th v alue:" }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 21 "DrawVariable(A,2,1 7);" }}{PARA 13 "" 1 "" {INLPLOT "6'-%'CURVESG6%737$\"\"\"$\"#;!\"#7$ \"\"#F)7$\"\"$F)7$\"\"%F)7$\"\"&F)7$\"\"'F)7$\"\"($\"+(ed+s\"!#57$\"\" )$\"+VkUuF:7$\"#:FM7$F*FM7$\"#F:7$F3F^o7$F5F^o7$F7 F^o7$F9'Qe#F:7$FLFio7$FP$\"+6 x$Q%HF:7$F*F]p7$FSF]p-FU6$FWF(FY-%&TITLEG6#%GVariable~A~for~2~firms~an d~17~periods.G-%*AXESSTYLEG6#%'NORMALG-%*AXESTICKSG6$F3F3" 2 246 246 246 2 0 1 0 2 9 0 4 2 1.000000 45.000000 45.000000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 }}}{EXCHG {PARA 0 "> " 0 "" {MPLTEXT 1 0 0 "" }}}}}}{MARK "5 3 9 0 0" 0 }{VIEWOPTS 1 1 0 1 1 1803 }