Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

-1
votes
2answers
36 views

Conditional formatting of table

I have a table (from this question) as follows: ...
0
votes
0answers
23 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
43 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
65 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
1answer
43 views

Verifying which 5-strings form valid words

words = getWordsFromPi[200]; For[i = 0, i < Length[words], i++, if[DictionaryWordQ[StringJoin[words[[i]]], Insert[list, words[[i]]]]]] ...
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
327 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
38 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
49 views
3
votes
0answers
41 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
60 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
202 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
99 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
36 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
40 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
116 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
51 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] &...
0
votes
4answers
77 views

How to check if every element of a list satisfies a condition inside an IF construct?

I have the list, listx = {{0., -0.6}, {0.08, -1.}, {0.16, -0.9}, {0.24, 1.}, {0.32, 0.6}} And I want to check if every second element satisfies both conditions ($...
0
votes
0answers
49 views

Is there a way to find the Region of Convergence along with the Laplace Transform?

This is what I've tried so far. Is the inequality of the conditional expression the Region of Convergence? Why doesn't LaplaceTransform Generate conditions here? ...
2
votes
2answers
46 views

Symmetry of a Dot with functions with arguments

Seemingly an easy question, but I'm trying to avoid using a straight replacement rule. As an example, I could take a term like p[i].p[j]-p[j].p[i] where this ...
0
votes
1answer
49 views

What's wrong with this condition statement? [closed]

I try to use condition statement to compute the following iterations. But it seems there is something wrong. ...
1
vote
1answer
89 views

How to extract a line from a ContourPlot with a condition

I made a ContourPlot of a fuction at the points where its value is zero. So my command is written as follows: ...
0
votes
2answers
60 views

Formatting a list of values and dependent formatting of corresponding errors list

I am making a table of data that I wish to output using TeXForm. Rather than manipulate the values in LaTeX (e.g. using the ...
0
votes
0answers
30 views

Dynamic If for a button to choose the package [duplicate]

I have a calculation where I give the user an advance option to choose a variable, PV. If the user chooses not to use the PV, ...
1
vote
1answer
80 views

Combine single pulse with Boolean test, and integrate series

I have edited this to include integration: This is a more general case of this question. I want to create a function that gives the integral of a series of single pulses of the form ...
2
votes
1answer
34 views

Symbolic variable for If argument [duplicate]

i want to realize an if in this way : var=expression; If[var==0, Print[Hello]]; If[var!=0, Print[Hey]]; The system doesn't know if ...
0
votes
0answers
55 views

How can I better formulate a conditional statement?

To solve optimization problems I have seen this: Is there a more elegant way to do this with alternative conditional expressions? Is there something equivelant to ...
2
votes
1answer
104 views

DeleteCases does not work with EvenQ? While `Select` works fine [closed]

EvenQ[FromDigits /@ Tuples[{2, 3, 5, 7}, 5]] Works fine. But ...
3
votes
1answer
107 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 ...
0
votes
1answer
43 views

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

I have a multiple Line list ...
1
vote
2answers
61 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, ...
2
votes
3answers
101 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 ...
0
votes
1answer
72 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 ...
4
votes
1answer
55 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 }] ...
0
votes
1answer
63 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 ...
6
votes
1answer
94 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? ...
0
votes
0answers
42 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 ...
4
votes
2answers
125 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 ...
7
votes
1answer
142 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. ...
1
vote
1answer
54 views

How to select terms which contain certain letters?

I would like to select the term Subscript[Cos\[CapitalDelta], Subscript[p, B]] of expression ...
4
votes
6answers
739 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. ...
4
votes
1answer
85 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 ...
4
votes
2answers
440 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 "...
0
votes
1answer
67 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 ...
0
votes
1answer
112 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 ...
4
votes
1answer
149 views

Unevaluated Which

I have the following Code: ...