Questions about how Mathematica evaluates expressions, tracing evaluation (Trace*), handling expressions in unevaluated form (Hold*, Unevaluated), nonstandard evaluation, etc.

learn more… | top users | synonyms

2
votes
2answers
119 views

Time delayed evaluation of a function

I'd like to write a function that delays the evaluation of a function (say) $5$ seconds after I hit Shift+Return. Is this possible?
2
votes
2answers
149 views

Expectation of a family of random variables

I did some search here, but seems that no one asked about this. I want to define a family of independent and identically distributed random variables, $x_1,...,x_n$, and then calculates the expected ...
2
votes
2answers
87 views

Merging two held expressions into a held compound expression

Consider e1 = Hold[a = x + x; b = y + y + y]; e2 = Hold[c = a + a + b + b + b; c^2]; How can I obtain the following? ...
2
votes
1answer
115 views

Strange results of definitions using OwnValues

I am asking this question simultatenously with this one, which is strongly related. I was trying to see if I could create the behaviour as in that question without using ...
2
votes
2answers
150 views

While loop doing cell evaluation not completing

I am trying to get a loop structure using While to repeatedly evaluate another cell referred to in its body (using a cell tag). ...
2
votes
2answers
180 views

Evaluating Polynomials at Grid Points

I am continuing my quest on B-splines. The code below builds a 5x5 matrix out of B-splines, using the BSplineBasis[] routine. I now want to evaluate the polynomials that are stored in each matrix ...
2
votes
2answers
154 views

Updating a tracked symbol inside Refresh?

I have some code inside a Manipulate, whose goal is to allow the user to edit the upper half of the matrix while keeping it symmetric at all time. The minimal code ...
2
votes
2answers
1k views

Animation of Differential Equations from NDSolve with ParametricPlot3D and Evaluate

I have a system of differential equations (referred to as "s") and use NDSolve to obtain the solution. I substitute the interpolated functions for the original ...
2
votes
1answer
624 views

A combination of Set::setraw and Set::shape errors

Please consider the following toy code: ...
2
votes
1answer
79 views

Need to run evaluation 2 times

Why does this only work after running the evaluation 2 times? ...
2
votes
1answer
200 views

Expectation function does evaluate my expression

I am trying to evaluate the expression Expectation[(B x (-6 b + 12 a n0 + B x + B^2 x^2))/(2 (6 a + B x + B^2 x^2)), Distributed[x, BetaDistribution[α, β]]] ...
2
votes
1answer
77 views

ParallelEvaluate: Evaluation Rules and Increment

I'm trying to understand how ParallelEvaluate works, considering the two following snippets: ...
2
votes
1answer
58 views

Defer parts of the expression

Is there a way to Defer only parts of the expression? For example, I have a=1; and then I want the expression to be shown as...
2
votes
2answers
62 views

Confused with HoldForm in Postfix notation

Why does the following code produce different result? In my mental model, they should be the same. ...
2
votes
1answer
353 views

Is there anything like a C pointer (or returning a reference) in $Mathematica$?

I want to do in Mathematica what the following does in C. ...
2
votes
1answer
246 views

Evaluate Numerator and Denominator Separately

I have this function. ...
2
votes
3answers
147 views

Function to preserve evaluation on display?

I'm looking for a function that applies the following behavior to an expression: -When the expression is given as the full input, or as part of a function that cannot be evaluated, it remains in ...
2
votes
1answer
2k views

setting a variable equal to the output of FindRoot

So I set a function f[x] f[x_] := x*E^(-x) - 0.16064 Then I set a variable 'actualroot' to the function FindRoot, starting at 3 ...
2
votes
1answer
198 views

Why is this expression being held, and how can I evaluate it?

I can't figure out why an expression isn't evaluating, even though there's no Hold* in its FullForm: ...
2
votes
1answer
167 views

Manipulate executes expressions multiple times

I am using Manipulate for a rather intricate front end for data visualization. I was getting very sluggish performance and was able to boil the problem down to a ...
2
votes
1answer
236 views

Use output of NDSolve as an integration limit of NIntegrate

I've been working on a ODE, for a function y[t], that, due to it's complexity, has to be solved numerically. I then need to use the results of NDSolve, which I ...
2
votes
3answers
388 views

GraphPlot only working when I evaluate twice

I have some code that builds a graph and some vertex coordinates, but when I evaluate it I get a message that the list of coordinates is not valid and the graph is not valid and it shows the output as ...
2
votes
2answers
46 views

Order of Evaluate for Map

I would like to get a list of variable names as strings. For example, x = 1; y = 2; Map[SymbolName, Unevaluated /@ Unevaluated@{x, y}] {"x", "y"} This works ...
2
votes
1answer
92 views

Wrapping at evaluation for inline cell

I've been playing with inline evaluation and I've came to the conclusion that it's most convenient to put the Dynamic@ inside the inline cell, so I've started to ...
2
votes
2answers
72 views

Can I have Mathematica show intermediate forms before final evaluation?

If I have x = 2 and I want to evaluate y = x^2 I would like to the output to show ...
2
votes
1answer
38 views

is there a way to construct a pattern that would trigger when an expression is used as a held/unevaluated in some form?

For example, consider the following code f[x_] := (Print["evaluated f"]; workWith[x]); We use it, then f evaluates: ...
2
votes
2answers
228 views

Integrating a Simple Piecewise Function

If I define f[x_]:=If[x<0,-1,1] and then integrate,say Integrate[f[x],{x,-3,7}] I get what I expect, namely 4. But ...
2
votes
2answers
127 views

Generating an editable table that can be used as input

Say I have a number $n_{max}$. I want a command to generate a table like 1 1 2 2 3 3 4 4 ... nmax nmax where the second column is editable, and this table can be ...
2
votes
1answer
115 views

Need help looping a notebook evaluation

I'm a new user and would like to find the minimum value of soln1[30] obtained after repeating the following evaluation (below) for 1000 cycles (for instance). I can obtain sequential values of ...
2
votes
1answer
72 views

Differentiating a function that has NIntegrate within it

I am something of a novice with Mathematica. I have written the following code; ...
2
votes
1answer
49 views

Label cell goes away with SelectionEvaluate

When a given cell has a label (given with the CellLabel->"label" option of the cell), then this label disappears after calling SelectionEvaluate[ nb ] when the ...
2
votes
1answer
143 views

Dynamic [ NotebookEvaluate [“_”] ]

A nice way to centralize various tasks in one notebook is the NotebookEvaluation function. For instance I can evaluate ten notebooks from a single notebook (e.g. ...
2
votes
1answer
98 views

Reuse local variable in declaration within With [duplicate]

Considering the richness of Mathematica.SE, I am quite surprised I could not find my answer... I am very sorry if it is a duplicate. Consider the following example: ...
2
votes
1answer
162 views

is there a method to send different cell evaluation to different core

I am running Mathematica on a computer with mulicpu and every cpu has multicore. I am wondering if there exist a method to send different cell evaluation to different core? So if I already have a ...
2
votes
1answer
105 views

NotebookWrite undo

Is there way to make NotebookWrites undooable? For example let's say I open a new notebook and then run. ...
2
votes
1answer
74 views

ExampleData menu view

I'm trying to build an ExampleData browser, so that the "collection"/"type" is selectable in a drop down menu, and the "name" is selectable in another drop down menu. What I have so far: ...
2
votes
1answer
216 views

Why does Mathematica evaluate Sin[2.0] but not Sin[2]?

I can't understand why is it that In[88]:= Sin[2] Out[88]= Sin[2] while In[89]:= Sin[2.0] Out[89]= 0.909297 I even tried ...
2
votes
1answer
124 views

Order of operations, precedence in Mathematica [duplicate]

I get confused in the order of operations in Mathematica. For example, f /@ 10^{1, 2, 3} {10, 100, 1000} In my head, that ...
2
votes
1answer
103 views

Piecewise function with user-input interval

I would like define a function g[data,bins,x] which is a piecewise constant function taking value data[[i]] in the range ...
2
votes
1answer
69 views

Evaluate only one from a set of procedures

Let's say I've got a list of procedures: {Print[1];, Print[2];, Print[3];} And I want to only evaluate 3rd one: ...
2
votes
1answer
122 views

Implementing a For (?) or series or loop (?) for individual results for every x to n

I'm working on improving a modeling formula and have spreadsheets worth of data to use, but my work so far has been quite tedious. I'm essentially pulling 20 rows of data from each separate sheet of a ...
2
votes
0answers
40 views

Timing of ParallelDo versus Do: simple example [duplicate]

I'm trying to understand why a simple do-loop takes substantially longer when done in parallel than sequentially: ...
2
votes
0answers
48 views

What is “ (Dialog) Input [ ] := ” after evaluating a cell?

I have done a time-consuming run and calculation. After many hours ( about 7 hours!), the black color which shows that the cell is evaluating, turn into gray and a strange text appears like this : ...
2
votes
0answers
65 views

Assign a value to a variable without using Set or SetDelayed?

I supose probably yes, but at the end I assume that internally mathematica has to use Set or SetDelayed. Am I right? Background: I am developing a super simple phraser that takes a code description ...
2
votes
0answers
71 views

Assign variables from list inside With or Module

I have found that it is possible to assign variables from lists, as follows. In[1]:= r = {1, 2, 3}; In[2]:= {a, b, c} = r; In[3]:= b Out[3]= 2 However, if I try ...
2
votes
0answers
102 views

Force Dispatch to generate dispatch tables

Dispatch creates hash tables only for lists of length larger than 3. Is there any way to force MMA to create hash tables even for lists of length smaller than 4? ...
2
votes
0answers
151 views

Lazy evaluation/loading of parts of an expression

Is it possible to have an expression x such that its elements are only evaluated when they are individually accessed, for example when evaluating statements like ...
2
votes
0answers
106 views

Strange double evaluation using MorphologicalGraph

(MMA 9.0.0 on Mac OS/X 10.8) Please consider the following snippet (this is as SMALL as I could make it -- my attempts at making a smaller repro-case eliminated the effect that I am investigating) ...
1
vote
1answer
366 views

The underlying process of Integrate[] [duplicate]

Integrate[x^4 E^-x^2, {x, 0, +∞}] Output: (3 Sqrt[π])/8 Can someone explain to me the specific calculation process ?
1
vote
2answers
135 views

How can I speed up this plot manipulation? Why does Evaluate not help?

If I were able to "Save" the computed inverse function somewhere and then plot it, the manipulation would become faster. As I understand, Evaluate should do the job, but for some reason it does not. ...