2
$\begingroup$

I have a expression of the following form:

$$x_{t}=a_{0}+a_{1}x_{t-1}+a_{2}y_{t-2}$$

where $a$'s are just coefficients and anything with time subscript is a variable. I would like to have list of variables in $x_t$ (that would be $x_{t-1}$ and $y_{t-2}$) and find the coefficient for variable say $y_{t-2}$ (which is $a_{2}$). Mathematica's Variables[x] and Coefficient[x] functions don't work here.

$\endgroup$
  • 2
    $\begingroup$ Show us the expression IN MATHEMATICA CODE, rather than $\LaTeX$. $\endgroup$ – MarcoB Aug 17 '17 at 14:56
3
$\begingroup$

Using @Alucard's setup slightly modified:

b = Thread[Subscript[#1, #2] &[{x, y, z}, {t - 3, t - 4, t - 6}]];
bb2 =  Subscript[x, t] == Subscript[a, 5] Subscript[d, 9 + q] + 
   Dot[Subscript[c, #] & /@ Range[Length[b]], b]

Block[{Times = List, Plus = List}, 
 Cases[#, {_, Subscript[_, s_ /; Not[FreeQ[s, t]]]}, Infinity]] /.
   Subscript[v_, s : {__}] :> Subscript[v, Plus @@ s]& @ bb2

{{Subscript[c, 1], Subscript[x, -3 + t]}, {Subscript[c, 2], Subscript[y, -4 + t]}, {Subscript[c, 3], Subscript[z, -6 + t]}}

TeXForm[%]

$\left( \begin{array}{cc} c_1 & x_{t-3} \\ c_2 & y_{t-4} \\ c_3 & z_{t-6} \\ \end{array} \right)$

$\endgroup$
2
$\begingroup$

(example data)

b = Thread[Subscript[#1, #2 ] &[{x, y,z}, {t - 3, t - 4,t-6}]]   

bb = Subscript[x, t] == Dot[Subscript[c, #] & /@ Range[Length[b] ], b]

$$ x_t=c_1 x_{t-3}+c_2 y_{t-4}+c_3 z_{t-6} $$ applying

{bb[[2, #, 1]], bb[[2, #, 2]]} & /@ Range[Length[b]  ]

gives a 3x2 list with the variables and the corresponding coefficient

$\endgroup$
0
$\begingroup$

If your expressions are similar to those in your previous questions:

xtRule=x[t]->a[0]+a[1] x[t-1]+a[2] y[t-2]+a[3]z[t-1]+\[Epsilon][t];
ytRule=y[t]->b[0]+b[1] y[t-1]+b[2] i[t-2]+b[3]z[t-1]+\[Eta][t];
ztRule=z[t]->p[1]z[t-1]+p[2]i[t-1]+\[Upsilon][t];
itRule=i[t]->r i[t-1]+(1-r)g y[t-2]+\[Omega][t];

You could do something like:

coefValues[Rule[from_, to_]] := Module[{vars, data, construct},
  vars = to /. a_[t_ + b_] :> Sow[a[t + b]] // Reap // Last // 
     Flatten // Union;
  construct["variables"] = vars;
  (construct[#] = Coefficient[to, #]) & /@ vars;
  construct[] = First[CoefficientArrays[to, vars]];
  construct]

Usage:

In[17]:= coefValues[xtRule]["variables"]

Out[17]= {x[-1 + t], y[-2 + t], z[-1 + t]}

In[18]:= coefValues[xtRule][x[t - 1]]

Out[18]= a[1]

In[19]:= coefValues[xtRule][z[t - 1]]

Out[19]= a[3]

In[20]:= coefValues[xtRule][]

Out[20]= a[0] + \[Epsilon][t]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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