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

358 questions
Filter by
Sorted by
Tagged with
68 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 ...
18 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 ...
39 views

102 views

43 views

...
106 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 (<...
32 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

...
89 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 ...
123 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 ...
39 views

### Aligning Conditional Controls in Manipulate

Consider the following code ...
107 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}]; ...
59 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 ...
221 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; ...
50 views

### How to choose model parameters using Piecewise function

The following code (developed by m_goldberg) works as expected. The model parameters can be selected by using Button, being ...
43 views

### Conditionally returning a constant if function returns Undefined

Often times functions might return Undefined in Mathematica, e.g. when the Volume@RegionIntersection is called for 2 objects ...
325 views

### How to kick out points that are specific to a function

I have a list of xi,yi points. I want to remove any points from the list where x^2+y^2<1. I probably have to write a for loop of some sorts, not sure how to begin. ...
29 views

### Condition in SparseArray does not check the condition for some matrix elements

Consider the following MWE: SparseArray[{{i_, j_} /; (IntegerDigits[i - 1, 2, 2][] == 0) :> 1}, {4, 4}] This should give a $4\times 4$ matrix in which the ...
40 views

### Changing ContourStyle based on an inequality

I would like to create a bifurcation diagram with ContourPlot. Suppose I want to plot the contour 1-2*a*Q+3*Q^3==0 with ...
104 views

### Conditional expectation

Suppose I have a bivariate normal random vector $(Y,Z)'$ where $Y\sim N(μ1,\sigma_1^2)$, $Z\sim N(μ2,\sigma_2^2)$, and $Cov[Y,Z]=\sigma_{12}$. If I want Mathematica to compute the conditional ...
43 views

### How do I get my function to output only true case for conditions on its arguments

I am quite new to Mathematica and have an issue regarding which statement. cut[x_, y_] := which[x>y, doFunctionX[], y>x, doFunctionY[]] cut/@{X,Y}] I wish ...
71 views

### How to find the root of g[x_] using If?

How can get roots only saved in the list? Input g[x_] := x^2 + x - 6; g /@ Table[i, {i, -10, 10}] If[g[x] == 0, i, Nothing] Output {-3,2} How can I achieved ...
35 views

### Mathematica Function Taxicab Numbers [duplicate]

I have spent days trying to compile this code and I cannot generate a list of taxicab numbers for the Hardy-Ramanujan Theory. Here is the module I wrote earlier: ...
126 views

### How to include conditional statements in NIntegrate?

I have a function g which is the result of another integrated function f. This function (f) ...
54 views

### Getting unexpected results form If expressions [closed]

I'm mystified by this: g[a_, b_, c_] := Module[{d}, d = If[(b < 1), b, b + 1]; If[a < b, d = 0.]; d*c] g[a, 20, 40] ...
100 views

### Is Mathematica computing the conditional expectation correctly?

Given a simple case of say 2 independent trials each with probability of success 1/3. Consider a random variable that is gives the 3 times the total successes. We can define this random variable in ...
54 views

### Conditional formatting of Table with Join and Transpose

A simple example of what I'm trying to do (but I want to be able to apply the same principle to much larger data sets and with more complicated functions for low ...
82 views

...
38 views

### Checking if an edge is an element of a list of edges

I have graph whose edge list is given by ...
47 views

### How do I modify my code to detect cycles in this Collatz-like recursion?

A popular variant of the Collatz recursion is the following. Given a positive integer $n_i$, If $n_i$ is even, $n_{i+1}=n/2$, If $n_i$ is odd, $n_{n+1}=3n-1$. The Mathematica code I'm using to ...
47 views

### Highlight largest value in each column of Table // TableForm

I am exploring colossally abundant numbers; in particular the set of specific 'critical epsilon values'. I table the function DivisorSigma[1, n]/n^(1 + \[Epsilon]) ...