# Questions tagged [conditional]

Questions about programming or mathematical constructs that enable verification, selection, or branching behavior when one or more criteria are determined to be True.

371 questions
Filter by
Sorted by
Tagged with
5k views

### 2D random walk within a bounded area

I want to simulate a random walk in two dimensions within a bounded area, such as a square or a circle. I am thinking of using an If statement to define a boundary. ...
1k views

### Quick way to use conditioned patterns when defining multi-argument function?

I have a simple function that is supposed to only accept numeric values (i.e. complex/real numbers and constant symbols e.g. Pi, E). $$f(a,b,c)=a+b+c$$ Edit: I should have chosen a less simple ...
1k views

### Generating Tuples with restrictions

I am interested in a certain subset of all tuples. Generating all with Tuples and then filtering is wasteful, and will "blow up" very quickly. For a concrete ...
767 views

### Flatten not working

I am trying to modify some code proposed here Part assignment is not a symbol and I cannot manage to make Flatten work. I write ...
108 views

### Reduce[Sin[x]==0,x] splitting odd and even multiples of Pi

as from Title, I'm wondering why Mathematica does not automatically give a single, simple solution for the problem Reduce[Sin[x] == 0, x] for which I obtain the ...
879 views

### Double Sum Involving Condition

I would like to compute the dimensions of some small free nilpotent Lie algebras. However, I am totally new to this and I could not figure out how to write the double sum which gives the dimension of ...
2k views

### Evaluating an If condition to yield True/False

I would like to decide whether an option passed to my custom function has the value Automatic or something else. This is my attempt: ...
13k views

### How to remove ConditionalExpression from output

I need define the function with parameter so I could directly generate a power series expansion. The problem is that in some cases ConditionalExpression appears in output. Here is my code: ...
826 views

### ListPlot under conditions

I have a data file containing several columns and thousands lines of data. Below I present a small portion of it, in order to express my issue: ...
796 views

### Difference between Piecewise, Which, If?

I have the impression that these functions have different evaluation rules. I cannot produce a minimal example right now, but in general, what are the differences between these functions? That is, ...
408 views

### Question about Rules and Pattern (The operator patt/;test)

Maybe this question is so trivial but it has confused me. I'm studying the What the @#%^&*?! do all those funny signs mean? and in the Rules and patterns under ...
372 views

### Finding the condition for root of a third degree polynomial

I've a third degree polynomial (in $s$): $$as^3+bs^2+cs+d\tag1$$ I need to find the roots of the polynomial, so I can use the code: ...
277 views

### using memoization with conditional statement

I would like some advice about the use of memoization in conjunction with conditional statements. Let me try to explain my problem: I am constructing a function depending on a number of parameters. ...
116 views

### JoinAcross datasets based on Equal and not on SameQ

JoinAcross will join keys if values are the same (SameQ==True) but not if there are equal. For example these two associations are not joined : ...
3k views

### Simplifying nested If statements

Consider : list = {100,102,103,99,106,107,104,112} I want to consider, extract only the "big moves" of that time series. In this case the moves bigger then 5 ...
284 views

### Weird behavior of conditions when using OptionsPattern and OptionValue

I'm trying to define a function that is evaluated differently depending on its options. This code ...
708 views

### Switch inside Manipulate controls statement

I am using this code inside Manipulate: ...
450 views

### Why does pattern test work only with pure functions?

Why is it that pattern test works only with pure functions? Cases[Range[0, 70], _?(Divisible[#, 7] &)] Cases[Range[0, 70], x_?(Divisible[x, 7])] I ...
1k views

### How can I name patterns in a Switch expression?

Suppose I have an expression and want to match it against successive patterns and return an expression corresponding to the first pattern that matched. In that case, I can use ...
153 views

### Checking what a function depends on

I'd like to define specific partial derivative operators that change based on if the passed expression is a function of, for example, x vs. ...
225 views

### Randomly generated coordinates

I want to code that will do the following: Write a Mathematica function called randomHop that takes as its argument a list containing two coordinates x and y; ...
157 views

### NExpectation not up to expectations with Boole or Conditioned

Context I am interested in computing numerically the number of extrema at a given threshold for random fields. These numbers are expectations of MultinormalDistributions. Problem This integral ...
220 views

### Is it possible to do probabilistic programming by variable elimination with plain Mathematica 10 or later?

Using frameworks like Figaro it is possible to do probabilistic programming by variable elimination to build a probabilistic model and then run inferences against it in a very intuitive way. Example: ...
226 views

### Take elements from a list based on two criteria

I am trying to take elements from a list of tuples using 2 criteria. An example of the list is: list={{-1, -1}, {-1, 1}, {1, 1}, {1, -1}, {1, (1 + I)/Sqrt}} ...
173 views

### How to create a sublist of elements with a congruence relation

I generated a list made up of lists of four elements such as: n = {{49, 9, 9, 5}, {57, 13, 9, 5}, {81, 21, 13, 5}, {95, 19, 19, 7},...} I would like to create a ...
3k views

### How to restrict the domain of a function

I realize this question has been asked many times, but I am fairly new at Mathematica and the other answers are very complex, and certainly too complicated for this simple code I am trying to write. ...
432 views

### How to select points from a table that are within some region

there, I encountered this problem while coding: I generate a table in the r-z plane of cylindrical coordinates: ...
20k views

### Multiple lines in an If statement [closed]

What I am wondering is how do you perform multiple lines when using the If statement. I know the following is not proper Mathematica code, but how would I do this in Mathematica? ...
15k views

### Add assumptions to Solve command

I want Mathematica to solve the following by assuming the part within the Log function, which is ...
879 views

### Flow/graph-based programming in Mathematica?

Is it possible in Mathematica to write a program inside a graph? For example if you have a bunch of different If[] statements that you need to embed within one ...
97 views

### Conditional rendering of items

Let's say I have a column to display and each of its items can be hidden separately. Question: Is there a way to make it work without re-rendering whole column whenever a particular item is hidden? ...
867 views

### When are If, Piecewise, Switch, and Which interchangeable and when are they not?

Experimenting with joint dependent distributions via the TransformedDistribution function, I used the following to derive a distribution where the second variate is ...
505 views

503 views

### How to simplify block of multiple repetitive If statements?

I'm building a boardgame...game in Mathematica. I have the board state represented as a matrix. It's a two player game, and each player (let's call them A & B) only has one type of piece or '...
151 views

### conditional expectation doesn't work with SmoothKernelDistribution

I'm trying to calculate a conditional expectation E[ x | x > a ], where the distribution of x is inferred from a finite ...
276 views

### There is no ConditionalExpression warning for an Indeterminate case in Integers

This expression yields Pi in the limit m -> n in the Complexes domain. But for ...
265 views

### Better use of pattern matching in replacing elements of a list

I have a list of reals and I'm replacing those which are contained in a given interval with two different values depending on wheter the selected reals are positive or negative. I came up with this ...
103 views

### An unexpected match when using Condition, Optional and passing a Sequence

Mathematica is behaving in an expected way when passing a parameter with an Optional and a Sequence. Here is an example: ...
998 views

### Simplifying conditional expressions using assumptions does not work

I have a conditional expression f[x_] := x /; x ∈ Reals This works fine for normal numbers and symbols, e.g. ...
130 views

### Check if a symbolic matrix is hermitian

I have a symbolic matrix: Potential = SparseArray[{Band[{1, 1}] -> V0/2, Band[{2, 1}] -> V0/4, Band[{1, 2}] -> V0/4}, {2*max + 1, 2*max + 1 }] ...