Tag Info

Hot answers tagged

11

Your basic requirement is met with: safeExport[file_String, args___] := If[ ! FileExistsQ[file] || ChoiceDialog["File already exists. Overwrite?"], Export[file, args], $Failed ] What you describe as "attributes" (e.g. PlotRange -> All) are known as Options or named optional arguments. (See Attributes for a description of what that ...


9

As was pointed out above, this is a good summary of Mathematica's constrained optimization methods. Read through this if you want to know a lot more. A quick answer is below: The answer to your question is strongly dependent on the function you want to maximize. Convex functions can be maximized quite easily, with the error controlled by the PrecisionGoal ...


4

ClearAll[eF] eF[z_: y] := Module[{j = 1, p = Partition[#, 2]}, First[Times @@ (z[Length@p] - p[[-1]]) Exp[Total[(Subtract[##] 2 z[j++] + {#-#2}^2) & @@@ p]]]] & Examples: ClearAll[a, b, c, d, e, f] eF[][{a, b, c, d}] (* E^((a-b)^2+(c-d)^2+2 (a-b) y[1]+2 (c-d) y[2]) (-c+y[2]) (-d+y[2]) *) eF[][{a, b, c, d, e, f}] (* E^((a-b)^2+(c-d)^2+(e-f)^2+2 ...


2

I would do something like this: autoPTAtkHill[portionOfPT_, portionOfCT_, m_] := Module[{ptBlocks, ctBlocks, ctMatrix, ptMatrix, inversePTMatrix}, ptBlocks = Partition[stringToNumbers[portionOfPT], m]; ctBlocks = Partition[stringToNumbers[portionOfCT], m]; ctMatrix = {ctBlocks[[1]], ctBlocks[[2]]}; ptMatrix = {ptBlocks[[1]], ptBlocks[[2]]}; ...


2

list1 = {{0, 0, 0, 0}, {0, 0, 0, 1}, {0, 0, 1, 0}, {1, 1, 1, 1}}; list2 = {1, 5, 5, 5}; Grid[Prepend[Transpose[{Row[{"(", Row[#, ","], ")"}] & /@ list1, list2}], {"Initial Vector", "Period"}], Dividers -> {2 -> True, 2 -> True}] or Grid[Join[{{"Initial Vector", "Period"}}, Transpose[{Row[{"(", Row[#, ","], ")"}] & /@ ...


1

You could define y to be an optional argument which will get the default value a when no value for y is supplied. f[x_, y_: a] := x^2 + y^2 {f[u, v], f[u]} {u^2 + v^2, a^2 + u^2}


1

Not sure if this help or not but you can try it: fTest[f_, variables_] := Module[variables, NMinimize[{f, 1 >= x >= 0, 1 >= w >= 0}, {x, w}]] ans=fTest[y, {x, w}] (*1., {x$8300 -> 0., w$8300 -> 1.}}*) The easiest way I found is as follows: ToExpression[StringReplace[ToString[ans], "$" :> "+0*"]] (*{-1., {x -> 0., w -> ...



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