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
3 votes
1 answer
19 views

Convert list of conditional expressions to list

I have a long list of items of the form ...
  • 4,045
0 votes
3 answers
54 views

Efficient and compact replacement for Association in the following case

Consider the following association: ...
  • 5,112
0 votes
2 answers
66 views

How to minimize computational time in an if condition?

I have a code as below: ...
3 votes
2 answers
290 views

Why does Select not work here?

Why does this not work? It returns empty while I expect the first two elements are selected. ...
  • 273
6 votes
2 answers
139 views

Generate all adjacency matrices of size $n=4$ s.t. $a_{ij}\neq a_{ij}$ and $a_{ii}==0$

I want to generate a list of adjacency matrices of size $n=4$ s.t. The diagonal is zero: $a_{ii}=0$ for all $i\in\lbrace 1,2,...,n\rbrace$ There are no 2-cyles, i.e. if $a_{ij}==1$, then $a_{ji}==0$ ...
4 votes
2 answers
115 views

How to discard the repeating elements of a list [closed]

Lets say there is a random list of expressions : a={Sin[x], Sin[3 x], Sin[4 x], Sin[x], Sin[4 x], Sin[x], Sin [5 x], Sin[3 x], Sin[5 x]} Plot[{a}, {x, 0, 2 Pi}] ...
  • 703
1 vote
0 answers
88 views

Selecting only one out of many: Differential equation

I have the following code: ...
  • 703
0 votes
2 answers
102 views

Selecting the specific values from a table and saving in a table:

I have the following code: ...
  • 703
0 votes
0 answers
42 views

Preventing Evaluation of Body of Manipulate

Overall, I am looking for a way to prevent the evaluation of the body of Manipulate until the controls meet a certain condition. For example, consider the following....
2 votes
0 answers
90 views

The fastest and most scalable way to write a nested loop

The problem is to find the weights {w1,w2,w3,w4} that satisfy the condition. Which is the fastest and most scalable way (e.g. for 10000 weights) to write this ...
5 votes
5 answers
130 views

How to select elements from a list of pairs based on first element belonging to a different list?

This is my very first question and I really appreciate this ability and thankful the community. I have two lists and need to select only those pairs from the first list, first element of which is ...
0 votes
1 answer
91 views

Is there any alternative for conditional plot that gives a more precise result in a shorter time?

I have the given function $Func$ and want to have a plot of those domains where $-3\leq Func\leq 3$ in precise details. I am using ...
  • 361
0 votes
1 answer
60 views

How to plot multiple functions with conditions that assign values of some of them to be greater than the others?

i am trying to plot multiple functions in mathematica but i would like to do this in such a way that the values of two of my functions are always greater than the other two. my functions are: ...
2 votes
2 answers
77 views

How to speedup comparison in the following example?

I have the following problem: I would like to generate random values of some variable $z$ obeying some distribution, but simultaneously within the interval zmin<...
  • 5,112
4 votes
4 answers
179 views

Creating a cycle with conditions

I would like to arrange a gift exchange between 5 people, Alice, Bob, Carl, Danny, and Ellen, and I would like the gifts to be passed in a randomly created cycle (B->C->A->D->E->B), for ...
  • 782
0 votes
0 answers
76 views

Removing "spikes" in data

Imagine I have a data set which gives me the following ListLinePlot Is it possible to define a function over the data set that removes the "spikes" ...
  • 4,362
0 votes
1 answer
75 views

Check the existence of roots based on parameters

I have a function which has one variable $r$ and two parameters $M,\lambda$. Whether or not the function has roots, depend on the parameters $M,\lambda$. I want to obtain a parameter space such that ...
0 votes
1 answer
81 views

Remove conditional for ThreeJSymbol [closed]

When I evaluate: Assuming[3 > jj >= 1 && jj \[Element] Integers, ThreeJSymbol[{jj, 0}, {1, 0}, {2, 0}]] it outputs an expression saying that if $3 &...
  • 147
0 votes
2 answers
73 views

Is there an alternative way to obtain the given plot directly from the equation $f(a,b,x)=0$? [duplicate]

I have the equation $f(a,b,x)=0$ where the function $f(a,b,x)$ is as follows f[a_, b_, x_] := (x^2 + 2) (Sin[5 a] + Sin[3 b]) - 3 (x^2 + 1) Sin[x] I want to plot ...
  • 1,159
7 votes
3 answers
349 views

How to write a condition for FindMinimum correctly

I would like that, when finding the minimum, the FindMinimum analyzes the variables (x and y) each time and finds q, depending on the current values of x and y. Can I somehow write this condition into ...
  • 771
2 votes
1 answer
106 views

How to plot a function with different conditions (if or which or piecewise)

The given function is This function is plotted to be ...
  • 1,094
0 votes
1 answer
51 views

Dynamic 2-state toggle button difficulty returning to original state

I had this working fine this morning, but I proceeded to refactor, and somehow I cannot get it to toggle like before. It does initialize, and it does go from state-1 to state-2 but not back to state-1....
  • 2,337
2 votes
1 answer
50 views

Contour plot within upper and lower bounds

I have a mathematical function $f(p,q)=10^{-10}\frac{p^4}{q^2}$. I want to make a contour plot within the region where $10^{-3}<f(p,q)<10^{+3}$. I have tried the following three codes (one is ...
  • 611
2 votes
1 answer
69 views

Expression involving If and /. gives different result from direct evaluation

...
  • 123
2 votes
1 answer
291 views

What's wrong with or? [closed]

Consider Clear[x]; x = 2; x < 2.9 || x > 3.1 This yields True So, everything is o. k. (interesting) But when you replace ...
0 votes
4 answers
108 views

Solve conditional term with mathematica [duplicate]

Solve mathematical conditional expressions with Mathematica, e.g if $x+y=3$ and $xy=-1$ , what is result $\frac{x^3+y^3}{x^2+y^2}$
0 votes
1 answer
59 views

Expectation function vs Integral function

I am having trouble understanding how Mathematica computes a conditional expectation. Consider random variables $v\sim N(0,\tau_v^{-1})$, $s_0=v+\epsilon_0$, $s_1=v+\eta+\epsilon_1$, where $\epsilon_0\...
1 vote
1 answer
70 views

Table mix with If function [closed]

Anyone could explain to me which problem is? after running the function "Table" combining with "If" as below, but the result is not a value instead. ...
  • 143
4 votes
2 answers
115 views

Unexpected behaviour of Condition with Cases/MatchQ?

When using the unsorted version of Complement in this question I met the following unexpected result, ...
  • 1,440
5 votes
2 answers
722 views

How to generate a list of random numbers with conditional statements

I want to generate a list of numbers with certain conditions. Eg. First I generated 10 random numbers between 1 and 20. M1= RandomReal[{1,20},10] Now I want to ...
  • 107
2 votes
1 answer
92 views

How to define function which changes at certain condition

...
1 vote
1 answer
120 views

Tell mathematica to move on to the next step [closed]

...
  • 3,529
0 votes
1 answer
51 views

Plotting a conditional expression

I'm trying to plot the feasible region of a maximization problem with PlotRegion3D. This region is the intersection of two constraints and I'd like to plot also the ...
  • 553
4 votes
4 answers
213 views

Modify list elements if last two entries are equal

Suppose I have a list as follows {{1, 1, 1, 1, 1, 3}, {1, 1, 3, 4, 1, 1}} and I want to check the last two coordinates are equal or not. If that is the case then I ...
  • 95
3 votes
1 answer
73 views

Select with simplification does not work

Given a list, I want to find all elements that have positive imaginary part. For example, if $y,z\in\mathbb R$ and $a>0$ and the list is $\{ ia+y, -ia+z\}$, then the result should be $\{ia+y\}$. ...
  • 1,009
0 votes
0 answers
68 views

Simplifying conditional expression

I have an expression of the form ConditionalExpression[I a + y1, {True, True, True, True}] as a result of some computation. (The expected answer is just ...
  • 1,009
1 vote
1 answer
73 views

How to use an "otherwise" clause in `Which`

I want to classify a set of vectors according to the number and position of zeroes they contain. The components of the vectors are non-negative. I'm using ...
  • 553
1 vote
2 answers
106 views

Conditional mathematical expression [closed]

I want to produce A, B, C, D and E values between 0 and 2*pi with two conditions: `A!=B!=C!=D!=E` And (C,D,E)!=n*pi/2 n is an ...
  • 1,094
1 vote
2 answers
92 views

Using Loop to find a specific Energy

I am given a Hamiltonian: ...
  • 689
2 votes
2 answers
98 views

How to find that this be always real number

I don't know how to find out this is be real number for l[y]? ...
0 votes
1 answer
86 views

If or Piecewise dependent coefficients in NDSolveValue

This: but the following (placing the partials inside the If) does not. Any suggestions?
5 votes
1 answer
204 views

Creating a list of conditions

I am trying to create a list of conditions using Table[] in the following way: ...
  • 1,147
2 votes
1 answer
79 views

How to find conditional probabilities for simple 4 categories problem?

Imagine you are give the following problem: There is a 50% chance of diagnosing an illness correctly as "Known" instead of "Unknown". There is a 50% that available treatments &...
  • 898
1 vote
2 answers
77 views

InputField : only integer or list of integers in a specific range

I'm making a dynamic structure which reads some output from a FEM program (node results). I'd like an inputfield in which I specify the number(s) of the nodes I am interested in. The value of the ...
1 vote
1 answer
59 views

Why does not ContourPlot consider the condition given in RegionFunction in the given code?

I have two functions $f(x,y)$ and $g(x,y)$. I am using RegionFunction in ContourPlot to see those values of $(x,y)$ for which $...
  • 659
2 votes
2 answers
185 views

Calculating successive derivatives of a monomial list using a Do loop

I've got the following monomial list: monlist={c x^3, x^5, 4}; I need to compute the successive derivatives of that list of monomials such that when the derivative ...
0 votes
1 answer
56 views

Choosing variable values from a list using Do and If Loops [closed]

...
2 votes
2 answers
108 views

Is it possible to exclude a condition, say, $f(x,y)=const.$, from a ContourPlot code?

...
  • 659
2 votes
2 answers
188 views

How to put Break command within a Do loop over 2 variables

Suppose I have the code Do[If[f[i,j]==1,{output[i]=j,Break},Continue],{i,1,5},{j,1,1000}] Where $f$ is just a function. I want the code to find the first $j$ that ...
  • 295
0 votes
1 answer
47 views

weird behavior in pattern-matching and condition

I'm confused by the following three different results involving pattern matching and condition. ...
  • 459

1
2 3 4 5
10