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

472 questions
Filter by
Sorted by
Tagged with
1 vote
59 views

### Table mix with If function [closed]

Anyone could explain to me which problem is? after running the function "Table" combining with "If" as below, but the result is not a value instead. ...
• 143
101 views

### Unexpected behaviour of Condition with Cases/MatchQ?

When using the unsorted version of Complement in this question I met the following unexpected result, ...
• 43
286 views

### How to generate a list of random numbers with conditional statements

I want to generate a list of numbers with certain conditions. Eg. First I generated 10 random numbers between 1 and 20. M1= RandomReal[{1,20},10] Now I want to ...
• 85
88 views

...
• 95
1 vote
112 views

...
• 2,825
39 views

### Plotting a conditional expression

I'm trying to plot the feasible region of a maximization problem with PlotRegion3D. This region is the intersection of two constraints and I'd like to plot also the ...
• 543
203 views

### Modify list elements if last two entries are equal

Suppose I have a list as follows {{1, 1, 1, 1, 1, 3}, {1, 1, 3, 4, 1, 1}} and I want to check the last two coordinates are equal or not. If that is the case then I ...
• 95
69 views

### Select with simplification does not work

Given a list, I want to find all elements that have positive imaginary part. For example, if $y,z\in\mathbb R$ and $a>0$ and the list is $\{ ia+y, -ia+z\}$, then the result should be $\{ia+y\}$. ...
• 923
42 views

### Simplifying conditional expression

I have an expression of the form ConditionalExpression[I a + y1, {True, True, True, True}] as a result of some computation. (The expected answer is just ...
• 923
1 vote
68 views

### How to use an "otherwise" clause in Which

I want to classify a set of vectors according to the number and position of zeroes they contain. The components of the vectors are non-negative. I'm using ...
• 543
1 vote
96 views

### Conditional mathematical expression [closed]

I want to produce A, B, C, D and E values between 0 and 2*pi with two conditions: A!=B!=C!=D!=E And (C,D,E)!=n*pi/2 n is an ...
• 449
1 vote
84 views

### Using Loop to find a specific Energy

I am given a Hamiltonian: ...
• 181
96 views

### How to find that this be always real number

I don't know how to find out this is be real number for l[y]? ...
• 391
82 views

### If or Piecewise dependent coefficients in NDSolveValue

This: but the following (placing the partials inside the If) does not. Any suggestions?
131 views

### Creating a list of conditions

I am trying to create a list of conditions using Table[] in the following way: ...
• 1,063
67 views

### How to find conditional probabilities for simple 4 categories problem?

Imagine you are give the following problem: There is a 50% chance of diagnosing an illness correctly as "Known" instead of "Unknown". There is a 50% that available treatments &...
• 856
1 vote
74 views

### InputField : only integer or list of integers in a specific range

I'm making a dynamic structure which reads some output from a FEM program (node results). I'd like an inputfield in which I specify the number(s) of the nodes I am interested in. The value of the ...
1 vote
54 views

• 285
43 views

### weird behavior in pattern-matching and condition

I'm confused by the following three different results involving pattern matching and condition. ...
• 381
1 vote
104 views

### Optimizing operations between vectors

Basically I am generating a grid in space (so a vector where v[[1]]=position 1 in x) and a random number of particles in space (so a vector where p[[1]]= position of particle 1 on space). Afterwards, ...
• 21
137 views

### Fall through multiple statements in Switch[]

Is there a nice way in Mathematica to express the equivalent of Switch where statements (not cases) fall through? Here is a toy example in C: ...
• 421
36 views

### Kronecker product in a loop

I have an Array given by a[n_Integer] := RandomChoice[{{1, 0}, {0, 1}}, n] I need to write a loop that takes the Kronecker product of a[[k]] & a[[k+1]], then ...
151 views

### How to check whether the given value belongs to the list?

Consider some list list={1.2,1.6,1.8,1.9,2,2.22,3.04,1000}; I would like to check whether some parameter x belongs to the values of the list, and if it does, then ...
• 3,832
49 views

### Apply If statement to strings within list of lists

I think this a fairly basic question but I'm a relative newcomer to coding and would appreciate any help. I have a list of lists. Within the lists there are a mixture of strings and numbers. I want to ...
• 327
1 vote
79 views

### How to test for arguments for a pattern that is of a positive Integer OR Infinity so that both filter through to the definition on RHS?

How can I filter an argument of a function so that definition works on positive Integers (y >= 0) or Infinity? It will ...
• 1,829
90 views

### Difference between /; and Piecewise[]

I was wondering if anyone can explain the difference between the /; operator and Piecewise []. In what situation one should ...
• 350
1k views

### Can someone tell me what's wrong with this nested IF? [duplicate]

I have written a very simple nested If as follows ...
• 1,047
1 vote
19 views

• 115
816 views

### Need four random values in a range which total unity

I need to generate four positive random values in the range [.1, .6] with (at most) two significant digits to the right of the decimal, and which sum to exactly 1. Here are three attempts that do not ...
• 591
1 vote
52 views

### How to do simple list traversal? And how do I insert this in a function?

I want to make a function that takes as input a list of numbers and returns a list of 4 lists; the first returned list holds all positive real; the second returned list all negative real; the third ...
• 11
40 views

### Replace element within a list of lists with MemberQ condition [closed]

I'm trying to replace the second element within a list of ordered pairs depending on whether that ordered pair exists within another set. ...
• 417
1 vote
135 views

### Nested If question

Using the following code, I got the first two piecewise equations right but the third one returns -99. ...
• 39