Tag Info

New answers tagged

3

frac[n_Integer, d_Integer, s_Integer] := Module[{m = 10^(Length@IntegerDigits@Max[d, n])}, FoldList[Plus, Array[{n, d} m^# &, s, 0]]] frac[33, 11, 5] (* {{33, 11}, {3333, 1111}, {333333, 111111}, {33333333, 11111111}, {3333333333, 1111111111}} *)


4

I found the solution in another topic here How to stop the Kernel from running wild? SetAttributes[timecon, HoldAll] timecon[new_] := TimeConstrained[new, 5] $Pre = timecon;


3

I think what you want can be probably be done with $PreRead, similarly to How to print unevaluated arguments in the form they were originally typed in? which I proposed as a possible duplicate. (If you need modified behavior for one particular Cell but not others see also CellEvaluationFunction). In that answer I gave code that fairly robustly lets a ...


2

Reading your comment about not wanting your TA's to type the quotes of a string, you could build some sort of user interface. Here's a very crude one. list = {}; DynamicModule[{f = ""}, Column[{ InputField[Dynamic[f], String], Dynamic[If[f =!= "", AppendTo[list, f]; f = ""]; list] }] ]


2

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, "." -> ""], ...


0

Here's a completely different take (from my other answer, which I think justifies a separate answer) that somewhat automates the idea of using HoldForm on the variables. It works as long as you name the variables consistently. It's still not perfect, since, you need to make the List of replacements, but once that's done, you don't need to do the cumbersome ...


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, ...


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], ...


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 -> ...


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 ...


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.


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 ...


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], ...


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 ...



Top 50 recent answers are included