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
0
votes
0answers
43 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 ...
3
votes
4answers
2k views

How to define conditional function with Mathematica?

How to define conditional function $f(x,y)$ with the following result. If $x=1$ and $y=0$ then $f=77$, if $x=0$ and $y=1$, then $f=66$, if $x$ and $y$ are all other integer values then $f=0$. How to ...
2
votes
2answers
89 views

Why does conditional NExpectation fail for a multivariate distribution?

To give an example for a multiparametric distribution let us take a binormal distribution: ...
2
votes
2answers
49 views

behavior of functions with parameters inside arguments

I don't understand this behavior: why does Limit[z/(z - a), z -> 0] give zero and not a condition depending on a, provided it ...
0
votes
2answers
38 views

Reduce: number of available solutions changes and I want to pick the lowest

I have an equation that has no analytical solution and can have multiple roots. I am focusing on Real roots that are in the (0,1) interval. For example: ...
1
vote
1answer
89 views

Cases with condition vs Select inside Manipulate

I tried to plot integer points that fall into a 2D region that's dynamically changed. So I resort to Cases and Select, but ...
2
votes
1answer
83 views

Conditional Programming

I need help creating a function that takes 5 integer inputs and does the following: If exactly 2 or 3 of the first four inputs are not divisible by the last input I want the output to read “...
0
votes
2answers
123 views

Problems with If condition when Pochhammer symbols are zero

There is a formula for the hypergeometric ($_2F_1$) that expresses it as a sum of Pochhammer symbols, times something that reads $$_2F_1(a,b,c;x) = \sum_{i=0}^{\infty} \frac{(a)_i (b)_i}{(c)_i} \frac{...
-1
votes
1answer
93 views

Using `If` condition to replace columns of a matrix

I have two matrices: ...
1
vote
2answers
1k views

Define a function with a condition

I defined a function u[y]. ...
3
votes
4answers
1k views

Using “If” statement to change a list values

I have a question that would be pretty trivial in almost any other language but is giving me a massive headache in Mathematica. I am trying to construct an If statement check on one variable that I ...
0
votes
0answers
406 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 ...
6
votes
2answers
3k views

How to restrict the domain of a function

I realize this question has been asked many times, but I am fairly new at Mathematica and the other answers are very complex, and certainly too complicated for this simple code I am trying to write. ...
0
votes
0answers
46 views

How to pass var to Select[(#colunm == value) &] construct [duplicate]

I'm using a construct (more complex in fact as the value_ should take a list) to select some entries from an association with criteria: ...
0
votes
2answers
161 views

A simple code for conditional double summation?

I wrote a code as follows ...
0
votes
1answer
145 views

PlotStyle based on If condition

So in the If[evecs==Re[evecs], I want to then change the colour in PlotStyle of the ...
3
votes
2answers
143 views

How can I get all the possible conditions for a second-order equation?

I have the following equation: Solve[a x^2 + b x + c == 0, x] I want to gain three cases for this equation. If delta be $b^2 -4ac$ For $delta>0$: $x =(-b + ...
2
votes
1answer
41 views

Logical operations with defined conditions

I'd like to know how to define logical conditions to manipulate them. For example, say I have a list list of pairs of numbers, and I want to Select those which ...
10
votes
2answers
796 views

Difference between Piecewise, Which, If?

I have the impression that these functions have different evaluation rules. I cannot produce a minimal example right now, but in general, what are the differences between these functions? That is, ...
2
votes
2answers
63 views

Vectortransformation inside Cases condition very slow

I have the following piece of code ...
3
votes
2answers
689 views

ContourPlot with certain contour values omitted

Suppose I want contour plot of $x^2-y^2$, for $x,y\in[0,1]$ (my actual function is more complicated). Over this interval, $x^2-y^2$ is sometimes positive and sometimes negative. Using ...
0
votes
1answer
94 views

Add more than one condition to my equation

I have the following code to solve for a bunch of n, m e U, but I need different conditions for n=0 and m=n, already explicit in my code, but I don't know how to make it work. I know I have to make it ...
0
votes
1answer
88 views
2
votes
2answers
97 views

How do I implement a condition on a plot in a Manipulate expression?

I want to implement a condition to affects the behavior of a plot made in a Manipulate expression. Suppose I have ...
0
votes
1answer
155 views

Map function using if statement [closed]

Here is what I tried (that doesn't work), reduced at minimum terms ...
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
232 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 ...
0
votes
0answers
35 views

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

...
6
votes
2answers
432 views

How to select points from a table that are within some region

there, I encountered this problem while coding: I generate a table in the r-z plane of cylindrical coordinates: ...
1
vote
2answers
53 views

Simplifying tests on a random set

I would like to simplify: ...
1
vote
1answer
146 views

Simplify nested If into a loop

I would like to simplify a set of tests (meant to be applied on a random set of parameters), written for now as nested If: ...
0
votes
1answer
113 views

Forming a 2D table with conditions with a function

I have a function which can be represented as a weighted sum of parameters f(m, n). Where m & n have values 1 - 10. ...
1
vote
1answer
43 views

Can I add different texts to these two pictures using the `If` function?

I use the code from an answer to get two pictures: ...
5
votes
2answers
276 views

There is no ConditionalExpression warning for an Indeterminate case in Integers

This expression yields Pi in the limit m -> n in the Complexes domain. But for ...
0
votes
0answers
76 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
1answer
59 views

How to change Boolean into a String, depending on the boolean?

I have this code (visualizing Simpson's paradox): ...
3
votes
2answers
119 views

curious simplification problem

Consider the following expression: If[x==x, 1, 2] This returns 1, as you might guess. However: If[x<x, 1, 2] Returns ...
2
votes
4answers
327 views

How to use Cases for nested list?

For example, we have a list ={1,2,3,4,5,6}, we can use Cases[list,x_/; 3<x<10] to pick up ...
0
votes
2answers
110 views

How do I use the existence of an array member as an 'If' condition?

I have an oddly shaped array (it is 100 by 100 by {1 or 3}, with the 1 or 3 being essentially random). I want to run a 'Do' loop on the first 2 dimensions of the array, but I only want to do the thing ...
1
vote
0answers
74 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}(...
2
votes
3answers
159 views

Finding the largest palindrome which is the product of two 2-digit numbers

My goal is to find the largest palindrome which is the product of two 2-digit numbers using the following program. I want the program to add each palindrome it finds, to the list H. I also want it to ...
4
votes
2answers
103 views

Condition syntax: “when equal to any of”

I am trying to write a condition clause for a certain expression. I need to pick out the following cases: Mod[x*y, 10] == 8, or Mod[x*y, 10] == 3, or Mod[x*y, 10] == 7. I need to repeat ...
1
vote
1answer
337 views

How to use If statement inside DynamicModule?

I believe I am missing an important piece of information. I am trying to execute a simple If statement inside a DynamicModule. The variable tested in the If statement is a Dynamic variable, in this ...
0
votes
1answer
110 views

Making ConditionalExpression as a Function to use

i have these functions: savA[k_, s_, a_] := s*a*k^0.5; savB[k_, s_, b_, c_] := s*b*k^(0.5) - c; depr[k_, n_, d_] := (n + d)*k; ...
1
vote
3answers
614 views

Find Array Elements That Meet a Condition

I have an array of 5 numbers (say m). I want the following operation m=[-1,-3,-2,-5,-4] For (j=1,j==5,j++) if ...
0
votes
1answer
98 views

Why this expression doesn't work?

I am trying to choose a function and then the parameters using Manipulate, but isn't working... ...
0
votes
1answer
57 views

Incorporating additional conditions on `FindInstance` or `Solve` for a cubic map

I have the cubic map: f[a_, x_] := (a - 1) x - a x^3 To determine the values of a for which this cubic map is bounded to the closed interval -1 and +1, I tried: <...
0
votes
2answers
139 views

Adding extra lines to the If[condition,t,f] command [duplicate]

I wish that the Mathematica documentation for the If command showed examples that have more than one statement for the t and f responses. All three of these work: No parentheses or braces: ...
2
votes
0answers
45 views

If and NDSolve Causing Issues [duplicate]

I have the code below, which simulates a particle of mass $m$ in a fourth order polynomial potential given an initial conditions $q_0,p_0$. That is to say, I am simulating Hamilton's equations using <...
0
votes
2answers
72 views

Iterating a function

I have a piecewise map of the form $M\left ( x \right )=\left\{\begin{matrix} 2x & x<0.5 \\ 2-2x& x>0.5 \end{matrix}\right.$ The domain is the closed interval from 0 to 1. I would ...

1 2 3
4
5
8