Questions tagged [evaluation]

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

Filter by
Sorted by
Tagged with
41
votes
5answers
4k views

Why doesn't Mathematica abort evaluation when I tell it to?

This frequently happens to me. I'll have some code, execute it, and realize it's taking a long time. My PC isn't frozen, and Mathematica itself isn't even frozen: I can select stuff in the notebook, ...
11
votes
2answers
211 views

Why doesn't 'Abort evaluation' properly work when NotebookEvaluate is executed?

The following procedure can be easily aborted using Evaluation > Abort Evaluation menu item: Do[j + k, {j, 1, 10000}, {k, 1, 10000}] But it is not possible if <...
5
votes
1answer
114 views

Integrating over colors

I'm trying to compute the following integral: $$\int_{380 \, \mathrm{nm}}^{700 \, \mathrm{nm}}\mathbf{RGB}(\mathrm{Hue}(\lambda))\frac{\mathrm{d}\lambda}{\lambda^4}$$ where $\mathbf{RBG}$ takes in ...
0
votes
1answer
71 views

Unable to operate on the table imported from .mx file

I saved a table by exporting it to .mx file. Now, when I import it back, it gives me the desired output. So, to work with elements of the table, I first define the imported table as (...
2
votes
1answer
41 views

What is the best way to coalesce two values, if the first value is Null?

I want to set a variable to a value, and have a default value in case the previous value is Null. Basically it would act like a Coalesce statement in SQL. I have not been able to find a succinct way ...
1
vote
0answers
31 views

Evaluating function taken as input

Consider this toy example: myDerivative[f_, x_] := D[f, {x, 2}] This defines a function myDerivative that takes in a function <...
0
votes
1answer
30 views

TemplateEvaluate, TemplateUnevaluated, and TemplateVerbatim [Undocumented] - What do you know?

Let's discuss some undocumented Template-related functionality. Specifically, what do you know about TemplateEvaluate, ...
3
votes
0answers
40 views

Symbol differentation in Wolfram Programming Lab gives recursion error [closed]

I was experimenting with the Wolfram Programming Lab, but it doesn't seem to be working. I tried running this code in a notebook: D[x^2, x] but it gives the error <...
2
votes
0answers
46 views

What are key differences between InputNotebook and EvaluationNotebook?

I am still new to Mathematica but advancing to a point of programming notebook and cell manipulations using native commands. Sometimes they call for specifying ...
2
votes
1answer
264 views

Return unevaluated expression from function

Is there any way (except using upvalues) to make a function that returns it's input Unevaluated? What I mean by that: Take the following example: ...
0
votes
1answer
80 views

Combination of Block and With - Unexpected results

I'm trying to use Block to prevent a function from executing. In this example, the function I'm trying to block will simply be ...
0
votes
0answers
33 views

Accessing already defined Symbols in a function

I'd a like a function that assigns variables based on a rule list. That is, SetParameters[{x->1, y->2}] would set x=1 ...
9
votes
1answer
121 views

Problem with Unevaluated

I found this problem form Robby Villegas's Working with Unevaluated Expressions, here is the problem i copied from his notebook: The subtle and confusing situation where Unevaluated persists is when ...
10
votes
2answers
1k views

Indeterminate expression 0^0 encountered

I'm new to Wolfram Mathematica so the the question may seem quite simple. I define the following function: ...
6
votes
1answer
113 views

Thread and RandomReal

I am trying to use Thread to apply a function involving RandomReal but it does not work as I expected. If I have the function <...
0
votes
2answers
63 views

Hold `outermost layer` of expression

In pursuit of a function to force unsimplified fractions forceden[x_,d_]:=Hold[Evaluate[Numerator[x]d/Denominator@x]/d]; There are many related functions (...
2
votes
1answer
334 views

How to get Mathematica to abort the current evaluation if an assertion fails?

I can turn on assertions, but they don't terminate the current evaluation. For example: ...
16
votes
3answers
845 views

stop notebook evaluation when Assert fails

I would like a notebook evaluation to entirely stop when an Assert fails, without quitting the kernel. Is this possible (e.g., by setting ...
3
votes
1answer
70 views

Improving `$AssertFunction` to always tell what the assertion test resulted in

I really like this form of assertion failure: On[Assert]; Assert[1 + 1 == True]; Assert::asrttf: Assertion test 1+1==True evaluated to 2==True that is neither ...
2
votes
2answers
183 views

Wolfram modules returning functions

I am trying to get a With / Module pair to return a set of functions. ...
1
vote
0answers
84 views

Do Loop contained in a function defined within a custom package doesn’t work as expected but works fine when function is defined directly in a script

Below is my code and I am having problems running the StdMPC function that I am trying to define. Running my code gives me the error that the matrix A and Xopt[[i]] are not of compatible shapes for ...
0
votes
1answer
48 views

How to instruct internal function to evaluate arguments only after numerical values are plugged in?

For convenience, let me start with a simple example. The following code calculates the sorted eigenvalues of a 4x4 Hermitian matrix with a parameter x ...
0
votes
1answer
58 views

How to programmatically Evaluate Notebook (all cells in an open notebook) rather than from Evaluation menu? [duplicate]

I am working on a DockedCells toolbar for common tasks like Save, ClearAll, scrolling, etc., ...
6
votes
5answers
3k views

Replace symbols with values without evaluation

If I have assigned values to a, b and c: a=7; b=5; c=6; ...
0
votes
1answer
95 views

Through does not have hold attribute?

Possibly Related to Unexpected behavior of KeyTake. Consider the following example, where I input #11 (last) is the misbehaving one. Am I missing something or do you agree there is a bug? ...
1
vote
1answer
55 views

function within function

delFunc[funcform_, lstofparams_,lstoferrs_] := √Total[Table[(D[funcform, lstofparams[[i]]]*lstoferrs[[i]])^2, {i,Length[lstofparams]}]] ...
0
votes
0answers
34 views

Simplifying expression involving Boson operators

I want to do calculations involving Boson operators $a(k), a^{\dagger}(k)$, e.g $(x + a(k))(y+a^{\dagger}(k))$. My code is: ...
3
votes
1answer
47 views

How to force Mathematica to output a function using its alternate pretty form when using Apply? [closed]

By default, Bra is an undefined function. Let's say I have defined Bra, Bra[a___]:=... such ...
0
votes
1answer
71 views

Evaluate analytic solution of the function [closed]

Here, i have plotted a function and i would like to print the y coordinate values from the plot for the x-coordinate given below. Coordinates in the sequence that every fourth y-coordinate should be ...
0
votes
1answer
44 views

Symbolic evaluation expressions containing a user-defined function [closed]

I have a function F[r] = (-1)^(r + 1) Binomial[n, r]/r I would like to evaluate F[x+1]/F[x] for some arbitrary ...
11
votes
2answers
450 views

Threading behavior of SameQ vs. Equal

I ran into unexpected behavior in my code based on an errant assumption. Namely, I thought that: ...
1
vote
2answers
74 views

Repeat every $ x $ coordinate except the last one

Below is the code to print the x value. ...
3
votes
2answers
124 views

Change the color of sub-expression when the whole expression evaluates to a different expression

I found it's tricky to colorize a sub-expression of an expression that changes to a different expression when it is evaluated. For example, if I replace s with ...
2
votes
2answers
62 views

Print function value at specified coordinate

Below is the code to evaluate the function. I am trying to print the function values at a specified coordinate as shown in ActCoor. ...
0
votes
1answer
56 views

Mathematica 12.1 is treating all my cells as raw texts by default

I was once using Mathematica 11 it all works fine - when I create new Notebook (.nb) input like 1+1 and press shift+...
4
votes
2answers
265 views

Stopping a head from evaluating more than once

While attempting to answer my own question, Is there a way to "hold" prefix / infix / postfix notation?, I came across the need to evaluate a recursive function only one level deep. For ...
0
votes
1answer
187 views

Elliptical Integration

I have an integral which can be decomposed into three complete elliptical integrals. I want to know the method by which I can achieve this. The integration is the following: (4 (-1 + y)^2)/(c Sqrt[y (-...
1
vote
1answer
50 views

How to inline a variable in function definition

I need to compile a function g that calls an external function f. f and ...
3
votes
2answers
169 views

Why can't I evaluate this integral and obtain a closed-form solution?

I have the following spherical density distribution: $\rho(x, z) = \frac{1}{\sqrt{x^2 + z^2}\left(1+\sqrt{x^2+z^2}\right)^2}$ which I have broken into a "line of sight" dimension $z$ and a &...
2
votes
1answer
29 views

How to conveniently evaluate a function at several points when there are way too many points

Say I define a function as follows: pos[n_] := If[Cos[288 ((n Pi)/233)] > 0 && Sin[288 ((n Pi)/233)] > 0, 1, 0] Then I want to evaluate at this ...
6
votes
0answers
98 views

Difference between the infinite rewriting behavior of evaluation and ReplaceRepeated

In the documentation tutorial/Evaluation it's said that: Every time the expression changes, the Wolfram Language effectively starts the evaluation sequence over ...
4
votes
2answers
2k views

Evaluate a list

I have a function $f(x_1,\cdots,x_n)$ that takes $n$ arguments, and I would like to evaluate it using a list of lists $\lbrace\lbrace x_1,\cdots,x_n \rbrace,\cdots,\lbrace x_1',\cdots,x_n' \rbrace,\...
5
votes
2answers
230 views

Evaluate notebook without opening cell groups

I have a notebook with grouped cells, where the input cells are hidden and only output cells open. Is it possible in an easy way to evaluate the whole notebook and preventing opening all groups, ...
0
votes
1answer
24 views

How to keep a variable unevaluated when used as parameter for `Sum`?

Let's say I have assigned the follow value to s by s = Floor[Log[n]] Then I want to compute ...
0
votes
1answer
30 views

Solving a large system of equations for the smallest integer values

I'm trying to find the smallest possible non-negative integer solutions to hundreds of fairly large equations systems . An average example would be the following: ...
0
votes
1answer
30 views

Errors within code to change the intersection of two Log Functions

I have been asked to produce a "parametric log-log plot of s=f(y) as a function of t=g(y), where ...
2
votes
1answer
57 views

Function does not take many inputs, and cannot plot correctly using Listplot

I am a beginner with Mathematica. I have a function which is defined as follows: $h(x) = \begin{cases} \hfill \frac{1}{x}\sin(x) & \text{if $x\neq 0$}\\ 1 & \text{...
0
votes
0answers
22 views

Different results when using ReplaceAll

Here's a riddle. I have a matrix QQsimple with some algebraic expressions. For example: QQsimple[[36, 22]] evaluates to: ...
2
votes
0answers
81 views

Is there any way to change the box-formatting behavior thoroughly?

Background The box-formmating behavior is affected by the downvalues of the symbol MakeBoxes. But the formatting behavior is not exactly ...

1
2 3 4 5
27