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.

51 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
15
votes
0answers
148 views

Reduce[Sin[x]==0,x] splitting odd and even multiples of Pi

as from Title, I'm wondering why Mathematica does not automatically give a single, simple solution for the problem Reduce[Sin[x] == 0, x] for which I obtain the ...
7
votes
0answers
258 views

Is it possible to do probabilistic programming by variable elimination with plain Mathematica 10 or later?

Using frameworks like Figaro it is possible to do probabilistic programming by variable elimination to build a probabilistic model and then run inferences against it in a very intuitive way. Example: ...
6
votes
0answers
893 views

When are `If`, `Piecewise`, `Switch`, and `Which` interchangeable and when are they not?

Experimenting with joint dependent distributions via the TransformedDistribution function, I used the following to derive a distribution where the second variate is ...
5
votes
0answers
75 views

Why does Mathematica recognize the conditional convergence of some integrals but not others?

Consider the following two polynomials: f1[t_] := t^3 - 1 f2[t_] := t^3 + 3t - 1 Both of these polynomials have a single real root: $f_1(t)$ at $t = 1$, and $...
5
votes
0answers
165 views

Find regions in which the roots of a third degree polynomial are real

I have to find the roots of a third degree polynomial in $\phi$ that depends from 3 parameters, namely $t,s,w\in \mathbb R$. In order to do that I've used the command ...
3
votes
1answer
133 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'[...
3
votes
0answers
203 views

Define (conditional) substitution rule for sum/difference of radicals

I want to tell Mathematica to simplify some expressions applying the following substitutions, conditioned on the fact that $a\geq 0,b \geq 0, a^2-b\geq0 $ $$ \sqrt{a+\sqrt{a^2-b}} \pm \sqrt{a-\sqrt{a^...
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 ...
2
votes
0answers
126 views

Is Mathematica computing the conditional expectation correctly?

Given a simple case of say 2 independent trials each with probability of success 1/3. Consider a random variable that is gives the 3 times the total successes. We can define this random variable in ...
2
votes
0answers
69 views
2
votes
0answers
132 views

How to set up Switch with variable number of conditionals?

I would like to use a Switch command with IntegerPartitions[n] of terms with n ranging from 3 to 12 and n chosen at run time. I have: ...
1
vote
0answers
80 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 ...
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 ...
1
vote
0answers
29 views

How to avoid delayed evaluation in Condition used in a function definition

I would like to define a function (below, f) that evaluates only under the condition that some expression is True. The condition is to be specified now, and I don't want it to change for the purposes ...
1
vote
0answers
34 views

Are the conditions in ConditionalExpression necessary or sufficient?

I computed a limit and obtained it in the form of a ConditionalExpression (see below). Substituting the variables with numerical values in the resulting formula ...
1
vote
0answers
28 views

Finding the positions of minima for a function with algebraic constants

I have a function of several variables: inverse[Qx_, Qy_]:= T - 2 J + 4 J1 Cos[(Qx + Qy)/2 a] Cos[(Qx - Qy)/2 a] - 2 J2 Cos[(Qx - Qy) a] + 2 J3 Cos[(Qx + Qy) a] ...
1
vote
0answers
194 views

Is there a way to find the Region of Convergence along with the Laplace Transform?

This is what I've tried so far. Is the inequality of the conditional expression the Region of Convergence? Why doesn't LaplaceTransform Generate conditions here? ...
1
vote
0answers
334 views

Ternary diagram

I'd like to make a RegionPlot on a ternary diagram, meaning in a triangle where the axis are $x,y,z$, which are related by $x+y+z=1$. The RegionPlot would have as a condition $x^2+y^2<1$ for ...
1
vote
0answers
62 views

Determine n related elements with least sum from a matrix?

Consider defining a matrix such as mat: ...
1
vote
0answers
308 views

How to solve a system of six coupled PDE with step function

i'm trying to solve a coupled system of six partial differential equations with NDSolve. The system is as follows but i don't have idea how to use the conditionals. Here $H_{\sigma}$ is a continuous ...
1
vote
0answers
104 views

How to check the positivity of a function depending on many variables?

Suppose we have some complicated function $f(x,y,z,v,u,w)$ with $\{x,y,z,v,u,w\} \in G$; precisely, each variable excepting one is defined in the sub-domain depending on other variables: $w \in G_{1}(...
1
vote
0answers
641 views

How can I perform a scan and plot of a parameter space?

I have three functions dependent on three independent variables, like so: H[u,m,s] S[u,m,s] SH[u,m,s] However, I don't actually know these functions--they are ...
1
vote
0answers
101 views

Using Which with a list

In a While loop I have: Y1 = Table[A1[[k]], {k, 1, j}]; c1 = Last[Flatten[Position[Y1, 1]]]; a1p[j] = Which[c1 == j, 0, c1 < j, t[j] - t[c1], True, t[j]]; I ...
1
vote
0answers
219 views

What is the symbol FE`None for?

I have run into the symbol FE`None multiple times. What is this symbol, and what is it designed to indicate? All I could find is that FE indicates the front-end, but it's unfortunately a very ...
1
vote
0answers
185 views

Recursion and If-statements

So I'm trying to write a recursion module in Mathematica (specifically for strassen multiplication but this doesn't matter). My issue is I don't really know how If ...
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
37 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 ...
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 ...
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....
0
votes
0answers
46 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
0answers
58 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 ...
0
votes
0answers
82 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
48 views

Problems with Which statement doesn't evaluate

...
0
votes
0answers
54 views

How do I correctly set up an "If" statement?

I have the following list of variables: z=1; a={{A,B,C,D},{A,A,E,W},{B,B,B,B},{S,R,B,T,D},{M,M,M,M}} What I'm trying to do is set up a statement that reads ...
0
votes
0answers
48 views

Integrals with conditional result

I am trying to get Mathematica to evaluate integrals such as the well-known Fourier orthogonality relations $\int_0^L \sin \frac{2 m \pi x}{L} \sin\frac{2 n \pi x}{L}\,\mathrm{d}x=\begin{cases}0& ...
0
votes
0answers
78 views

3D-plot of a maximization of a definite integral

I'm applying the answer (If method) suggested by 'ThatGravityGuy' in this post in a more complicated case. Consider my objective function (pardon its formidable ...
0
votes
0answers
62 views

solving inside for loop and sorting x which are less than 3 and greater than -3 from the list

I give a simple function code here... Clear[a, x, t]; s = ParametricNDSolve[{x'[t] + a*x[t] == 0, x[0]==1}, x, {t, 0, 100}, {a}] y = x[1] /. s y[5] /. s I ...
0
votes
0answers
66 views

How can I better formulate a conditional statement?

To solve optimization problems I have seen this: Is there a more elegant way to do this with alternative conditional expressions? Is there something equivelant to ...
0
votes
0answers
47 views

How to use === with condition?

I have two expressions, and they are same when k is positive and x is non-zero real number. Below code gives me ...
0
votes
0answers
61 views

How can I select the true expansion?

I have a series expansion which gives two results. Series[-(1/ Sqrt[-1 + x + x z1^2 \[Chi]^2]) , {x, 0, 1}] /. y -> x I want only the series which is true. ...
0
votes
0answers
53 views

How to carry out a different function based on weighted probabilities

I am looking to carry out a function based on weighted probabilities I have looked at using If[] and random numbers but ...
0
votes
0answers
560 views

Can For loop be used with multiple conditions?

I am wondering if For could be used with multiple conditions (tests). For the simple example ...
0
votes
0answers
35 views

Attached program is giving an output, even if conditions are not met

...
0
votes
0answers
83 views

The conditions used in Sum or ParallelSum: Calling a function/variable

For some reason, I encounter a problem when doing the Sum and ParallelSum (or doing the Do or ParallelDo, e.g. such as the issue here), I figured that the potential cause of the problem can be ...
0
votes
0answers
79 views

How to put conditional for a iterator?

I have the next code: f = Table[ mtxt[[p[[i, j]] - wi ;; p[[i, j]] + we]], {i, n}, {j, m}] I want that wi and we have different values depend of the j value. For ...
0
votes
0answers
83 views

Solving a system of equations with conditional functions

With your help i am getting closer to the solution of my problem. I know that the code is long but most of it is boring definition. At the beginning i am just defining function, which works at the ...
0
votes
0answers
442 views

Use If condition with ListPlot

Here is my code to use If condition with PLot: ...
0
votes
0answers
119 views

Impose a condition on a function in a loop

I am trying to calculate something in the following code and I need to omit the final values which are going to be infinity.obviously I want to extract the answers of H2[s] which are zero. ...