I need to automatically form a list of equations that later will be used in FindRoot
. The number of equations (NN) is variable, so I need to use a For loop. When I am doing this
LstEqns = {}; For[i = 1, i <= NN, i++,
LstEqns =
Append[LstEqns,
NIntegrate[Eq[i], {x, 0, L}] == 0];
];
I am getting a warning that L
is not a valid limit of integration (the value is not provided at this point) and in the list I am not getting i
substituted by its proper values, i.e. LstEqns
looks like {NIntegrate[Eq[i], {x, 0, L}] == 0,...}
instead of {NIntegrate[Eq[1], {x, 0, L}] == 0,...}
.
The value of L is provided later (as well as actual Eq[i]
), after forming the list.
So the question is - how can I get a list of equations with a proper numbering?
Mathematica 11.3 is what I am using if this matters.
UPD
n = 1;
LstEqns2 :=
Inactive[NIntegrate][#[[1]], {x, 0, L}] == 0 & /@ Transpose[{eqns2}];
eqns2 = Array[Eq, n];
theEqns2 = LstEqns2;
Eq[1] = x*y + 1;
L = 1;
FindRoot[theEqns2, {y, 0}, Evaluated -> False]
- doesn't work ("The function value is not a list of numbers")
Manually copying the output of theEqns2 into FindRoot doesn't work either:
FindRoot[Inactive[NIntegrate][x*y + 1, {x, 0, L}], {y, 0},
Evaluated -> False]
- same error
However, the same line as above will work if I delete inactive NIntegrate (that has a different color in Mathematica) and placeholder and then write NIntegrate again
FindRoot[NIntegrate[x*y + 1, {x, 0, L}] == 0, {y, 0},
Evaluated -> False]
- this code works
N
as a variable because it has a predefined meaning in Mathematica. Second, useHold
orInactive
, for example:Hold@NIntegrate[Eq[i], {x, 0, L}]
orInactive[NIntegrate][Eq[i], {x, 0, L}]
. $\endgroup$