I have a complicated code which puts out one value, which I want to minimize. Instead of copy pasting my code I present here a much simpler code which produces the same error.
range[x_] := Range[1, x]
f2[x_, y_, z_] :=
Sum[(Sin[x] Exp[z] ArcTan[y])^n, {n, 1, x}] Norm[range[x]]
Please do not change this code above in your answer since it's not the real code. If I evaluate f2[x,y,z] for some positive and real x,y,z, I get a number. Just as the code I use.
However, if I do this:
NMinimize[{f2[x, y, z], 4 <= x <= 15, 2 <= y <= 4, 4 <= z <= 9}, {x,
y, z}]
I get an error message:
Range::range: Range specification in Range[1,x] does not have appropriate bounds.
How can I change Nminimize, or do something to the function f2 (without changing the code which creates f2) such that NMinimize works?
rangeonly evaluate for numerical values. Try usingrange[x_?NumericQ] := Range[1, x]. – Chris K Apr 11 '20 at 13:31f2should have its argument forxconstrained to being numeric, i.e.,f2[x_?NumericQ, y_, z_] := .... As pointed out in the error message,f2is callingrangewith a symbolic value forx– Bob Hanlon Apr 11 '20 at 13:37