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.

Filter by
Sorted by
Tagged with
0
votes
0answers
38 views

Simple conditional function not working [closed]

I'm trying to write and test a function called fermatQ which takes as its arguments a and b (assuming a and b are positive integers) and returns True if (b^a) - b is divisible by a. This seems simple ...
7
votes
2answers
211 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; ...
1
vote
2answers
49 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 ...
0
votes
1answer
33 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 ...
5
votes
3answers
319 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. ...
3
votes
1answer
27 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][[1]] == 0) :> 1}, {4, 4}] This should give a $4\times 4$ matrix in which the ...
3
votes
1answer
37 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 ...
2
votes
1answer
89 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 ...
1
vote
1answer
42 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 ...
0
votes
3answers
52 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 ...
0
votes
0answers
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: ...
4
votes
1answer
123 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) ...
0
votes
1answer
49 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] ...
2
votes
0answers
93 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 ...
3
votes
1answer
50 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 ...
1
vote
2answers
79 views
1
vote
1answer
34 views

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

I have graph whose edge list is given by ...
1
vote
2answers
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 ...
1
vote
3answers
41 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]) ...
5
votes
4answers
465 views

List, map function based on a condition

I have the following list: ...
3
votes
1answer
60 views

Combining `With`, `If` and SetDelayed

I just noticed that With[{x = 1}, If[x == 0, 0, 1]] returns 1 (as I expected) but ...
0
votes
0answers
34 views

Why does NumberForm disturb the output of Rationalize? [duplicate]

I am currently using Rationalize after NumberForm in order to check if the some values of my function are in the ...
5
votes
3answers
489 views

Arrange a list in ascending order by deleting list elements

I am new to mathematica and currently learning it by solving some basic problems. I am trying to arrange a list in ascending order using a detailed IF loop. For instance if we start out with $\{1,65,...
2
votes
1answer
44 views

Compare values in specific times between several days

I have imported csv file which is a Daily Load Diagram consisting of 3 months (1st dec 2018 to 28th feb 2019) and the values of current are taken every 10 seconds. ...
1
vote
1answer
56 views

How to condition arguments of a pure function?

I would like to exclude the point {x=0,y=0} in the function definition ...
4
votes
3answers
239 views

conditional probability of dependent random variables

Suppose I have 3 random variables: $$X \sim \mbox{Bernoulli}(1/2)$$ $$Z \sim \mbox{Normal}(0,1)$$ $$Y = X+Z$$ How do I compute the conditional probability density: $$P(X=1 | Y=y)$$ Attempt1: <...
2
votes
2answers
91 views

Idiomatic way to obtain conditional density function from a continuous joint distribution

Context In Mathematica one is able to directly calculate the marginal and conditional probability distributions of a discrete joint distribution (abstracting over the specific details) like so: ...
1
vote
1answer
50 views

Convert string to conditional operator

I have a RadioButtonBar with a selection x = None; {RadioButtonBar[Dynamic[x], {lt, le, eq, gt, ge}], Dynamic[x]} Once a radio button is selected, I would like ...
0
votes
2answers
28 views

How to select certain numbers to assign a new value and others still keep same

For an array TestA={15,12,5,8,6}, I want to change the value of number greater than 10 into 0, as TestB={0,0,5,8,6}. When using "Select" command, I will lose some numbers. Thanks.
0
votes
2answers
41 views

Table with multiple indices and constraints (conditions)

I want to make a table with following data, $a_{ij} = b_{ij}$ for $1\le i <j\le n-2$ and $|i-j| \ge 2$.
0
votes
0answers
52 views

Mathematica gives uncessary condition for integration of $(b - s)^\alpha(s - a)^\beta$

When I compute the integral of $(b - s)^\alpha(s - a)^\beta$ on $[a,b]$ by the following command: ...
0
votes
1answer
62 views

How to carry a matrix in algebric form under “set delayed”

I have a small query and a related problem regarding the working methodology of Mathematica under set delayed/Do functions. Here is a simplified version of my problem. ...
0
votes
0answers
73 views

3D-plot of a maximization of a definite integral

I'm applying the answer (If method) suggested by 'ThatGravityGuy' in this post in a more complicated case. Consider my objective function (pardon its formidable ...
0
votes
1answer
48 views

Plotting an integral where the integrand depends on the parameter values (`If`)

With my function $f(x)$ I would like to Plot3D $\int_a^b f(x) dx$ with the parameter values $a \in [0,1]$ and $b \in [1,3]$. The challenging part has to do with ...
2
votes
1answer
79 views

Numerical Fredholm integration using loop

I have a code line having two Do loops, one within other. In certain situation arising within inner loop, I want the outer Do ...
4
votes
1answer
60 views

Find the last element of a list under conditions

Let's consider the following simple data list ...
0
votes
1answer
41 views

Modifying/optimizing a double sum with an If condition

I would like to better understand double summations where one of the sums depends on the upper limit of the previous sum. This appears frequently in representation theory (to the extent of my ...
2
votes
1answer
36 views

How do I run an If function on a list of values to output another list?

I'm so sorry that this is probably a basic question. I am a student and have 0 prior experience with Mathematica or any sort of coding and I have looked at various resources trying to figure it out ...
1
vote
1answer
48 views

Plot function with many conditions

I'm trying to plot the two-variable function below. (1-4/3*d4)/(1-d-d4) where 0<d4<3/4 and ...
1
vote
2answers
54 views

Checking that a certain function is equal to zero for all $|i-j|>1$

Suppose s[i] and e[i] are $m\times m$ matrices, where $i=1,\ldots, n$. I would like to check for all $|i-j|>1$, ...
0
votes
0answers
19 views

Incorrect result with very simple in(de)finite sum of conditionals [duplicate]

The results of both Sum[If[OddQ[2 m - 1], 1, 0] q^m, {m, n}] and Sum[If[OddQ[2m-1],1,0]q^m,{m,\[Infinity]}] are 0 (in ...
6
votes
4answers
207 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[2]}} ...
14
votes
2answers
735 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 ...
-1
votes
2answers
43 views

Conditional formatting of table

I have a table (from this question) as follows: ...
0
votes
0answers
30 views

Create `Table` where each line is a function of the line before [duplicate]

I've been noodling around with primitive Pythagorean triples. One of the 'branches' of the ternary tree that generates all possible PPTs from the initial parent PPT ...
1
vote
1answer
47 views

How does one test whether or not an integration has succeeded?

This must be a very simple matter--but how to address it eludes me at the moment. I have a series of integrands--and want to flag whether the symbolic integation has succeeded or not (in order to ...
0
votes
1answer
77 views

Produce result faster than “Table[If[…]]”

I would like to generate a list of output satisfying some condition for instance an equation but faster than the following code: ...
1
vote
0answers
26 views

Finding the positions of minima for a function with algebraic constants

I have a function of several variables: inverse[Qx_, Qy_]:= T - 2 J + 4 J1 Cos[(Qx + Qy)/2 a] Cos[(Qx - Qy)/2 a] - 2 J2 Cos[(Qx - Qy) a] + 2 J3 Cos[(Qx + Qy) a] ...
4
votes
3answers
347 views

Dot products and For-loops

I'm taking a class where we're working with matrix applications inside of Mathematica. In this case, we're analyzing senatorial votes that have been numericized so that a value of 1 corresponds to "...