Tag Info

New answers tagged

11

Preamble What happens can be understood when we recall that Rule is a scoping construct. The general issues related to variable renamings in scoping constructs have been considered in more details in this answer. General Now, to this particular case. When the code runs, the external RuleDelayed considers the situation "dangerous" and performs variable ...


0

Based on your extended example I think you are going to need to change your fundamental approach to this problem, as it becomes too complicated to work out which parts should be evaluated and which should be held. (That is, for a general case.) For the simpler example I recommend that you read How do I evaluate only one step of an expression? and my ...


2

Sure, one way is to use patterns and replacement rules (check out Symbol): {Subscript[x, 1], Subscript[x, 2], Subscript[x, 3], Subscript[x, 4], Subscript[x, 5], Subscript[x, 6], Subscript[x, 7], Subscript[x, 8], Subscript[x, 9], Subscript[x, 10]} /. Subscript[x_, k_] :> Symbol[ToString[x] <> StringReplace[ToString[k]," "->""]] (* {x1, ...


2

Holding the pattern works: diffy := Hold[D[U[z], z]] held = diffy /. U[z] :> Exp[-I*k*z] Edit for completeness: held // ReleaseHold


2

Although I cannot offer anything as robust and elegant as Rojo's single pass method I find this an interesting problem, and I present a limited alternative for the interest of others. For the sake of the examples I will use a modified y expression: x = Hold[1 + 1, 2 + 2, 3 + 3]; y = Hold[foo @ bar[2], bar[1], foo[1, bar[3]]]; If our parts are always at ...


1

I present this for illustrative purposes. Here is a toy data set: samp = RandomReal[{23, 32}, 365 8 ]; This is just 365 days of 8 samples per day. You can get daily mean using: Mean /@ Partition[samp, 8]; You can visualize by just wrapping in ListPlot and with option Joined->True: You can also use TemporalData: td = TemporalData[samp]; td2 = ...


4

There are built-in functions to do that. Mean/@Partition[lst,365*8] Variance/@Partition[lst,365*8]


4

You have to forbid the evaluation of Total[myList] and Mean[anotherList] until you have actually replaced the arguments with the specific lists: obj = someClass[myList -> {}, anotherList -> {1, 2}]; calculateStuff[someClass[props___]] := Unevaluated[1 + Total[myList]*Mean[anotherList]] /. {props}; calculateStuff[obj] (* 1 *)


0

One method I've found that works, at least for this case, is to use Position and MapAt: myReplaceListAll[l_, rule_] := MapAt[Function[x, Replace[x, rule]], l, #] & /@ Position[l, rule[[1]] ] This almost works, except that when Position matches the whole list it returns {}, and MapAt doesn't return the whole expression. list rule = ({x_, y_} ...


0

I would try this, step by step: t = Table[Evaluate[D[Log@h[z, 3], {z, w}]], {w, 4}] (wait with defining f) t /. Derivative[d_,0][h][z,k_]:> x[z,d,k]/. h[z_,k_]:> x[z,0,k] (using FullForm of the derivative). Now apply (repeatedly) % //. x[z,d_,k_] :> x[z, d-1, k-1] /; d >= 1 && k >= 1 and, as a last step, restore the ...


3

What's happening only indirectly involves the pattern matching. Mathematica, when dealing with operations that are Orderless, will put the arguments into a canonical ordering (described here). In this case, an expression like Subscript[Z, 2, 1] Subscript[Z, 3, 1] can be seen to be equivalent to Times[Subscript[Z,2,1], Subscript[Z,3,1]] using FullForm. ...


1

If you want the term $\frac{\partial f}{\partial r}$ to disappear you need to introduce new function which would be: w2 = f[r, θ] r which means that you have to make a substitution f -> w2/r, this way: lapla1 /. f -> (w2[#, #2]/# &) // Simplify // ExpandAll If you once used f or w, don't change theirs definitions, use a new one, you ...


4

Basing on the following thread: Change variables in differential expressions and using great code by Jens for visualisation purposes (I have replaced part [vars__Symbol] with [vars__] because you are using Substripted names which are not Symbols, but that's only about visualisation). You can do the following in the first step: M2 = M /. f -> (f[#, #2, ...


2

The following assumes that your replacements are 3x3 matrices but it is easy to generalize. I'm not sure if you need. It will take care of -1 on edges. replace[mm_, reps_] := Module[{m = ArrayPad[mm, 1], pos = Position[mm, -1]}, MapThread[ (m[[#[[1]] ;; #[[1]] + 2, #[[2]] ;; #[[2]] + 2]] = #2) &, {pos, reps}]; ArrayPad[m, -1]] mm = ...



Top 50 recent answers are included