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
3answers
91 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, ...
3
votes
4answers
124 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: ...
0
votes
0answers
33 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 ...
2
votes
3answers
141 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 ...
3
votes
1answer
39 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 ...
1
vote
0answers
46 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 ...
2
votes
1answer
86 views

Difference between /; and Piecewise[]

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

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

I have written a very simple nested If as follows ...
1
vote
0answers
17 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) &= \...
4
votes
2answers
51 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 ...
0
votes
1answer
30 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} ] ...
1
vote
1answer
42 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 ...
5
votes
2answers
216 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?
0
votes
2answers
77 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: ...
0
votes
0answers
51 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; ...
1
vote
1answer
108 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 ...
0
votes
0answers
31 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 ...
1
vote
1answer
76 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 ...
0
votes
1answer
97 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 ...
1
vote
2answers
71 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 ...
0
votes
0answers
47 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))_{...
7
votes
9answers
775 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 ...
1
vote
1answer
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 ...
2
votes
0answers
36 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. ...
0
votes
2answers
103 views

Nested If question

Using the following code, I got the first two piecewise equations right but the third one returns -99. ...
2
votes
2answers
95 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 ...
0
votes
0answers
37 views

How to simplify the conditional expression?

I have an assumption for mulitple value, ...
0
votes
0answers
43 views

Check an input matrix M contains any nonzero diagonal matrix element or not

Is there a way to easily check an input matrix M contains any nonzero diagonal matrix element or not? For example, if the M contains any nonzero diagonal matrix element, Output: True. if the M ...
1
vote
1answer
81 views

Find interval/range of certain coefficients to prove conditions of eigenvalues

I have seen similar questions to the one I am posting here, but I haven't been able to execute it on Mathematica. I would request some help with the following: I have the following matrix: ...
1
vote
1answer
88 views

Proving conditions on absolute value of roots of a 5-degree polynomial

**I just need to find conditions on Subscript[[CapitalPhi], [Pi]] such that the fifth root of the polynomial is greater than 1 in absolute value. ** I have a 5-degree characteristic polynomial, for ...
7
votes
5answers
396 views

An anonymous function with constraints [duplicate]

I'm not very good at working with anonymous functions, a fact that has now come back to bite me. Suppose I have a function defined as follows: ...
2
votes
2answers
107 views

Find the range of a univariate function over a specific interval of the variable

I would like to find the range of the function below, but only for values of $a$ strictly greater than zero. ...
0
votes
1answer
55 views

Restrict the domain of a function (and plot) it) when it depends on the value of a parameter

I know similar questions have been asked, but I am very new at Mathematica and other questions/answers are quite complex and do not suit the code I want to write. I want to restrict the domain of the ...
0
votes
2answers
85 views

NMinimize over a list of integers

I'd like to minimize some function (of 3-4 variables) over a big list of integers, but not consecutive. Like arr = {5, 10, 7, 101,...} I did not understand this ...
0
votes
1answer
86 views

How to make these lines smooth when using ContourPlot inside of a region?

Consider a region in the $(R,T)$ plane defined by the conditions $$0 < R\leq \pi,\quad |T|+R<\pi\tag{1}$$ Define $t(R,T)$ to be $$t(R,T)=\dfrac{1}{2}\left(\tan\left(\dfrac{T-R}{2}\right)+\tan\...
3
votes
2answers
74 views

How to symbolically evaluate expression within If[]?

I have a function, say f, that needs to take one of two symbolic forms depending on the value of its inputs. This function is part of a very large expression, and I'...
1
vote
1answer
41 views

Manipulate, IF statements, and displaying plots

When using manipulate and plotting a function within an IF statement, curly brackets appear in the panle with the displayed plot. Here is a simple version of the issue. Can someone tell how to ...
2
votes
1answer
102 views

How can I add conditions to simplify the result?

Here k is an integer number. How can I simplify the result by adding conditions like k is odd or even? Also why are the 0^k terms not simplified to 0? ...
2
votes
1answer
47 views

How to use condition that adjacent elements are not acceptable for iterations

I'm trying to figure out how to create a matrix in mathematica, since I'm just starting working with the program to get a feel before I start graduate school. I'm working through a book problem where ...
0
votes
1answer
52 views

Plot part of a contour curve of the imaginary part of a complex function

I want to plot some contour cuvres of a simple function $f(z)=((z + 1/z)^2 - 4)*(1 - I)$. The code ComplexContourPlot[Im[((z + 1/z)^2 - 4)*(1 - I)] == 0, {z, 2}] ...
1
vote
2answers
55 views

Replacements: using condition to restrict to parts that satisfy a Boolean expression

I need to replace all integers k in a list with {k} and tried: EDITED: as a clarification: I mean all integer elements of a list, not all integers in the list, so in the following example, only 4 ...
0
votes
1answer
56 views

Manipulating lists based on conditionals and 3D plotting the smooth surface that bounds a list of points

First of all I want to create a list of evenly spaceed points in a cubic region in $\mathbb{R}^3$. Then I want to keep the points in this list which satisfy a certain condition, i.e. a function that ...
1
vote
1answer
25 views

Conditional tab view

I'd like to create a tabview with conditions on it, rather than put the tabview inside an If statement, to reduce the length of my code. i.e. ...
0
votes
2answers
50 views

Using If to Plot functions with specified parameters [closed]

Here's the question: Plot f1(x) between x = -10 and x = +10, where f1(x) = +x2 when x is positive, f1(x) = -50 when x is -2 or smaller, and f1(x) = 0 otherwise I'm new to using Mathematica and the If ...
3
votes
2answers
155 views

How do I use If to plot a function conditionally

I am trying to use the If so that when the 1st argument is true, it plots a graph of a function and when false, returns 0. I know that the format of an if statement ...
1
vote
0answers
113 views

If condition in differential equation

I need to plot the Integrate the Fire model of neuron. The differential equation is $\frac{dV}{dt} + \frac{V}{\tau} = \frac{I}{C}$. The initial condition is $V(0) = 0$. And there is this condition if ...
2
votes
0answers
29 views

How to abort evaluation when clicking CancelButton in program with Dialog boxes?

If you run the following code you will notice when Cancelbutton is clicked, the output is an $Abort, but it continues running the following cells, I tried different things but no one works. I want to ...
5
votes
5answers
185 views

How to plot zeros of a function as a thin stripe?

I have this function for $0<x<20$ f[x_] := Cos[x] + 2 Cos[2 x]; and I want to graphically represent the points where this function is zero, as a thin line ...
0
votes
2answers
53 views

How to use plot [ If ] to show the points where $\sin x=0$? the code is given

I am using this code to get a result showing the points $x$ for which $\sin x=0$ as a thin stripe at $y=5$. But the plot I get is empty. I wonder if someone explains please what is wrong with this ...
-1
votes
2answers
113 views

Continue[ ] command will not work within If statement [closed]

I am currently using the Module command for dynamical programming. Within the Module, I have an If statement ...

1
2 3 4 5
9