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
1answer
38 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
95 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
42 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
39 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
49 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
52 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
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. ...
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 ...
3
votes
2answers
118 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
61 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
23 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
175 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
51 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
61 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
45 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 ...
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 ...
0
votes
0answers
36 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 ...
4
votes
1answer
116 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 ...
2
votes
1answer
65 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 ...
2
votes
2answers
119 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 ...
1
vote
2answers
107 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: ...
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 <...
1
vote
0answers
82 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
124 views

Solving Piecewise Differential Equation

I am trying to simulate something using differential equations. However, the equations are piecewise. Here is my code: ...
1
vote
1answer
50 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? ...
1
vote
1answer
37 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
73 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
82 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
196 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?
-1
votes
1answer
41 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 ...
0
votes
3answers
84 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: ...
0
votes
0answers
37 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 ...
0
votes
4answers
64 views

Only Reals Rules

I have a huge array of rules with many variables, such as ...
4
votes
2answers
143 views

How to find random values of variable satisfying multiple conditions?

I have multiple conditions to be satisfied ...
0
votes
1answer
41 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? ...
0
votes
0answers
51 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 ...
1
vote
1answer
58 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, ...
1
vote
1answer
56 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 ...
3
votes
1answer
75 views

How should I define the Cayley transform?

I am a beginner to Mathematica. I am trying to define a function which would evalute the Cayley matrix transform, namely taking a matrix $M$ such that $I + M$ is invertible to $(I-M)(I+M)^{-1}$. I ...
1
vote
3answers
191 views

Evaluation order of `If` and `Sum`

Where in the manual are the specifications for the order of evaluation that produce the following result? Sum[If[OddQ[n], 1, 0]/n!, {n, 0, ∞}] (*0*) Addendum ...
2
votes
3answers
86 views

Multiple Calculations in a condition

I want to add and subtract 3 from a list. pos = {82,84} If[# > 3, (# - 3) && (# + 3)] & /@ pos the output I want: ...
0
votes
2answers
174 views

How to construct an IF statement within `Manipulate` with various stopping statements

Take the following data: ...
3
votes
1answer
46 views

Add a condition to the double summation

How can I add this condition Ei[i] + Ei[j] != 0 to the following summation? ...
1
vote
2answers
52 views

Swap two numbers - but only in a particular context

I have a list of terms such as {2*s[1,2]^2, 3*s[3,5]^4, ...} and I would like to have a replacement that swaps $2 \leftrightarrow 4, 3 \leftrightarrow 1$, but only ...
1
vote
0answers
40 views

How to generate conditionals programmatically? [closed]

I need to generate conditionals (||, &&, etc) from a list conditionList that I don't know beforehand how many/which elements will it contain. For simplicity,...
0
votes
0answers
73 views

Using an if statement to assign a value to a variable

New Mathematica user here. I'm using some code from a colleague and editing it to give me more specific results in finding the zeros of a complex polynomial. I am attempting to find a way to assign a ...
0
votes
0answers
46 views

Problems with Which statement doesn't evaluate

...
1
vote
1answer
48 views

Cannot get conditional Take[…] from List[…] to work inside a user-defined function

Abstract I have a function eqsfromMatrix[...] that does exactly as it sounds. It returns a list of equations given matrix m for ...
4
votes
4answers
222 views

Dropping some row from a Table with If condition [closed]

I have to drop the rows of a table only when the element in the first coloumn of the row satisfies multiple condition. The table: ...

1
2 3 4 5
9