Tag Info

Hot answers tagged

8

You must remember that Unevaluated only "works" when it is the explicit head of an expression. In the non-working format the structure looks like: TreeForm @ HoldForm[lispify /@ Unevaluated /@ {arg1, arg2}] Note that Unevaluated does not surround arg1 and arg2 therefore they evaluate prematurely. Now compare the working structure: TreeForm @ ...


7

As suggested in the comments by both me and Jens r = Defer[Integrate][Cos[x], x]; r /. Defer -> Identity Sin[x]


6

Body of Manipulate is wrapped by Dynamic and Dynamic doesn't know what's inside inner Dynamics, that's how we can screen a variable to not prompt the very outer Dynamic to evaluate: Manipulate[ e = RandomVariate[NormalDistribution[0, sigma], n]; {Dynamic@a, e}, {{n, 3}, 1, 5, 1, Appearance -> "Labeled"}, {{sigma, 1}, 1, 2, Appearance -> ...


5

There will be more clever answers from people who better understand Mathematica's order of evaluation and how to use Hold and such, and so I can't answer your question in exactly the way that you've phrased it, but here's how I go about doing these types of things. First, instead of declaring the values of x, omega, and R as you've done, make a list of ...


5

Defer is a special head that behaves like Hold, but it has an additional rule for output: it disappears from the output box expression. There is nothing special about how it is handled as input -- all the "magic" takes place during output formatting. To emulate this process, simply apply a ToBoxes ToExpression pair: r = Defer[Integrate][Cos[x], x]; r // ...


4

Reading your question and comments again, and assuming that none of your pure functions contain SlotSequence, I think maybe this will work for you: combine[expr_] := Max[ Cases[expr, Slot[n_] :> n, {-2}], Cases[expr, Verbatim[Function][x_List, __] :> Length@Unevaluated@x, {1}] ] // Function @@ {Through[expr @@ Array[Slot, #]]} & Test: f ...


3

I think $PreRead may be your only hope (but see below). You can set it up with $PreRead = (# /. RowBox@{"PermanentRespect", "[", expr_, "]"} | RowBox@{"PermanentRespect", "@", expr_} | RowBox@{expr_, "//", "PermanentRespect"} :> RowBox@{"RawBoxes", "[", MakeBoxes@expr, "]"} ) &; LoseRespect[expr_] := expr /. RawBoxes -> ToExpression ...


3

We can replace something, in all definitions associated with a symbol, using function like this: ClearAll[replaceExtendedDefinition] SetAttributes[replaceExtendedDefinition, HoldFirst] replaceExtendedDefinition[sym_, rules_] := Replace[ Language`ExtendedDefinition[sym] , (rule:Rule | RuleDelayed)[lhs_, rhs_] :> ...


2

My quick-n-dirty take on this: mergef = Module[{ds = Symbol /@ ("s" <> ToString@# & /@ Range@100), fs = ##, rf}, rf = Plus@Through[fs[Sequence @@ ds]]; Function @@ {Take[ds, Max[Position[ds, #] & /@ Cases[rf, Alternatives @@ ds, Infinity]]], rf}] &; (* do some stuff *) f = # &; g = Function[{a}, a^2]; h = (-2 ...


2

Could this work for you? f = # &; g = #^2 &; h = (-2 #1 + #3) &; totalfunc = (f + g + h) /. f_[fl__Function] :> Module[{arg = {fl} /. Function -> List, int}, int = f @@ arg; Function @@ (Evaluate[int]) ] totalfunc[6, 3, 3] ==> 33 The replacement rule is rather general. EDIT: In the case you ...


2

I don't believe you can do it with Through[ ]. The following works: f = {#1, #2} &; g = Sin[{#1, #2}/#3] &; h = Cos[{#1 + #2, #3 + #4 + #5}] &; expr = Evaluate[(Plus @@ (First /@ {f, g, h}))] & (* {Cos[#1 + #2] + Sin[#1/#3] + #1, Cos[#3 + #4 + #5] + Sin[#2/#3] + #2} & *) expr[a, b, c, d, e] (* {a + Cos[a + b] + Sin[a/c], b + Cos[c + d ...


2

Is this near to what you are looking for? ClearAll[f, g, h] f1[s__] := Total@Take[{s}, 3]; f2[s__] := Times @@ Take[{s}, 2]; f3[s__] := {s}[[1]] {s}[[3]] - {s}[[2]] {s}[[4]]; expr = Through[(f + g + h)[##]] & w = expr /. {f -> f1, g -> f2, h -> f3}; w[5, 6, 7, 8] (* 35 *)


2

You can use Inactivate with TraditionalForm. Inactivate[h = (R.omega + x).x] // TraditionalForm Inactivate prevents the operations from executing and TraditionalForm gives the formatted output. Hope this helps.


2

This is messy and imperfect, but it will work in simple cases: Import the package contents: pack = ImportString[data, {"Package", "HeldExpressions"}] (* {HoldComplete[BeginPackage["Test`"]], HoldComplete[testFunction::usage = "-";], HoldComplete[Begin["`Private`"]], HoldComplete[testFunction[] := {123, explicitvalue, Hold[explicitvalue]};], ...


1

Here's a possible solution. It's working (really well) for 1 particle, but needs to be checked for two particles, I guess due to minor mistakes. Basically, I changed approach and turned to a matrix notation. Let's start from the one-particle system. We simply write the state as a vector, and the operators as matrices, being very careful about the indexing. ...


1

Very similar to your other question. Replace the following definitions in your code: u[t_] := 1/ b2[t]*(-(a21[t]*x1[t] + a22[t]*x3'[t]) + r2dot[t] - c (x3'[t] - rdot[t]) - k*2/Pi*ArcTan[((x3'[t] - rdot[t]) + c (x3[t] - r[t]))]); sol = First[NDSolve[ {x1'[t] == a11[t]*x1[t] + a12[t]*x3'[t] + a13[t]*x3[t] + b1[t]*u[t], x3''[t] == ...



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