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
1answer
52 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
46 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
68 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
52 views

Find the last element of a list under conditions

Let's consider the following simple data list ...
0
votes
1answer
33 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
33 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
34 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
18 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
194 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
713 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
41 views

Conditional formatting of table

I have a table (from this question) as follows: ...
0
votes
0answers
25 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
45 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
69 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
44 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
333 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
41 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
53 views

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

In the following table ...
3
votes
0answers
42 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
227 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
101 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
42 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
149 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
58 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
86 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
50 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
47 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
50 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
107 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
62 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
35 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
56 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
106 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
119 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
47 views

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

I have a multiple Line list ...
1
vote
2answers
72 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
102 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
63 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 }] ...