from Adam Matic 2011.08.16.19.15 CET
Bill Powers (2011.08.04.0705 MDT)
Would you like a simple practice problem to work on just to get your feet wet?
Here’s one. A consumer wishes to have Rg amount of goods ("R"eference amount, subcategory "g"oods). The goods inventory already contains N units of goods. The goods cost Cg for each unit. The customer’s money inventory stands at M dollars to start with. Write a control system model for bringing N to the value Rg, by spending money from the inventory M. For various initial values of the variables, determine whether the desired amount of goods will be obtained. Don’t calculate it yourself; make the model show you the answer.
Hint: M is not allowed to go negative.
AM:
Ok, feet in the water. The ruby code is in the attachment.
I don’t like ruby very much. It was fun learning it, but I had a lot of trouble with the Tk GUI library while making the labels and buttons do what I want, and the main event loop which I just barely made work, and I’ll have no idea what to do if things get more complicated.
I’m considering transfering to some other language while the project is still small, but I’m waiting for my laptop to come from the repair shop. Apparently, the power circuits failed and it’s taking them quite a while to fix it. In the meantime, I’m using my roomate’s laptop for short periods of time when she is not on facebook. ![]()
Anyway, I tried to make things as simple as possible, I hope I didn’t over-simplify the code for the control loop.
There is an “actor” with a single loop for controling the quantity of some good X by buying it from the shop. The shop is a simple container of variables, no control loops yet.
Initial variables can be changed in code. The program runs until the actor reaches Rg or is out of money.
By clicking the two buttons “take 1” or “give 1” a user can act as a disturbance by adding or removing one unit of money from the actor.
Standing by for comments.
ecmodel.rb (2.16 KB)
···
The smallest next step, other then fixing errors, I assume, is adding another shop. It would tacke the problem of ‘choosing’. If all else is equal, a person will allways choose a cheaper good. (?) Since all else is rarely equal, we don’t see that law very much. Perhaps one shop is closer to the other, or smells nicer, or our friend works there, or there is some other need being met.
ps. for anyone interested, ruby can be downloaded from: http://www.ruby-lang.org/en/downloads/
make sure to check the ‘tcl/tk’ check box before starting the installation, those are for the GUI libraries
Best, Adam