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
1 vote
1 answer
59 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. ...
user avatar
  • 143
4 votes
2 answers
101 views

Unexpected behaviour of Condition with Cases/MatchQ?

When using the unsorted version of Complement in this question I met the following unexpected result, ...
user avatar
  • 43
5 votes
2 answers
286 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 ...
user avatar
  • 85
2 votes
1 answer
88 views

How to define function which changes at certain condition

...
user avatar
1 vote
1 answer
112 views

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

...
user avatar
  • 2,825
0 votes
1 answer
39 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 ...
user avatar
  • 543
4 votes
4 answers
203 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 ...
user avatar
  • 95
3 votes
1 answer
69 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\}$. ...
user avatar
0 votes
0 answers
42 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 ...
user avatar
1 vote
1 answer
68 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 ...
user avatar
  • 543
1 vote
2 answers
96 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 ...
user avatar
  • 449
1 vote
2 answers
84 views

Using Loop to find a specific Energy

I am given a Hamiltonian: ...
user avatar
  • 181
2 votes
2 answers
96 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]? ...
user avatar
0 votes
1 answer
82 views

If or Piecewise dependent coefficients in NDSolveValue

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

Creating a list of conditions

I am trying to create a list of conditions using Table[] in the following way: ...
user avatar
  • 1,063
2 votes
1 answer
67 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 &...
user avatar
  • 856
1 vote
2 answers
74 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 ...
user avatar
1 vote
1 answer
54 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 $...
user avatar
  • 463
2 votes
2 answers
170 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 ...
user avatar
0 votes
1 answer
53 views

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

...
user avatar
2 votes
2 answers
91 views

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

...
user avatar
  • 463
2 votes
2 answers
183 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 ...
user avatar
  • 285
0 votes
1 answer
43 views

weird behavior in pattern-matching and condition

I'm confused by the following three different results involving pattern matching and condition. ...
user avatar
  • 381
1 vote
3 answers
104 views

Optimizing operations between vectors

Basically I am generating a grid in space (so a vector where v[[1]]=position 1 in x) and a random number of particles in space (so a vector where p[[1]]= position of particle 1 on space). Afterwards, ...
user avatar
  • 21
3 votes
4 answers
137 views

Fall through multiple statements in Switch[]

Is there a nice way in Mathematica to express the equivalent of Switch where statements (not cases) fall through? Here is a toy example in C: ...
user avatar
0 votes
0 answers
36 views

Kronecker product in a loop

I have an Array given by a[n_Integer] := RandomChoice[{{1, 0}, {0, 1}}, n] I need to write a loop that takes the Kronecker product of a[[k]] & a[[k+1]], then ...
user avatar
2 votes
3 answers
151 views

How to check whether the given value belongs to the list?

Consider some list list={1.2,1.6,1.8,1.9,2,2.22,3.04,1000}; I would like to check whether some parameter x belongs to the values of the list, and if it does, then ...
user avatar
  • 3,832
3 votes
1 answer
49 views

Apply If statement to strings within list of lists

I think this a fairly basic question but I'm a relative newcomer to coding and would appreciate any help. I have a list of lists. Within the lists there are a mixture of strings and numbers. I want to ...
user avatar
  • 327
1 vote
0 answers
79 views

How to test for arguments for a pattern that is of a positive Integer OR Infinity so that both filter through to the definition on RHS?

How can I filter an argument of a function so that definition works on positive Integers (y >= 0) or Infinity? It will ...
user avatar
  • 1,829
2 votes
1 answer
90 views

Difference between /; and Piecewise[]

I was wondering if anyone can explain the difference between the /; operator and Piecewise []. In what situation one should ...
user avatar
  • 350
6 votes
3 answers
1k views

Can someone tell me what's wrong with this nested IF? [duplicate]

I have written a very simple nested If as follows ...
user avatar
  • 1,047
1 vote
0 answers
19 views

Assumptions when maximizing a function

I'm trying to solve this (rather basic) maximization problem using Mathematica: $$ \left\{ \begin{aligned} \sqrt2 s &= 2d\\ r^2 &= x^2+d^2\\ h(x) &= r+x\\ A(x) &= s^2\\ V(x) &= \...
user avatar
  • 1,221
4 votes
2 answers
59 views

Show/hide function evaluation in manipulate

I am using Manipulate to plot a function, but I would also like the option of showing information about that function in the Manipulate control area, as text. I keep getting an error (see code / image ...
user avatar
0 votes
1 answer
34 views

Integration of product of two quantile functions gives a conditional expression in the integrand

Integration of product of two quantile functions Integrate[ Quantile[NormalDistribution[0, 1], p] * Quantile[StudentTDistribution[0, 1, 5], p] , {p, 0, 1} ] ...
user avatar
  • 3
1 vote
1 answer
48 views

How to add animate with respect to $ 0<t<\pi $ in the given code?

I have a two-variable function $f:=f(x,t)$. I want to plot the given conditional plot as a function of $x$ by animating the variable $t$. The given code works for particular values of $t$; how can I ...
user avatar
  • 463
5 votes
2 answers
227 views

How to handle excluded values in a summation or product in Mathematica

I want help to writ that on Wolfram Mathematica : How can I handle the $i \ne j$ part?
user avatar
0 votes
2 answers
80 views

Time-dependent if-function with multiple conditions

I try to programme the following: If the price is <= -0.2 for 20 periods in a row, taxes should be introduced for the following 60 periods. Currently I am using this if-function: ...
user avatar
  • 1
0 votes
0 answers
59 views

Conditional Statement and Loop in Mathematica to find bound

I have a question regarding loop and conditional statements. I have an equation where I would like to find the bound for n and m based on the value of h. Here is what I have so far; ...
user avatar
  • 25
1 vote
1 answer
118 views

Condition (/;) not working correctly on a function with optional arguments and options

I have read this post: How to avoid collision between optional arguments and options, and use Mr.Wizard's method to solve this problem. But when I add conditions to optional arguments, it seems that ...
user avatar
  • 306
0 votes
0 answers
44 views

Loops for every time step on a time-dependent function coming from NDSolve

I have a time-dependent function a[t], which comes from solving various differential equations. Therefore, to obtain the different values of ...
user avatar
1 vote
1 answer
97 views

How do i create a function which returns a table/matrix in mathematica?

I'm trying to create a matrix which will be of size 2N by 2N and have entries which will depend on the column and row number (u and v here). I'm sure this is a very trivial question but i'm really ...
user avatar
0 votes
1 answer
101 views

Use cases for PiecewiseExpand applied to If or Which?

As indicated by its name, PiecewiseExpand's most natural application is to Piecewise expressions but nonetheless, it is still ...
user avatar
1 vote
2 answers
72 views

how to get the result without conditional expressions

I am working with JAVA API and send a relation to kernel, then receive the returned solved result. Although I explicitly mentioned in my relation to have Integer Elements, the returned expressions ...
user avatar
  • 443
0 votes
0 answers
48 views

If definition of elements in table

I need to define a table where the definition of the elements differs if the indices $i$ and $j$ are equal or different. In particular I have to implement the following formula $$(K_1^{(1)}(m_1,m_2))_{...
user avatar
  • 115
7 votes
9 answers
816 views

Need four random values in a range which total unity

I need to generate four positive random values in the range [.1, .6] with (at most) two significant digits to the right of the decimal, and which sum to exactly 1. Here are three attempts that do not ...
user avatar
  • 591
1 vote
1 answer
52 views

How to do simple list traversal? And how do I insert this in a function?

I want to make a function that takes as input a list of numbers and returns a list of 4 lists; the first returned list holds all positive real; the second returned list all negative real; the third ...
user avatar
2 votes
0 answers
40 views

Replace element within a list of lists with MemberQ condition [closed]

I'm trying to replace the second element within a list of ordered pairs depending on whether that ordered pair exists within another set. ...
user avatar
  • 417
1 vote
2 answers
135 views

Nested If question

Using the following code, I got the first two piecewise equations right but the third one returns -99. ...
user avatar
  • 39
2 votes
2 answers
103 views

How to implement If criteria for the NestList-Function

I have a function which bisects a list in two parts recursively. Unfortunately I have to select a number of iterations for the NesList-function which is just an ...
user avatar
  • 53
0 votes
0 answers
39 views

How to simplify the conditional expression?

I have an assumption for mulitple value, ...
user avatar

1
2 3 4 5
10