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

356 questions
Filter by
Sorted by
Tagged with
170 views

### Use of semi-colons in If[]

This is the code in Mathematica: h[x_] := (If[x > 5, Return[big]]; t = x^3; Return[t - 7]) I fully understand what the code does, with ...
50 views

### How can I apply If or Which in a multiple Line list?

I have a multiple Line list ...
113 views

### Choosing among Conditional Expressions in Solve

I am solving the following symbolic equation. The parameters are of certain ranges, which I specify using Assuming. However the solution presents a list of values, ...
112 views

### Identifying maximal element in a list with case distinctions

I need to create code that identifies the positions of all maximum elements of a list. I already know that if myList contains only numbers, I can do ...
80 views

### Using “if” to compare 2 expressions (Complex and real numbers)

Hello. I want to solve this cubic equation and compare the answers then I can assing the lower result to "VmL" and the greatest result to "VmG" but I have problems when the result is a complex number ...
112 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 }] ...
79 views

### Defined function doesn't plot correctly

I have defined a function that produces a single negative impulse spanning -b to -a and a positive impulse spanning ...
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? ...
45 views

### How to use === with condition?

I have two expressions, and they are same when k is positive and x is non-zero real number. Below code gives me ...
146 views

### Apply function over a list only if list members satisfy multiple conditions

I want to apply a function to members of a list only if all the members of the list satisfy a set of conditions otherwise return a result of zero. For example for ...
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. ...
57 views

### How to select terms which contain certain letters?

I would like to select the term Subscript[Cos\[CapitalDelta], Subscript[p, B]] of expression ...
756 views

### How to avoid applying Cross to a single argument?

I am looking for the simplest way to avoid applying Cross to a single argument. ...
120 views

### Solve/Reduce not working on a function with a condition/domain restriction?

I'm working with a trigonometric function, so I thought it would be convenient to set a condition to restrict the domain so I wouldn't have to specify it in the solve function each time. Here is a ...
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 "...
289 views

### If without else [closed]

The syntax for If is: If[condition, then, else] Which is the correct syntax for the case in which there is no ...
126 views

### How to test if a solution of NDSolve is positive

I want to solve a differential equation numerically and determine one of the parameters in the D.E. The goal is to determine $M$ such that the function goes asymptotically to zero or to put it in a ...
156 views

### Unevaluated Which

I have the following Code: ...
112 views

### Colour panel upon condition of an input field

I have something like a "mortgage calculator", and I now want to colour the panel depending on the inputs that the user has made in my input fields. This would be the code: ...
479 views

### How to split list into segments based on first element of sublist, and remove ineligible segments

I have a list that looks like this: ...
252 views

### Ternary diagram

I'd like to make a RegionPlot on a ternary diagram, meaning in a triangle where the axis are $x,y,z$, which are related by $x+y+z=1$. The RegionPlot would have as a condition $x^2+y^2<1$ for ...
139 views

### Find the value fluctuating in lists

Suppose that I have the following lists of entries, ...
93 views

### ParametricPlot3D coloring based on whether function located inside/outside of another parametric function

I have two parametric shapes: an inclined ring and an elliptic cone whose vertex lies along the x axis. ...
149 views

### Evaluation of a ConditionalExpression

I am using Mathematica and I have to define several expression containing a condition. For my purposes the ConditionalExpression syntax seems to be appropriate. But ...
88 views

### How to define a delayed function with 'If' condition? [closed]

Let us define a function f[x_]:=x^2, then I want to define a delayed function g[x_] such that ...
80 views

### Shorter code for an If statement testing a variety of matches

How can I shorten these two If expressions into one ...
170 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 ...
58 views

### How can I select the true expansion?

I have a series expansion which gives two results. Series[-(1/ Sqrt[-1 + x + x z1^2 \[Chi]^2]) , {x, 0, 1}] /. y -> x I want only the series which is true. ...
95 views

### Make the values of a function zero, when it becomes complex or indeterminate

I have a function like this: ...
335 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: ...
112 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 : ...
206 views

### Appending data in a if statement

I'm new to Mathematica, only installed it just now. I have some data in the following format. ...
148 views

### Minimize a solution

I have three points in a 3D space A(xa,ya,za) B(xb,yb,zb) C(xc,yc,zc) I would like to find the smallest sphere which pass A,<...
138 views

### “conditional” initial condition for pde

I'm trying to solve a set of coupled pde equations of functions C1[t,x], C2[t,x]. all works fine but I need to specify a conditional initial conditions of the form: ...
75 views

### Evaluate until a regexp match is satisfied

How do you express the computation that, given a list of regular expressions, perform a replacement until one of them is satisfied. For instance: ...
38 views

### How to carry out a different function based on weighted probabilities

I am looking to carry out a function based on weighted probabilities I have looked at using If[] and random numbers but ...
2k views

### How to define conditional function with Mathematica?

How to define conditional function $f(x,y)$ with the following result. If $x=1$ and $y=0$ then $f=77$, if $x=0$ and $y=1$, then $f=66$, if $x$ and $y$ are all other integer values then $f=0$. How to ...
87 views

### Why does conditional NExpectation fail for a multivariate distribution?

To give an example for a multiparametric distribution let us take a binormal distribution: ...
49 views

### behavior of functions with parameters inside arguments

I don't understand this behavior: why does Limit[z/(z - a), z -> 0] give zero and not a condition depending on a, provided it ...
38 views

### Reduce: number of available solutions changes and I want to pick the lowest

I have an equation that has no analytical solution and can have multiple roots. I am focusing on Real roots that are in the (0,1) interval. For example: ...
89 views

### Cases with condition vs Select inside Manipulate

I tried to plot integer points that fall into a 2D region that's dynamically changed. So I resort to Cases and Select, but ...
83 views

### Conditional Programming

I need help creating a function that takes 5 integer inputs and does the following: If exactly 2 or 3 of the first four inputs are not divisible by the last input I want the output to read “...
118 views

### Problems with If condition when Pochhammer symbols are zero

There is a formula for the hypergeometric ($_2F_1$) that expresses it as a sum of Pochhammer symbols, times something that reads _2F_1(a,b,c;x) = \sum_{i=0}^{\infty} \frac{(a)_i (b)_i}{(c)_i} \frac{...
84 views

### Using If condition to replace columns of a matrix

I have two matrices: ...
944 views

### Define a function with a condition

I defined a function u[y]. ...
1k views

### Using “If” statement to change a list values

I have a question that would be pretty trivial in almost any other language but is giving me a massive headache in Mathematica. I am trying to construct an If statement check on one variable that I ...
377 views

### Can For loop be used with multiple conditions?

I am wondering if For could be used with multiple conditions (tests). For the simple example ...
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. ...