# Tag Info

## Hot answers tagged mathematical-optimization

9

You´ll find a lot of Mathematica Code on the internet regarding this problem. Your code generates the collate sequence for every number without taking into account, that there are a lot of duplicate calculations. You can approach it via collatz[n_] := collatz[n] = If[EvenQ[n], n/2, 3*n + 1] to remember the calculations, then... collatzSequence[n_] := ...

3

For extra brute force, just Compile it to C code: collatzLength = Compile[{{x, _Integer}}, Module[{c, n}, (For[n = x; c = 1, n != 1, c += 1, If[EvenQ[n], n = Round[n/2], n = 3*n + 1]]); c], CompilationTarget -> "C", RuntimeAttributes -> {Listable}] It computes the first million lengths in under 2 seconds: ...

3

I've found one difference between NonLinearModelFit and FindFit, and that is that NonLinearModelFit does not allow you to use the NormFunction to adjust how normalization as weighting is done. By default NonLinearModelFit seeks to reduce the sum of the squares of the residuals, so it will be equivalent to FindFit with NormFunction -> (Norm[Abs[#], 2] ...

3

Your use of NMaximize has a couple syntax errors. According to the documentation, the restrictions and equations should be given as a list as the first argument, not as the first and second arguments. Also, you have an extraneous {} around your equation and restrictions, so remove those. Finally, remember that LinearProgramming assumes all quantities are ...

3

I don't know if I understand well, but if you want to check, with Mathematica on Unix, if a given file/directory is executable, you'll have to run a specific external unix command line and retrieve the result. Unix useful commands The following concerns UNIX systems but there are probably some equivalent commands for Windows. (Feel free to edit the post if ...

2

Define so it only exists for explicitly numeric intput, as g[x1_?NumberQ,x2_?NumberQ,x3_?NumberQ,x4_?NumberQ,x5_?NumberQ,x6_?NumberQ] Then can do vars = {x1,x2,x3,x4,x5,x6}; NMinimize[{g[x1,x2,x3,x4,x5,x6],Element[vars,Integers] Thread[-2<=#<=2&, vars]}, vars] There are ways to make this slightly cleaner, but that's the idea. The reason ...

2

The following does return a result: pp1= Reduce[{D[K, x1] == 0 && D[K, x2] == 0 && D[K, {x1, 2}] < 0 && D[K, {x2, 2}] < 0 && D[K, {x2, 2}] D[K, {x1, 2}] > D[K, x1, x2]^2 && And @@ region}, {x1, x2}, Reals] Solve[] also works: pp2 = Solve[{D[K, x1] == 0 ...

2

Your collatzLength function is fast on an individual integer, but when you map it to all integers from 1 to a million, the function recalculates values repeatedly. For example, the Collatz series for $n=10$ is $\{10,5,16,8,4,2,1\}$. But the length for $n=5$ would have been already calculated to be 6. Hence, the Collatz length for $n=10$ is $1+6=7$. Use ...

1

A nice little function KT (based on Reduce) that provides both optimal variables and corresponding Lagrange multipliers for simple and small problems can be found here The following code takes about 15sec to evaluate on my pc: f = (3/10)*Exp[-z2]*((9/100)*Exp[-(x + z1)] + (3/10)*Exp[-y]) + (9/100)*Exp[-(x + z1)] + (3/10)*Exp[-x] + (3/10)*Exp[-y] + ...

1

Your question is a bit unclear, because you need r for your first expression, but you obtain u in the second expression. Therefore, I assume that u is to replace r in the first expression. If not, please say so. With that assumption, u = t /. First@NDSolve[{t'[r] == r^3/(Sqrt[0.13 r^3 + 2 r - (0.5)^2] (-0.13 r^3 + r^2 - 2 r + (0.5)^2)), t[0.134] == ...

Only top voted, non community-wiki answers of a minimum length are eligible