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
2 answers
241 views

Nested If question

Using the following code, I got the first two piecewise equations right but the third one returns -99. ...
Richard's user avatar
  • 49
5 votes
2 answers
174 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 ...
Axha's user avatar
  • 83
3 votes
2 answers
139 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 ...
Марина Marina S's user avatar
1 vote
1 answer
105 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: ...
rt1101's user avatar
  • 33
1 vote
1 answer
98 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 ...
user15723's user avatar
7 votes
5 answers
503 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: ...
user26718's user avatar
  • 366
2 votes
2 answers
195 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. ...
Banalaude's user avatar
  • 107
0 votes
1 answer
234 views

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

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 ...
Banalaude's user avatar
  • 107
1 vote
2 answers
278 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 ...
lesobrod's user avatar
  • 1,667
0 votes
1 answer
104 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\...
user1620696's user avatar
3 votes
2 answers
297 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'...
book_kees's user avatar
  • 255
1 vote
1 answer
182 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 ...
user57616's user avatar
2 votes
1 answer
414 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? ...
emnha's user avatar
  • 2,111
2 votes
1 answer
64 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 ...
mathfanatic33's user avatar
0 votes
1 answer
67 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}] ...
Pengfei's user avatar
  • 105
1 vote
2 answers
64 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 ...
ExpressionCoder's user avatar
0 votes
1 answer
63 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 ...
ghost's user avatar
  • 381
1 vote
1 answer
42 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. ...
Daniel's user avatar
  • 53
0 votes
2 answers
52 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 ...
Bob's user avatar
  • 47
3 votes
2 answers
739 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 ...
Bob's user avatar
  • 47
1 vote
0 answers
305 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 ...
A Q's user avatar
  • 161
2 votes
0 answers
36 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 ...
Tania Mata Aguayo's user avatar
5 votes
5 answers
214 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 ...
user avatar
0 votes
2 answers
60 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 ...
user avatar
-1 votes
2 answers
534 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 ...
Gabi23's user avatar
  • 295
1 vote
0 answers
81 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 ...
Caden Lin's user avatar
1 vote
2 answers
68 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 ...
geom's user avatar
  • 668
0 votes
0 answers
47 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 ...
seher's user avatar
  • 31
4 votes
1 answer
135 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 ...
jbl's user avatar
  • 347
2 votes
1 answer
75 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 ...
bob the legend's user avatar
2 votes
2 answers
351 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 ...
123infinity's user avatar
1 vote
2 answers
119 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: ...
SJa's user avatar
  • 113
1 vote
2 answers
180 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 <...
emnha's user avatar
  • 2,111
1 vote
0 answers
92 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 ...
bob the legend's user avatar
2 votes
1 answer
218 views

Solving Piecewise Differential Equation

I am trying to simulate something using differential equations. However, the equations are piecewise. Here is my code: ...
bob the legend's user avatar
1 vote
1 answer
369 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? ...
David's user avatar
  • 93
1 vote
1 answer
47 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 ...
Descartes Before the Horse's user avatar
0 votes
1 answer
87 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 ...
user avatar
0 votes
0 answers
44 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....
mrtydn's user avatar
  • 123
2 votes
2 answers
119 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 ...
JacobsonRadical's user avatar
3 votes
4 answers
410 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?
Arghya Datta's user avatar
-1 votes
2 answers
204 views

How to check if solution to NSolve exists?

I'm trying to created a table where the entries are values of x, either given by x/.NSolve[...][[1]] or a fixed value x0 if there is no numerical solution. Is there a way to find the truth value for ...
John Smith's user avatar
1 vote
3 answers
319 views

NIntegrate with a function defined with conditions

Good afternoon, I am trying to integrate a function that is defined with a conditional. The simplified code is the following: ...
TsuKi's user avatar
  • 11
0 votes
0 answers
98 views

How do I extract the minima from a list of NMinimize outputs in a smart way?

I am trying to find the absolute minimum of a potential surface on the x-y plane as a function of a third parameter p which changes the shape of this surface. In other words: at p=1, I want the ...
Al Waurora's user avatar
0 votes
4 answers
88 views

Only Reals Rules

I have a huge array of rules with many variables, such as ...
Hegel19's user avatar
  • 31
4 votes
2 answers
299 views

How to find random values of variable satisfying multiple conditions?

I have multiple conditions to be satisfied ...
Epsilon's user avatar
  • 1,122
0 votes
1 answer
49 views

Seamless ContourPlot for a conditional function

When I try to create a ContourPlot of a continuous conditional function, Mathematica leaves a "seam" in between the two regions demarcated by the conditional. How do I fill this seam? ...
Corvus's user avatar
  • 407
0 votes
0 answers
251 views

Constant inside If condition

I hope you are doing well. I am currently writing some code in which I have an If statement where I will be dividing two expressions and checking to see if the quotient comes out to be a constant ...
Carlos Villeda's user avatar
1 vote
1 answer
63 views

Obtain fairly sampled data set subject to a condition?

I need to obtain a random distribution of some parameters {t1,t2,t3} subject to a set of conditions. For example, ...
naomig's user avatar
  • 343
1 vote
1 answer
59 views

Can't make this "If" clause work

I am writing a code that creates a population with a probability to die for each citizen. They all start with some age, and after each application of the function, it either kills a person or adds +1 ...
David Fígols Olaria's user avatar

1 2
3
4 5
11