I have a code here that needs some help with iteration. Below is the code:
q1 = 1/204.8; q2 = 0.05; bd = { {0, 0}, {0, 0}, {-q2, 155900 q2}, {q1, 0} }; X1 = {{-b0 q1 q2 σ, b0 q1 q2 - b1 q1 q2 σ, b1 q1 q2 - b2 q1 q2 σ, b2 q1 q2 - 155900 q1 q2^2 - q1 q2 σ^2}, {b0 q1^2 σ, -b0 q1^2 + 24304810000 q1^2 q2^2 + b1 q1^2 σ, -b1 q1^2 + b2 q1^2 σ, -b2 q1^2 + 311800 q1^2 q2 + q1^2 σ^2}, {-b0 b2 q1 q2 + 155900 b0 q1 q2^2 + b0 q1 q2 σ^2, -b1 b2 q1 q2 + 155900 b1 q1 q2^2 - b0 q1 q2 σ + b1 q1 q2 σ^2, b0 q1 q2 - b2^2 q1 q2 + 155900 b2 q1 q2^2 - b1 q1 q2 σ + b2 q1 q2 σ^2, b1 q1 q2 - 2 b2 q1 q2 σ + 155900 q1 q2^2 σ + q1 q2 σ^3}, {b0 b2 q1^2 - 311800 b0 q1^2 q2 - b0 q1^2 σ^2, b1 b2 q1^2 - 311800 b1 q1^2 q2 + b0 q1^2 σ - b1 q1^2 σ^2, -b0 q1^2 + b2^2 q1^2 - 311800 b2 q1^2 q2 + 24304810000 q1^2 q2^2 + b1 q1^2 σ - b2 q1^2 σ^2, -b1 q1^2 + 2 b2 q1^2 σ - 311800 q1^2 q2 σ - q1^2 σ^3}}; inverseX1 = Inverse[X1]; X2 = {{-b0 q1^2 - b0 q1 q2, -b1 q1^2 - b1 q1 q2, -b2 q1^2 - b2 q1 q2 + 155900 q1^2 q2, -q1^2 σ - q1 q2 σ}, {b0 q1^2 + b0 q1 q2 - 24304810000 q1^2 q2^2, b1 q1^2 + b1 q1 q2, b2 q1^2 + b2 q1 q2 - 311800 q1^2 q2 - 155900 q1 q2^2, q1^2 σ + q1 q2 σ}, {0, -155900 q1^2 q2, 0, -q1^2 - q1 q2}, {-b0 b1 + 2 b0 b2 σ - 311800 b0 q2 σ - b0 σ^3, -b1^2 - b0 b2 + 311800 b0 q2 - 155900 q1 q2^2 + 2 b1 b2 σ - 311800 b1 q2 σ + b0 σ^2 - b1 σ^3, -2 b1 b2 + 311800 b1 q2 - b0 σ + 2 b2^2 σ - 311800 b2 q2 σ + b1 σ^2 - b2 σ^3, b0 - b2^2 + 311800 b2 q2 - q1 q2 - 24304810001 q2^2 - 2 b1 σ + 3 b2 σ^2 - 311800 q2 σ^2 - σ^4}}; value1 = {b0 -> 155900 q1 q2, b1 -> 10 Sqrt[1559] Sqrt[-2 q1^2 q2 + 311798 q1 q2^2 + q1 q2 σ^2], b2 -> 1/2 (311800 q2 + σ^2)}; value2 = {σ -> Sqrt[2] \[Sqrt](-10 Sqrt[3118] Sqrt[q1] Sqrt[q2] - 155900 q2 + \[Sqrt](q1^2 + 20 Sqrt[3118] q1^(3/2) Sqrt[q2] + 623602 q1 q2 + 3118020 Sqrt[3118] Sqrt[q1] q2^(3/2) + 24304810001 q2^2))}; X = X2.inverseX1; J = (-Transpose[bd].X) /. value1 /. value2
The code above is to calculate value of J
based on the input given in q1
. Suppose that I want add below code and change q1=
into this:
i = Input["Number of examples?"]; v = RandomInteger[200, i] q1 = 1/v;
How do I do the looping process for the code above and get each value of J
based on the number of different q1
generated? I’m kinda lost at looping the code above. I’ve tried looking at Table
, For
, Do..while
but I’m not too sure on how to do it correctly. Your help is greatly appreciated.