# Get all parameters

Posted 9 years ago
3149 Views
|
2 Replies
|
1 Total Likes
|
 (* Capture Recapture History *)  myCHcc[K_] := Table[IntegerDigits[n, 2, K], {n, 1, 2^K - 1}]  (* Capture Recapture Probability *)  myindprobCC[CH_]:=Module[{K,ind,fi,li,d,ans},     (* Get $K$ *)    K = Length[ CH ];        (* None Zero Positions *)    ind = Position[ CH, _?(# != 0 &) ];    fi = ind[[1]][[1]];    li = ind[[-1]][[1]];        (* Get probabilities *)        ans =  Sum[   Product[ Subscript[\[Phi], j], {j, fi, d - 1}]   *   (1 - Subscript[\[Phi], d])   *   Product[    Subscript[p,j]^CH[[j]]    *    (1-Subscript[p,j])^(1 - CH[[j]]),    {j, fi + 1, d}   ],   {d, li, K}  ]]xij = myCHcc[3]ans = Map[myindprobCC, xij]I have been a long time Maple user, so sorry if the questions are a bit basic.Now,how I do get all the parameters in "ans"? What I hope to have is a derivative matrix (Jacobian) from the vector "ans".In Maple, there is a function called "indets"http://www.maplesoft.com/support/help/Maple/view.aspx?path=indetsSo, quickly, I can apply the "D" fucntion to the "ans" with respect to the "parameters".Is there a similar function in Mathematica?This is just a simple "ans" that I am testing, so the solution from an earlier post for mehttp://community.wolfram.com/groups/-/m/t/224025?p_p_auth=gS9GUIxXdoes not work in this case.Also, just a side to this piece of code,is there a "proper" way to get the integer from the linefi = ind[[1]][[1]];the [[1]][[1]] seems "unnecessary" to me. So I wonder is this the correct way to do it.Thanks,
2 Replies
Sort By:
Posted 9 years ago
 That's perfect! Thanks! I am one more step closer to getting everything from Maple to Mathematica.Just to note, D[ans, {Variables[ans]}]is good enough for me, rather than using the Outer functionOuter[D, ans, Variables[ans]]
Posted 9 years ago
 Seems like Variables is suitable for this. Variables[ans]  (* Out[67]= {Subscript[p, 2], Subscript[p, 3], Subscript[\[Phi], 1], \ Subscript[\[Phi], 2], Subscript[\[Phi], 3]} *)  In[70]:= jac = Outer[D, ans, Variables[ans]]  (* {{0, 0, 0,   0, -1}, {0, -Subscript[\[Phi], 2] (1 - Subscript[\[Phi], 3]),  0, -1 + (1 - Subscript[p, 3]) (1 - Subscript[\[Phi], 3]), -(1 -      Subscript[p, 3]) Subscript[\[Phi], 2]}, {0,  Subscript[\[Phi], 2] (1 - Subscript[\[Phi], 3]), 0,  Subscript[p,   3] (1 - Subscript[\[Phi], 3]), -Subscript[p, 3] Subscript[\[Phi],   2]}, {-Subscript[\[Phi],     1] (1 - Subscript[\[Phi], 2]) - (1 - Subscript[p,      3]) Subscript[\[Phi], 1] Subscript[\[Phi],    2] (1 - Subscript[\[Phi], 3]), -(1 - Subscript[p,      2]) Subscript[\[Phi], 1] Subscript[\[Phi],   2] (1 - Subscript[\[Phi],     3]), -1 + (1 - Subscript[p, 2]) (1 - Subscript[\[Phi], 2]) + (1 -       Subscript[p, 2]) (1 - Subscript[p, 3]) Subscript[\[Phi],    2] (1 - Subscript[\[Phi],      3]), -(1 - Subscript[p, 2]) Subscript[\[Phi],    1] + (1 - Subscript[p, 2]) (1 - Subscript[p, 3]) Subscript[\[Phi],     1] (1 - Subscript[\[Phi], 3]), -(1 - Subscript[p, 2]) (1 -     Subscript[p, 3]) Subscript[\[Phi], 1] Subscript[\[Phi],   2]}, {-Subscript[p, 3] Subscript[\[Phi], 1] Subscript[\[Phi],   2] (1 - Subscript[\[Phi], 3]), (1 - Subscript[p,     2]) Subscript[\[Phi], 1] Subscript[\[Phi],   2] (1 - Subscript[\[Phi], 3]), (1 - Subscript[p, 2]) Subscript[p,   3] Subscript[\[Phi],   2] (1 - Subscript[\[Phi], 3]), (1 - Subscript[p, 2]) Subscript[p,   3] Subscript[\[Phi],   1] (1 - Subscript[\[Phi], 3]), -(1 - Subscript[p, 2]) Subscript[p,   3] Subscript[\[Phi], 1] Subscript[\[Phi],   2]}, {Subscript[\[Phi],    1] (1 - Subscript[\[Phi], 2]) + (1 - Subscript[p,      3]) Subscript[\[Phi], 1] Subscript[\[Phi],    2] (1 - Subscript[\[Phi], 3]), -Subscript[p, 2] Subscript[\[Phi],   1] Subscript[\[Phi], 2] (1 - Subscript[\[Phi], 3]),  Subscript[p, 2] (1 - Subscript[\[Phi], 2]) +   Subscript[p, 2] (1 - Subscript[p, 3]) Subscript[\[Phi],    2] (1 - Subscript[\[Phi], 3]), -Subscript[p, 2] Subscript[\[Phi],    1] + Subscript[p, 2] (1 - Subscript[p, 3]) Subscript[\[Phi],    1] (1 - Subscript[\[Phi], 3]), -Subscript[p,    2] (1 - Subscript[p, 3]) Subscript[\[Phi], 1] Subscript[\[Phi],   2]}, {Subscript[p, 3] Subscript[\[Phi], 1] Subscript[\[Phi],   2] (1 - Subscript[\[Phi], 3]),  Subscript[p, 2] Subscript[\[Phi], 1] Subscript[\[Phi],   2] (1 - Subscript[\[Phi], 3]),  Subscript[p, 2] Subscript[p, 3] Subscript[\[Phi],   2] (1 - Subscript[\[Phi], 3]),  Subscript[p, 2] Subscript[p, 3] Subscript[\[Phi],   1] (1 - Subscript[\[Phi], 3]), -Subscript[p, 2] Subscript[p, 3]    Subscript[\[Phi], 1] Subscript[\[Phi], 2]}} *)