Tag Info

Hot answers tagged

10

I have reworked your code somewhat. I hope what I have done will help you with your problem. BezierDefinition[pts_, u0_?NumericQ] := Nest[MovingAverage[ArrayPad[#, 1], {u0, 1 - u0}] &, {1}, Length[pts] - 1].pts ClearAll @ CAGDBezierCurve; Options[CAGDBezierCurve] = {SplineClosed -> False, SplineDegree -> Automatic, ControlPoints -> ...


7

There are two possibilities you could be aiming for. First, I'll take your question literally and just inject expression into the Module: expression = a + 1; With[{expression = expression}, g[x_] := Module[ {a, b}, a = 1; b = expression; x*b]] expression = 1 (* ==> 1 *) g[xi] (* ==> (1 + a) xi *) As the result after changing ...


7

I think my answer to Why does this pattern with Plus not work for numbers? is also the answer here. See Plus in the reference manual: Unlike other functions, Plus applies built-in rules before user-defined ones. As a result, it is not possible to make definitions such as 2+2=5. The ability for user-defined rules to supersede built-in ones was ...


6

Let's assume you really can only evaluate your function evals for numeric values. Then the approach of using Evaluate or removing ?NumericQ is not helping. For this situation, I see two possible solutions from the top of my head. Using memoization suppress recalculation evals[x_?NumericQ] := evals[x] = Eigenvalues[{{x^2, 2 x}, {x, 3 x^2}}]; ...


4

I can illustrate what is going on with a simpler function than yours. Consider f[x_, y_] := Sum[y[[i]], {i, Length[x]} Then f[{"a", "b"}, {3, 4}] gives 7 as expected, but f[x, y] /. {x -> {"a", "b"}, y -> {3, 4}} gives 0, just as your function did. Now /. is infix operator version of ReplaceAll, so the above is equivalent of ReplaceAll[f[x, y], ...


4

According to the suggestion of Michael E2 and the answer of m_goldberg Replacing the Evaluate @Sequence @@ FilterRules[{opts}, Options[ParametricPlot]] with Evaluate @ FilterRules[{opts}, Options[ParametricPlot]]; Using the construct Block[{u}, ParametricPlot @@ {args...}] Ultilizing the Show and Graphics[If[cp, {Green, Line[pts], ...


3

In the interest of showcasing a functional answer to an interesting question, I take the liberty of turning @Szabolcs comments above to an answer, since the OP has confirmed that this approach has solved his problem. Szabolcs pointed out that when one is "evaluating" a cell in the front end it really just queues that cell for evaluation. When one evaluates ...


3

Part1. The ordering of the roots and consequently which is the fourth root depends on when a is given its value. Table[Root[-7 a^4 #1^2 - 2 a^2 #1^4 + #1^6 &, n] // ToRadicals, {n, 6}] /. a -> 1. {0, 0, 0. + 1.35219 I, 0. - 1.35219 I, 1.95664, -1.95664} Table[Root[-7 a^4 #1^2 - 2 a^2 #1^4 + #1^6 &, n] /. a -> 1. // ToRadicals, {n, ...


3

I closed this as a duplicate of Why does this pattern with Plus not work for numbers? but I think I have something that is general enough to be useful, and it's not applicable to that question. We may observe that although a plain use of Block[{Plus}, . . .] does not prevent numeric evaluation of Plus we can still make a substitution that does: Block[{Plus ...


3

If I understand what you want: SetAttributes[fun, HoldAll]; fun[expr_] := Identity @@ Identity @@ MapAll[Unevaluated, Hold[expr], Heads -> True] The two Identity operations fix the fact that MapAll applies Unevaluated to the entire expression as well - MapAll[g, f[x,y]] is g[g[f][g[x],g[y]] when we want g[f][g[x],g[y] - and remove the Hold we ...


2

I though it is nice untill I had to add reparse function :) SetAttributes[mySequence, HoldAllComplete]; mySequence[args__] := RawBoxes[ MakeBoxes[{args}][[1, 2]] ]; reparse = ToExpression @* FrontEndExecute @* FrontEnd`ReparseBoxStructurePacket @* ToBoxes y = 7; Hold[{1, x, 2, x, 3}] /. x :> RuleCondition @ mySequence[y, 1+2] //reparse Hold[{1, ...


2

To make Plot aware that it's a list: evals[x_] = Eigenvalues[{{x^2, 2 x}, {x, 3 x^2}}] Plot[Evaluate@evals@x, {x, -1, 1}, PlotStyle -> {Red, Green}]


1

Aside from the fun evaluation control and numerical precision discussions happening, is this useful to accomplish the task you wanted? It does simply use string patterns to drop the appropriate zeroes. sigfigs[str_String] : = StringLength @ If[ StringContainsQ[s, "."], StringTrim[ StringReplace[s, "." -> ""], ...


1

You can use Inactivate and Activate to control the evaluation of the right-hand side. expression = Inactivate[a + 1]; g[x_] := x Activate[expression /. a -> 1]; g[2] (* 4 *) expression (* a + 1 *) Inactivate prevents the execution while Activate executes without losing the inactivated expression. Hope this helps.



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