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.

43 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
13
votes
0answers
107 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
211 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
866 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
70 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
161 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
0answers
194 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
100 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
52 views
2
votes
0answers
100 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
29 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
26 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
254 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
60 views

Determine n related elements with least sum from a matrix?

Consider defining a matrix such as mat: ...
1
vote
0answers
226 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
69 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
523 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
209 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
174 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
0answers
29 views

How do I set a control in an “If” statement?

I have the following lines of code: ...
0
votes
0answers
41 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
20 views

Optimization of storages capacity

Consider a series of storages where different goods are added into daily. I would like to optimize the distribution of these goods between the storages in a way which takes into account some ...
0
votes
0answers
40 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
1answer
47 views

conditional statement in function

It seems the equality condition does not work as expected. ...
0
votes
0answers
11 views

Min of a set defined with conditions

I would like to define this parameter inside a function: $R = \min\left\lbrace i \in \left\lbrace 1,\cdots,n \right\rbrace \; : \; ((p+i)\mod n) \; \neq a_{j} \; \forall j \in \left\lbrace 1,\cdots,m ...
0
votes
0answers
44 views

Using If statement to evaluate lists

I have a list of x,y values and i am finding the distance between each point, So for 20 point in my file I have something like this, ...
0
votes
0answers
53 views
0
votes
0answers
54 views

Mathematica gives uncessary condition for integration of $(b - s)^\alpha(s - a)^\beta$

When I compute the integral of $(b - s)^\alpha(s - a)^\beta$ on $[a,b]$ by the following command: ...
0
votes
0answers
75 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
56 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
84 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? ...
0
votes
0answers
62 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
46 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
58 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
42 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
388 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
72 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
75 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
80 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
342 views

Use If condition with ListPlot

Here is my code to use If condition with PLot: ...
0
votes
0answers
110 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. ...
-1
votes
1answer
86 views

Using `If` condition to replace columns of a matrix

I have two matrices: ...