# Tag Info

1

Starting with your code, corrected as in my comment, z[x_, y_] := x + y*I F[z_] := (25*Pi*z*I)/(1 + 10*Pi*z*I) you can plot the imaginary part of F as follow ContourPlot[Im[F[z[x, y]]], {x, -.2, .2}, {y, -.2, .2}, PlotRange -> All, Contours -> Range[-5, 5, .5], ContourLabels -> True] and similarly for other quantities. Many different ...

0

The thing that made this work in the end was using dummy variables as the function parameters. This then allowed me to use /. to replace variables. solution[mm_, gg_] := NDSolve[{eqn /. {m -> mm, g -> gg}, z[0] == 0, z'[0] == 0}, z[t], {t, 0, 10}] I think this is a pretty unintrusive solution, since it only affects one line of code and I can ...

4

In the Standard Evaluation Sequence the heads of expressions are evaluated first: If the expression is a raw object (e.g., Integer, String, etc.), leave it unchanged. Evaluate the head h of the expression. Evaluate each element of the expression in turn ... Therefore since f[1] is the head of f[1][2] it will evaluate if it has a definition that matches. ...

3

AddAssumption[assumption_]:=$Assumptions=DeleteDuplicates[$Assumptions&&assumption] You need to also check which functions use $Assumptions by default. Simplify, Refine and FullSimplify use it. To reset the assumptions use:$Assumptions=True Example: AddAssumption[x>0] Simplify[Sqrt[x^2]] Out: x

3

Using my bump function (horrible name, sorry) from Elegant manipulation of the variables list: func_[bump[lst_, idx___], arg___] ^:= func[#, arg] & @ Part[List @@@ Unevaluated @@ {lst}, {1}, idx] {v1, v2} = {7, 9}; (* existing values *) vars = Hold[v1, v2]; Block[bump[vars], Print[v1, ", ", v2]] v1, v2 See the linked question for many other ...

3

Storing v1 and v2 in a variable makes it more complicated. It is better to construct custom dynamic environments based on Block, which would be closures, closed over symbolic variables you want. Here is a generator for such environments: withBlockedVars = Function[vars, Function[code, Block[vars, code], HoldAll], HoldAll]; Here is how you generate a ...

8

I will make no attempt to defend the fact that Mathematica simulates scoping by means of variable renaming. However, the behaviour that we see is consistent with the principles under which Mathematica does operate. Whenever Mathematica tries to interpret a symbol name, it first checks to see whether a symbol with that name already exists in a package in ...

2

I agree with this comment, so let me put here a wiki: I'm reasonably certain this is designed behavior - the variable coloring is only supposed to apply to the Global context. As an indication, in Preferences>Appearance>Syntax Coloring>Other the typical blue color is assigned to "Global symbols that have no value assigned". I'm not aware ...

0

If you test the code above, i.e. run mySetVar[t] it works correctly (i.e. var is set to 20). The problem is actually one of "Definition" rather than SetDelayed. Definition is a weird function that simply prints some info to the screen. In this case, it gets it wrong, i.e. there is a bug in Definition. As a work around, if you want authoritative ...

8

Basics To get it out of the way, for the specific example given you could use Unevaluated: Cases[Unevaluated[1 + 3], _, {-1}] {1, 3} To actually be able to modify a System function I recommend InternalInheritedBlock: SetAttributes[cases, HoldAll] cases[args___] := Internal`InheritedBlock[{Cases}, SetAttributes[Cases, HoldFirst]; ...

7

Yes, you can set both with UpValues: x_G.f[] ^:= x h_[a___, G[x_, ___, y_], b___] ^:= h[a, y[x], b] G[2, e].f[] // Simplify (* e[2] *) It seems to work, but it is quite dangerous, as Leonid mention in the comment. For example, it was too easy to make a mistake in my previous revision. Here Simplify helps to deal with pure G[x_, ___, y_].

7

General considerations This seems to be tricky, and I don't know how to do this without involving the inspection of Stack. The main problem is the order of rule applications. Since Dot evaluates its arguments, UpValues for f or G are only applied after both f[] and call to G have been fully evaluated - and then it's too late. Therefore, generally you have 3 ...

Top 50 recent answers are included