17

A simple example of the use of formal symbols is for mathematical tasks that require the use of dummy variables. Most functions like Plot will localize their dummy variables, but not all. For example, LinearModelFit will not work with symbols that already have a value assigned to them: x = 1; LinearModelFit[RandomReal[1, {10, 2}], {1, x}, x] (spits out ...


12

These are typically used when you are making symbolic transformations and you don't want to risk failure from existing global definitions. For example: Sin'[\[FormalX]] D[Sin[\[FormalX]], \[FormalX]] Integrate[Sin[\[FormalX]], {\[FormalX], 0, \[FormalY]}] Sum[Sin[t], {t, 0, \[FormalX]}] Limit[Sin[\[FormalX]]/\[FormalX], \[FormalX] -> 0] All of ...


9

These are considered special and used by System` functions. Bad things could happen if values are assigned to them. DifferenceRootReduce[n^2 + 1, n] (* DifferenceRoot[Function[{\[FormalY], \[FormalN]}, {(-2 - 2 \[FormalN] - \[FormalN]^2) \[FormalY][\[FormalN]] + (1 + \[FormalN]^2) \[FormalY][1 + \[FormalN]] == 0, \[FormalY][0] == 1}]][n] *) ...


6

The problem is that sort doesn't evaluate when the list is ordered. See what happens when you increase the nesting: NestList[sort, {5, 4, 3, 2, 1}, 12] {{5, 4, 3, 2, 1}, {4, 5, 3, 2, 1}, {4, 3, 5, 2, 1}, {3, 4, 5, 2, 1}, {3, 4, 2, 5, 1}, {3, 2, 4, 5, 1}, {2, 3, 4, 5, 1}, {2, 3, 4, 1, 5}, {2, 3, 1, 4, 5}, {2, 1, 3, 4, 5}, {1, 2, 3, 4, 5}, sort[{...


4

Here is my approach, building on Rojo's original from the linked quesiton. I use a primary function partition2 and two auxiliary functions f1 and f2. I believe this is working but I have not tested it extensively yet. Usage partitions2 spits out an object that includes continuation information. f1 extracts the partition for use. f2 produces the next ...


3

For is generally avoided as inefficient. Using a pure Function with Map data = T1 /. Solve[# == -4.84*10^(-4) - 17.82*10^(-4)*T1 + 1.53*10^(-4)*T1*2.303*Log[T1], T1][[1]] & /@ Range[0, 5] // Quiet (* {158.54, 1329.7, 2164.72, 2915.71, 3619.49, 4291.32} *) Plotting the results ListLinePlot[data, DataRange -> {0, 5}, AxesLabel -> {...


3

If you need to make a variable available for many threads in parallel computing, you should check out DistributeDefinitions. If you need parallel processing, you should first try built-in parallel functions like ParallelTable before running many copies of the whole Mathematica. In case you need dedicated kernels called from external software, consider ...


2

Perhaps this is what you are looking for. It is the best I can do when trying to guess what you really want to compute. My goal here is show you how your For-loop can be fixed, rather than to instruct you in the better methods available to solve your problem. For[mu = 0, mu < 6, mu++, sol = Quiet @ NSolve[ mu == -4.84*10^(-4) - 17.82*10^(...


2

Outer[Total[AdjacencyMatrix[g][[#, #2]], 2] &, SCCs, SCCs, 1] {{0, 0, 0, 0}, {1, 0, 0, 0}, {0, 0, 0, 0}, {1, 5, 3, 30}} or Outer[Length[AdjacencyMatrix[g][[#, #2]]["NonzeroPositions"]] &, SCCs, SCCs, 1] {{0, 0, 0, 0}, {1, 0, 0, 0}, {0, 0, 0, 0}, {1, 5, 3, 30}} or ecounts = Outer[EdgeCount[g, DirectedEdge[Alternatives @@ #, Alternatives @@ #...


2

Here is one implementation of your algorithm: firstTrue[f_] := next[f, 1, Infinity] next[f_, last_, cur_] := If[last + 1 == cur, If[f[last], last, cur], If[f[last], next[f, dec[last], last], next[f, inc[last], cur]] ] inc[n_] := With[{e = IntegerExponent[n, 2]}, If[n == 2^e, 2^(e+1), n + 2^(e-1)] ] dec[n_] := With[{e = IntegerExponent[n, 2]}, ...


1

ClearAll[edgeW, gr, m, n, mm, sa, wG, paths, pathMult, sccL, grSCCl]; n = 17; edgeW = Module[{g = #, e = DirectedEdge @@@ Partition[#, 2, 1] & /@ FindPath[##, ∞, All]}, Transpose[{e, PropertyValue[{g, #}, EdgeWeight] & /@ # & /@ e}]] &; Manipulate[SeedRandom[1245]; mm = RandomReal[1, {n, n}]; gr = RandomGraph[{n, m}, DirectedEdges -...


1

I think the new MutationHandler code is designed for this sort of thing. Here is one implementation: ClearAll[ObjHandler] SetAttributes[ObjHandler, HoldAll]; ObjHandler[Set[m_Symbol?objQ[key_String], rhs_]] := ( Extract[ m, 1, Function[Null, AssociateTo[#, key->rhs], HoldAll] ]; rhs ) Language`SetMutationHandler[Obj, ...


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