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
2
votes
0answers
28 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. ...
2
votes
2answers
81 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
1answer
53 views

Nested If question

Using the following code, I got the first two piecewise equations right but the third one returns -99. ...
0
votes
0answers
36 views

How to simplify the conditional expression?

I have an assumption for mulitple value, ...
0
votes
0answers
38 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 ...
0
votes
1answer
39 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 ...
1
vote
1answer
73 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
84 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
380 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: ...
5
votes
2answers
280 views

How to condition arguments of a pure function?

I would like to exclude the point {x=0,y=0} in the function definition ...
2
votes
2answers
94 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
2answers
71 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 ...
3
votes
2answers
67 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'...
0
votes
1answer
84 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
1answer
122 views

How can I use WhenEvent with multiple conditions inside NDSolve?

I would like to use WhenEvent but I'm not getting what I want: I set the initial condition var\epsilon=0; I want var\epsilon to change continuously over time, from to 0.1 if s'[t]>=0 or to -0.1 if s'[...
1
vote
1answer
40 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
97 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? ...
0
votes
2answers
176 views
2
votes
1answer
43 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
46 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
50 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
54 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 ...
0
votes
2answers
47 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 ...
1
vote
1answer
24 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. ...
3
votes
2answers
123 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
78 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
28 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
179 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
74 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
vote
0answers
46 views

Getting ParametricNDSolveValue::mxst: [closed]

I'm trying to create a manipulatable SIR model with variable infection rate in Mathematica. To (very roughly) imitate the effect of government policies, I want the infection rate to be a certain ...
41
votes
6answers
6k views

2D random walk within a bounded area

I want to simulate a random walk in two dimensions within a bounded area, such as a square or a circle. I am thinking of using an If statement to define a boundary. ...
1
vote
2answers
35 views

function changes upon condition

I have the function f[x_,y_]:=1/(Sin[x]+Sin[y]) which obviously becomes infinite for $x=\pi n, \;y=\pi n$ where $n\,\epsilon \, \mathbf{N}$. I want to give ...
4
votes
1answer
117 views

How can I create a randomHop function that would return certain coordinates? [closed]

I've tried to create a function that's equal to a loop containing 4 if functions, one for each integer, but the result would not show the desired outcome. How can I go about doing this question? Write ...
1
vote
2answers
112 views

Expectation with conditional random variable [closed]

Given an Exponentially Distributed Random Variable $X\sim \exp(1)$, I need to find $\mathbb{E}[P_v]$ in Mathematica, where $P_v$ is given as: ...
0
votes
0answers
37 views

When I insert an if block into the ScheduledTask, I'm entering the password and the program is closing

I'm new in Mathematica. So I'm unable to settle a matter. When I insert an if block into the ScheduledTask, I'm entering the password and the program is closing. What is my mistake? Can you help me ...
1
vote
2answers
154 views

Add condition for not plotting in some cases

I have the following function. Now I want to add condition to not plot when the function is ComplexInfinity, Indeterminate, or <...
2
votes
2answers
130 views

Checking for discontinuities

There was an older post about checking the continuity of a function but the routines in the reply don't seem to work for my function. Hence the new post. If I have a function ...
2
votes
1answer
68 views

Need help with using nested If expressions in NDSolve

Questions regarding the use of nested For-loops have been posted a few times on StackExchange. However, I think that the solutions to those questions are not really applicable to what I am trying to ...
1
vote
0answers
84 views

"If" not working when solving piecewise differential equation

This is a part 2 to my previous question: Solving Piecewise Differential Equation I am embarking on a physics project and this is the simulation that I would like to do. More information is included ...
2
votes
1answer
127 views

Solving Piecewise Differential Equation

I am trying to simulate something using differential equations. However, the equations are piecewise. Here is my code: ...
4
votes
4answers
144 views

Find the value fluctuating in lists

Suppose that I have the following lists of entries, ...
1
vote
1answer
54 views

If statement doesn't work properly [closed]

As the image shows, If doesn't return "Fail" if the condition didn't succeed, but works when conditions match. Why did that happen and how can I fix it? ...
2
votes
3answers
73 views

Rewrite ListPlot using Graphics while perserving point color?

I have a lot of data points, and I have noticed that plotting using Graphics is usually much quicker than plotting with ListPlot. The problem is I am trying to color the data points based off some ...
1
vote
1answer
38 views

Using For to generate a sequence

I want to find the smallest positive integer $k$ such that the finite list s[k*m] contains no odd numbers, for $m=1,2 \dots$. Unfortunately ...
0
votes
1answer
76 views

Allowing choice between If statements in user-friendly way

Is there a user-friendly way to get a Mathematica notebook to choose between If statements according to the value of a variable? I would like the user to be able to ...
0
votes
0answers
26 views

If statement in dynamic cluster query

I use a High-Performance Cluster for some of my work. I can dynamically see the state of the work but I couldn't use the If statement in the cluster query. I want to hear a sound when my work finishes....
2
votes
2answers
83 views

Use Mathematica to split a sequence according to other two sequences

I want to use Mathematica to solve the following problem: For example I have a sequence 101. I want to compare it with $1101$ and $0101$. The comparison has the following procedure: Check the first ...
2
votes
4answers
198 views

Usage of 'Less than' condition in Sum

I have following sum: $$ \sum_{\substack{n,j\\j<n}}^{3} x_nx_j$$. How can I give this $j<n$ condition in Sum?
3
votes
1answer
282 views

Break NDSolve when condition is "almost" constant

I'm trying the solve a differential equation using NDSolve, starting at x=0.001. I'd like the solver to stop when the function ...

1
2 3 4 5
9