New answers tagged

1

This one checks if the input ended with ; and prints Echo cells if it didn't. f[x_] := If[ Cases[NotebookRead[EvaluationCell[]], BoxData[RowBox[{___, last_}]] :> last] == {";"}, Null, CellPrint[ExpressionCell[#, "Echo"]] & /@ Range[x]; ] For example: f[5] f[5];


2

The code below is currently broken but I'll leave it for reference. I'll attempt a full rewrite somewhat later. Thanks to gwr for testing my code and pointing out problems. The first possibility that comes to mind is the use of $PreRead and $PrePrint to set a global variable, then use the value of this variable within your function to control Cell ...


9

Using GaussianFilter on the raw RGB data will produce a convolution in all 3 dimensions of the list (rather than just the 2 spatial dimensions of the image). So filtering the raw data will also convolve RGB values at the same pixel. To see this effect, we can start with a uniform red image where all RGB values are {1,0,0}: test2 = Table[{1, 0, 0}, {m, 20}, ...


1

To see what it "does", use symbolic values as suggested by J.M. (tmatrix = Array[t, {2, 2}]) // MatrixForm (expr1 = Table[Sum[tmatrix[[i, j]], {i, 1, 2}], {j, 1, 2}]) // MatrixForm An alternate way to obtain this result expr1 === Plus @@@ Transpose[tmatrix] (* True *)


1

Too long for a comment. You can try this. res will contain a list of you 100 result. ClearAll[inexactSolve] ; SetAttributes[inexactSolve, HoldFirst] ; inexactSolve[expr_Solve] := ReleaseHold@ Replace[Hold[expr], a_?InexactNumberQ :> inert[ToString[a]], Infinity] /. inert[a_String] :> ToExpression[a]; res = Reap@Do[ With[{A = 0.625, h = 0.61}, ...


10

You need to delay the evaluation of the right-hand side of ScalarCurvature: ScalarCurvature[fun_, xx_, yy_] := scalar /. Derivative[i_, j_][f][x, y] :> D[fun, {xx, i}, {yy, j}] Then it works, although there is a sign difference to your formula: ScalarCurvature[x^2 - y^2, x, y] -(8/(1 + 4 x^2 + 4 y^2)^2)


1

This works: hh @@ {3, 4} 7 This as well: myList = {3, 4} hh @@ myList 7 See: How to | Work with Lists Lists are at the core of the Wolfram Language. These "How tos" give step-by-step instructions for common tasks related to creating and manipulating lists. Applying Functions to Lists Many computations are conveniently specified in terms ...


3

Description The reason why your function doesn't execute as you'd expect is due to it expecting two arguments whilst you pass a single argument of type List containing two elements. Your function views it as hh[{3,4},y_]. Although, x parameter is passed successfully; y parameter is not available. Example: hh[3,4] Output: 7


11

This appears to be a difference in parsing between the frontend and the kernel. Compare (in a notebook) HoldForm[\[LeftCeiling]x\[RightCeiling] + 1] (* Ceiling[x] + 1 *) with Get[StringToStream["HoldForm[\[LeftCeiling]x\[RightCeiling] + 1]"]] (* Ceiling[x] (+1) *) where the latter has multiplication instead of addition. One possible workaround is ...


2

It seems to me that setenv is being used here to set the values of a series of helper variables that are then used by the other functions in the code. This (is awful but) works within a single notebook because all those variables are visible to all functions. I suspect, however, that once you put the code in a package, you run into context problems. Those ...


3

If you want recursion, write recursively. dualF[Not[p_]] := Not[dualF[p]] dualF[And[p_, q_]] := Not[Or[Not[dualF[p]], Not[dualF[q]]]] dualF[Or[p_, q_]] := Not[And[Not[dualF[p]], Not[dualF[q]]]] dualF[p_Symbol] := p then dualF[p && (q || r)] ! (! p || (! q && ! r)) which has the truth table which is same as


3

It returns 0 because you are doing something like: D[ Sin[Global`x1], MyP`Private`x1] (*Global` or current $Context really*) Why? You can read more in a related topic: Behavior of Remove inside a Package and in the general one I'm encouraging you to become familiar with: How symbol lookup actually works There are some tricks available to detect a ...


0

The error is in: fun1[p_] := p^2 + p - 1; fun2[p_] := p^3 - p^2 + p + 1 The separator doesn't ";" , is ",".


4

If you do this often why not create a shortcut or template as you mentioned in the question? This has the advantage of formatting directly without having to use Evaluate in Place etc, or introducing a custom notation. Example: Derivative[Placeholder[], Placeholder[]][Placeholder[]] // PasteButton // CreatePalette Makes: If preferred a keyboard ...


5

I've thought out 2 auxiliary functions. A possible improvement for the Derivative approach: d /: u_^d[a__][b__] := Derivative[a][u][b] Then $u^{(1,0)}(0,x)$ can be obtained by u^d[1, 0][0, x] But I'm not sure if typing Shift+6 is simpler than typing [+]… A possible improvement for the D approach: d2[u_, y__] := Module[{pos = Position[{y}, ...


1

This seems to meet your requirements, MyDensityPlot::argerr = "Number of undefined variables > 3"; Options[MyDensityPlot] := Options[DensityPlot]; MyDensityPlot[fn_, range_, options : OptionsPattern[]] := Module[{p1, externalSymbol, localx, localy, reg}, externalSymbol = With[{currentContextQ = Context@# === $Context &}, ...


0

(z[x, y]@@(Values[data1]))@@(Values[data2]) (* or z[x, y][##&@@(Values[data1])][##&@@(Values[data2])] *) -0.357143+0.5 (x+y) Plot3D[(z[x, y]@@(Values[data1]))@@(Values[data2]), {x, 0, 1}, {y, 0, 1}] (* or Plot3D[z[x, y][##&@@(Values[data1])][##&@@(Values[data2])], {x, 0, 1}, {y, 0, 1}]*)


4

This is very similar to the answer by Mr.Wizard, but avoids to introduce a named expression and therefore rewriting the function by using Condition: Replace[_, {_ /; IntegerQ[#] :> # (# - 1), _ :> #}] & /@ {1, 2, 3, x} {0, 2, 6, x} A more direct way is to use Switch: Switch[#, _Integer, # (# - 1), _, #] & /@ {1, 2, 3, x} ...



Top 50 recent answers are included