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

372 questions
Filter by
Sorted by
Tagged with
30 views

### Rewrite ListPlot using Graphics while perserving point color?

I have a lot of data points, and I have noticed that plotting using Graphics is usually much quicker than plotting with ListPlot. The problem is I am trying to color the data points based off some ...
35 views

### Replacement rules which for elements of a vector which meet conditions

I'm trying to create a function which will replace elements of a list with their values modulo 1, i.e. Mod[x,1], but only if ...
51 views

### How can I use WhenEvent with multiple conditions inside NDSolve?

I would like to use WhenEvent but I'm not getting what I want: I set the initial condition var\epsilon=0; I want var\epsilon to change continuously over time, from to 0.1 if s'[t]>=0 or to -0.1 if s'[...
44 views

### Replace the values of second position in a list with the values of another list given a condition

If I have the following two lists: list1= https://pastebin.com/zFin7kkB list2= https://pastebin.com/8ymCin6d where the first element of both list is the same. How can I replace the values in the ...
28 views

### Replace the values of the second position in a list given two conditions

Suppose I have the following list: https://pastebin.com/zFin7kkB and I have a given value of maxDh (let's say 0.5) . How can I replace only the values in the ...
62 views

### How do I loop my “If” statement?

I have list given by: d= {{{1,2},{1,1},{2,3}}, {{1,4},{3,3},{2,1}}, {{1,1},{3,1},{3,3}}} Each row in the list is a different generation of the ...
70 views

### Using pure functions to assign a value to variable depending on whether it has been defined already

Let's say I want to assign to a variable the value $2020$ if it has not already been defined and do nothing if it has. In short, for a variable $a$, I want to achieve the functionality of ...
1k views

### Generate “nice” random matrix

I don't frequent this community, so please give criticism if this is a poor question. I am trying to make a tool which generates a small (say, $4\times 4$) matrix with integer entries, which has a "...
25 views

### Which condition inside a loop with unknown value in a condition

I have a Which condition inside a loop such as: ...
25 views

### Assign a variable to a condition only if the condition is met using Which

If I have a conditional of the form: Which[Round[b[i], 0.1] == 74,1,40 < b[i] < x,2] where b[i] represents a number that ...
21 views

### Dynamically fixing a Control within Manipulate

Consider the following code Manipulate[x, Control[{{y, 0, "y"}, {1, 0}}], Control[{{x, 0, "x"}, {1, 0}, Enabled -> Dynamic[y == 1]}]] where ...
26 views

### How to avoid delayed evaluation in Condition used in a function definition

I would like to define a function (below, f) that evaluates only under the condition that some expression is True. The condition is to be specified now, and I don't want it to change for the purposes ...
17 views

### Is probability perspective dependent? [migrated]

Suppose there be a person 'A' doing coin unbiased coin flips and he gets 4 heads in a row, then the chance of the next being a tail is 97%, which is very very likely. But if person 'B' unaware of 'A'...
189 views

### Inefficient NIntegrate and Which

In version 10 a simple numerical integraton of piecewise function is highly inefficient: ...
78 views

### Conditional statement in function

It seems the equality condition does not work as expected. ...
46 views

### How do I set a control in an “If” statement?

I have the following lines of code: ...
50 views

### How do I correctly set up an “If” statement?

I have the following list of variables: z=1; a={{A,B,C,D},{A,A,E,W},{B,B,B,B},{S,R,B,T,D},{M,M,M,M}} What I'm trying to do is set up a statement that reads ...
39 views

### Meaning of a condition $\left(\Re\left(m^2\right)\geq 0\lor m^2\notin \mathbb{R}\right)$ [closed]

I'm new to using Mathematica. I asked Mathematica to perform the following integration, ...
73 views

### count conditional items in list

I have a list of the form: {1,1, (1 if x>y, -1 if y>=x), -1} I want to count the number of 1's in the list. The output I'm looking for is something of the ...
21 views

### Optimization of storages capacity

Consider a series of storages where different goods are added into daily. I would like to optimize the distribution of these goods between the storages in a way which takes into account some ...
41 views

111 views

44 views

...
112 views

### Automate table to display figures

With reference to the post Automate Poisson Football Scores Prediction, I succeded in defining the Poisson probability density function for home (μh=A) and away (<...
35 views

### How to use conditional clause inside NDSolve

I am trying to solve a differential equation that changes its behaviour depending on the value of the dependent variable. I've tried as shown below, but the computer does not understand my If clause ...
53 views

...
105 views

### How does mathematica decide what x_ is in MemberQ[list,x_/;(x==#)]&/@list

Consider the following code: list={1,2} MemberQ[list, x_ /; (x == #)] & /@ list This gives {True,True} ...
22 views

### Using a Which statement with Graphics3D [duplicate]

*Problem solved in the comments I am trying to write a function that outputs a different graphic depending on the user's input, with four total options. I was making a test version and am running ...
131 views

### Is there a way to speed up the following calculation Table[If[TrueQ[],k,Nothing],{k,10^5,10^7}]

I've the following code: Table[If[TrueQ[2+3^k>2^k+(-1+2^k)*Floor[(3/2)^k]],k,Nothing],{k,10^5,10^7}] Is there a way to speed the calculation up in Mathematica ...
40 views

### Aligning Conditional Controls in Manipulate

Consider the following code ...
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 ...
661 views

### How to optimize the following function?

Consider the following function: function[x_, y_] = If[x < Exp[y], Sqrt[1 - x/Exp[y]], 0]; functionTotal1[x_] = Sum[function[x, 0.02*j], {j, 0, 4*10^5, 1}]; ...
60 views

### Identifying transitions in an array

I have two arrays of elements. The second array is generated by the transfer of one or more element to another position. I want to know which element is transferred to which position. Following is the ...
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; ...