tl;dr version: Everything you need to know is right here (except when A is singular, in which case you'll need this too to find discrete time B) which tells you about converting back and forth from continuous to discrete time in a problem like this, namely, given the system:
for vectors x(t) and u(t) and constant matrices A and B and u(t) held constant over each sample period T, we have the discrete time equivalent:
Notice that the discrete time constant matrix coefficients Ad and Bd are dependent on the sample period T.
Success!! (I think). I changed my previous spreadsheet to make it truly invariant to the sample period (Ts in the green box below). Please refer to the previous version and the description underneath the spreadsheet for what the formulas are doing and the discrete time state space representation of the system, and to links to Jason and Ramanan's blogs (from whence this whole exercise originated). Below the spreadsheet on this page I describe what I'm doing differently. Feel free to play with the values: I only planned on people editing the green cells (in this embedded version), and if you get it irrevocably screwed up, just refresh the page (you can't hurt my original copy). Also you can download your own copy using the tool on the right side of the black toolbar running along the bottom of the sheet. Note that setting Ts < 0.1 will limit the data to less than 100 years (so the plot won't be filled out) because the number of time samples in my table is fixed at 1000.
Note the names and values with the modifier "alt" in them below don't affect anything: they're part of an experiment to get SIM2 to always satisfy all of G&L's accounting expressions. I've had success with the ΔH = G - T expression by using T-alt (in columns to the right, you have to scroll to see). I did add T-alt to the plot so you can see how it differs slightly from T. More in Update 5 below and here.
dx/dt = A∙x + B∙u
for vectors x(t) and u(t) and constant matrices A and B and u(t) held constant over each sample period T, we have the discrete time equivalent:
end tl;dr
Success!! (I think). I changed my previous spreadsheet to make it truly invariant to the sample period (Ts in the green box below). Please refer to the previous version and the description underneath the spreadsheet for what the formulas are doing and the discrete time state space representation of the system, and to links to Jason and Ramanan's blogs (from whence this whole exercise originated). Below the spreadsheet on this page I describe what I'm doing differently. Feel free to play with the values: I only planned on people editing the green cells (in this embedded version), and if you get it irrevocably screwed up, just refresh the page (you can't hurt my original copy). Also you can download your own copy using the tool on the right side of the black toolbar running along the bottom of the sheet. Note that setting Ts < 0.1 will limit the data to less than 100 years (so the plot won't be filled out) because the number of time samples in my table is fixed at 1000.
Note the names and values with the modifier "alt" in them below don't affect anything: they're part of an experiment to get SIM2 to always satisfy all of G&L's accounting expressions. I've had success with the ΔH = G - T expression by using T-alt (in columns to the right, you have to scroll to see). I did add T-alt to the plot so you can see how it differs slightly from T. More in Update 5 below and here.
NOTE (update of 2016.04.22): in the above sheet to calculate the so-called experimental "alt" version of values use CTalt = (1-A)/Ts and DTalt = (Ts-B)/Ts and alpha2alt = CTalt/DTalt, where A and B are a function of the new sample period Ts (assuming the old one Ts0 = 1). These expressions come from T as a function of Ts := T(Ts) = T*Ts = G(Ts) - ΔH(Ts) = G[n]*Ts - H[n](Ts) + H[n-1] = G[n]*Ts - A*H[n-1] - B*G[n] + H[n-1] = (1-A)*H[n-1] + (Ts-B)*G[n] = CTalt*H[n-1] + DTalt*G[n], assuming H[n-1] didn't change with Ts, and that A and B are functions of Ts, and that B requires multiplication by G expressed in old units (i.e. per Ts0). Then our new T expressed in old units as a rate (i.e. dollars per Ts0) is just T = T(Ts)/Ts = ((1-A)/Ts)*H[n-1] + ((Ts-B)/Ts)*G[n], thus matching terms we have CTalt = (1-A)/Ts and DTalt = (Ts-B)/Ts, and because C/D = alpha2 (where C is Cm, not SIM's consumption output C), then alpha2alt = CTalt/DTalt. I think the idea came from SIM3. Also see SIM5. Talt is calculated in terms of CTalt and DTalt in the columns you need to scroll to the right to see. The alpha2alt isn't actually used for anything (I don't think). It's a given that this experiment will "work" and that Jason's Γ = 1 for all Ts (the purpose of the "experiment"), given that we could just directly calculate Talt from the other columns: namely Talt = G - ΔH/Ts where the Talt and G columns are expressed as dollars per Ts0. Thus ΔH/Ts is just ΔH expressed in those same units. But ultimately the alpha2alt I calculate here doesn't lead anywhere. In contrast, SIM6 is a successful approach: it adjusts both alpha1 and alpha2 (but not theta) to change sample periods without affecting steady state values (expressed in dollars per Ts0 and in dollars for the case of H) or the time constant Tc (expressed in Ts0). An update there of the date of this update explains why you adjust alpha1 and alpha2 but not theta to accomplish that. Given that Ts is changed by changing these parameters, then it's a given that Jason's Γ = 1 for all Ts in SIM6 as well. That's not really the case here in SIM2 because the resultant alpha2alt is not used (because there's probably not a way to make it useful). Thus really Jason's Γ ≠ 1 for all Ts here (i.e. using the method here to change sample periods). And no, alpha2alt here is not equal to the alpha2 from SIM6. However, that's not to say that the SIM3 idea didn't ultimately lead to a greater success: see SIM9 and SIM10 for example.
The problem with my previous sheet was that the H curve changed when I changed the sample period (Ts). This was in spite of modifying the alpha2 parameter as per Ramanan's instructions.
I've changed tactics here: instead of scaling alpha2 (from a user provided alpha2_R parameter), I instead just use the User Parameters (in the green cells) directly without doing any modifications, (e.g. modifications such as scaling alpha2 by the ratio of change in the sample period (Ts/Ts_orig)).
What I do instead is record the original Ts setting (Ts_orig = 1 years). Then from the alpha1, alpha2 and theta parameters I derive continuous time parameters for the system. In particular I do the following:
Starting with the original discrete time system with A_orig and B_orig based on alpha1, alpha2 and theta, we have:
H[n+1] = A_orig*H[n] + B_orig*G[n+1]
From this I calculate the parameters for an equivalent continuous time system assuming G is held constant over each sample period:
dH(t)/dt = H'(t) = a_cont*H(t) + b_cont*G(t)
From this continuous time system, I re-descretize it with a new sample period (the user input sample period Ts in the green cells in the upper left). This gives me a new A and a new B, which I simply call A and B like in the old spreadsheet, and use them as follows in the results table:
H[n+1] = A*H[n] + B*G[n+1]
Here's how I do the calculations. First I assume the A_orig and B_orig resulted from a discetization of a continuous time system with an original sample period Ts = 1 year (Ts_orig = 1). Thus:
A_orig = expm(a_cont*Ts_orig) = exp(a_cont*Ts_orig) (matrix exponentiation expm() reduces to scalar exponentiation exp() in this case, since the system has a single state).
B_orig = (A_orig - 1)*b_cont/a_cont (to see why this is, look here).
I solve for a_cont and b_cont from the above, and then use these same formulas with a new sample period (Ts) to calculate A and B.
Some of these calculations are performed in the cells to the right of the chart, and the rest are in the cells for the A and B matrices respectively.
Matrices C and D (used for calculating the measurement vector [Y T YD C]' at sample n+1 by scaling H[n] and G[n+1] respectively), were not changed.
Now (you may notice) instead of H changing with Ts, ΔH changes with Ts. Is that a problem? I don't think so, because it SHOULD change with Ts: each Ts period of time now adds less to the total stock of money in the economy. H should NOT be changing with Ts, because the sample period should not affect the total stock of money accumulated in the economy at a fixed time in years.
---------------------------------------------------------------------------------------------------------------------------
Further information about calculating A and B as a function of Ts/Ts_orig:
DoΔ Δ
Starting with A_orig and B_orig and doing a little algebra reveals:
(1) A_orig = A(Ts_orig) = 1 - theta * alpha2 / (1 - alpha1 * (1 - theta))
(2) B_orig = B(Ts_orig) = 1 - theta / (1 - alpha1 * (1 - theta))
I write A(Ts_orig) and B(Ts_orig) because they are implicit functions of Ts_orig! Equations (1) and (2) were our starting point for A and B on the previous spreadsheet. Now what happens when we change Ts_orig to Ts?:
(3) A(Ts) = A_orig^(Ts/Ts_orig)
(4) B(Ts) = (B_orig/(A_orig - 1)) * (A(Ts) - 1) = -[(1 - alpha1*(1 - theta) - theta)/(theta*alpha2)] * (A(Ts) - 1)
Note: I didn't bother with that algebra in the spreadsheet above: I just used exp() and ln() according the the development above equation (1).
Enjoy!
UPDATE 1: March 6, 2016 1:02 AM
I made a few changes to the plot to eliminate apparent sensitivity to Ts. Basically two things: I start the plot at t=0 years, but I start the table at -Ts. Secondly, instead of plotting H (which I leave in the main table), I plot H[n-1] (H delayed by one). H[n-1] takes the place of x[n] in a normal (canonical) discrete time state space formulation, so I suspected that I was plotting the wrong sequence against the others (off by one), and sure enough, once I changed that it helped quite a bit. The plot now shows near complete Ts invariance, as it should.
UPDATE 1: END
UPDATE 2: March 7, 2016 9:06 PM
Note that I resolved my problem with the old method of changing sample periods suggested by Ramanan on that older post, and I've updated it accordingly (read Update #2 there at the top). However that doesn't mean that the alpha2 scaling method is the same as this method: it is for small values of Ts, but try Ts >= 10 on this sheet and that one to see how they still differ.
UPDATE 2: END
UPDATE 3: March 8, 2016 12:33 AM
Note the Γ below is Jason Smith's Γ from his March 2016 posts on SIM.
UPDATE 3: END
UPDATE 4: March 9, 2016, 5:21 PM
I made a new version called SIM3 posted here which combines the best of the version above (SIM2) with the old version (SIM), for the price of restricting the functional form of G.
UPDATE 4: END
UPDATE 5: March 13, 2016, 2:50 PM
I added some "alternative" parameters and variables to the spreadsheet. They don't affect any of the previous parameters or the plot, except that I've plotted T-alt to the plot. It differs slightly from T when Ts is changed. T-alt satisfies G&L's ΔH = G - T (actually ΔH = Ts*(G - T) since G and T are always rates expressed in dollars/(Ts_orig = Ts1 = 1 period = 1 year) in SIM2). Eventually there will be alternate versions of theta (thetaalt) and alpha1 (alpha1alt) as well. The idea is to eventually satisfy ALL of G&L's accounting equations, while maintaining sample period invariance, and matching G&L at Ts=1 (at least with G functions restricted to the form of their example). I have more information about it under the heading "SIM5" on a new post called SIM5.
UPDATE 5: END
UPDATE 6: March 17, 2016, 10:17 AM
As I explain in a new post (SIM6), and in a comment on Jason's blog, think Jason's Γ (above) represents both an approximate change to a new sample time (without actually changing the sample time values in the table), thus a time constant change without a change in steady states (what I explain in the comment). And, as I explain in the text of SIM6 below the spreadsheet) Jason's Γ as calculated above represents the difference between a sampled rate variable (like I treat G, Y, T, YD and C in the spreadsheet in this post) and an average rate calculated across a sample period interval (how they are treated in SIM and SIM6). As Ts gets larger, that difference grows.
UPDATE 6: END








