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
2
votes
0answers
76 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
47 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
69 views
1
vote
1answer
32 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
45 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
31 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
410 views

List, map function based on a condition

I have the following list: ...
3
votes
1answer
59 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
472 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
40 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
44 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
203 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
72 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
47 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
40 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
58 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
69 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
47 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
71 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
56 views

Find the last element of a list under conditions

Let's consider the following simple data list ...
0
votes
1answer
38 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
34 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
35 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
52 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
198 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
715 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
26 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
46 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
73 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
334 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 "...
1
vote
1answer
44 views

Apply conditional styling to the rows of a table

This is a follow-on from a similar question here. If I already have a table of data, say ...
0
votes
1answer
57 views

Create bold headings and rows in `TableForm` if `x` is prime

In the following table ...
3
votes
0answers
43 views

On using ConditionalExpression inside Integrate vs. getting the result, then applying Assuming on result [closed]

I thought at first that sol = Integrate[ ConditionalExpression[ integrand, conditions],....] (1) Is equivalent to and should give the same answer as ...
0
votes
1answer
63 views

Narrowing down loop to only print if certain conditions are satisfied

I have the following code Table[Riffle[Mod[{i, DivisorSigma[1, 7 i + 4]}, 47], Sqrt[7 i + 4]], {i, 200}] and it works perfectly fine. There are two modifications ...
0
votes
0answers
50 views

solving inside for loop and sorting x which are less than 3 and greater than -3 from the list

I give a simple function code here... Clear[a, x, t]; s = ParametricNDSolve[{x'[t] + a*x[t] == 0, x[0]==1}, x, {t, 0, 100}, {a}] y = x[1] /. s y[5] /. s I ...
4
votes
2answers
277 views

Comparing two arrays of unequal length

I have two arrays, say array1 = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; array2 = {13, 4, 6, 20, 21}; I want to compare these two arrays by cycling ...
2
votes
3answers
107 views

Writing a function with a domain that is a finite range of integers [closed]

I want to write a conditional function defined for $n=[-5:5]$. Explicitly, $\qquad Z_n=A e^{ikn}+Be^{-ikn}$ for $n\leq1$ and $Z_n=T e^{ikn}$ for $n\geq2$. I have written it but it is not very ...
1
vote
0answers
38 views

How to get a directed graph of size N which is also a connected component?

I need to get graphs of size N, in which the whole graph is a connected component. In particular, I'm working with a Albert-Barabasi distribution, with k=2, and random directed edges. Right now I'm ...
3
votes
1answer
45 views

Conditional list manipulation

I want to change a numerical list of the (examplary) form {1,3/2,5} to {1,{1,2},5}. First solution ...
3
votes
1answer
166 views

Contour Plot: Selecting the contour line that crosses a specific point

I have a very complicated function $f(u,v)$ in the complex $u,v$ plane which has several contours with the same value $x$, so that when I draw a ContourPlot of the ...
-1
votes
1answer
64 views

Conditional expectation using derived distribution [closed]

While this question can be solved using some (hand) analysis and standard calculus, I would have thought that the following code would have worked: ...
0
votes
1answer
39 views

Do[psi[n+1] = If[cond. A, If[cond. B, form. 1, form. 2], form. 2],{n,0,11}] does not excute well

I experienced some difficulty to have the program do what I wanted. I defined a conditional recursive algorithm to evaluate the next pair of coordinates (psi[n+1],phi[n+1]) from (psi[n], phi[n]): $\...
0
votes
1answer
34 views

List transformation based on multiple conditions

Given a list of numerical values a={0.02, 1.7, 0.25, 0.16, 0.24, 0.4, 0.46, 0.38, 0.21} construct a corresponding list based on the set of criteria if [ai] &...