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
268 views

solve recursion equation with condition

How can I find $f(x)$ in terms of $x$ in the following equation? $ -k\, x \,f(x) + k \, (x + 1)\, f(x + 1) - r \, f(x) + r\, f(x - 1) =0$ $r$ and $k$ are constants and $f(x)$ should satisfy: $\...
5
votes
1answer
955 views

Simplifying conditional expressions using assumptions does not work

I have a conditional expression f[x_] := x /; x ∈ Reals This works fine for normal numbers and symbols, e.g. ...
1
vote
2answers
485 views

Problems with Solve when constraining solutions to a range

I have the following code ...
1
vote
1answer
254 views

Compiling If statement

I'm tring to use Compile in the following code, but it gives me an error message that I don't understand: ...
0
votes
2answers
117 views

Simplify integration result with conditions

Let's say I have integral Integrate[1/(1 + (f^2/B^2)), {f, 0, Infinity}] The result is $$\text{ConditionalExpression}\left[\frac{\pi }{2 \sqrt{\frac{1}{B^2}}},\...
2
votes
1answer
213 views

Seeking simple function in interval

I am a bit rusty, and struggling to solve this problem. Looking for a simple, well behaved parametric function f[t], from [0,1] to [0,1] such that: f[0] = f0; f[1] = f1; f'[1] = ff1; where -1<= ...
3
votes
4answers
159 views

List Manipulation Via Conditionals

I'm trying to convert one list to another by applying a condition on the list's elements. But I can't figure out how to do this in mathematica's language. Python example below ...
0
votes
0answers
28 views

A question about conditional replacement [duplicate]

{g[x, y, z], h[x, y], f[]} /. (f_[t___] /; f != List) :> Plus[t] Why is the output of this expression ...
1
vote
1answer
154 views

Modifying a list of matrices with conditional statement

I have a list of around 100 matrices, that looks like this ...
8
votes
2answers
283 views

Weird behavior of conditions when using OptionsPattern and OptionValue

I'm trying to define a function that is evaluated differently depending on its options. This code ...
9
votes
2answers
269 views

using memoization with conditional statement

I would like some advice about the use of memoization in conjunction with conditional statements. Let me try to explain my problem: I am constructing a function depending on a number of parameters. ...
0
votes
2answers
120 views

Use conditional expression inside With

I want to assign a number to an internal variable, depending if a specific option has been given, but it seems to fail. Something like: ...
3
votes
1answer
102 views

How can I create a set (list) provide a kind of rule/algorithm?

Example: S = {r ∈ Q : r² < 2} Let S be the set of all rational numbers whose squares are less than 2. It follows that 1 ∈ S, 4/3 ∈ S, but 3/2 doesn't ∈ S because 9/4 ≥ 2. Thank you.
4
votes
1answer
316 views

How to use Assuming and If together?

I would like to compare variables t and u and print either Yes or ...
40
votes
6answers
5k views

2D random walk within a bounded area

I want to simulate a random walk in two dimensions within a bounded area, such as a square or a circle. I am thinking of using an If statement to define a boundary. ...
4
votes
5answers
1k views

Creating a conditional table

I'm trying to create a conditional table. Let's say I want to have such result: {1,2,3,4,5,0,0,0,0,0}. The idea is to create a table of n elements (10 in a given example), but when one element takes ...
1
vote
4answers
451 views

Minimum and maximum values under conditions

Let's create some sample data ...
0
votes
0answers
59 views

How to correctly use PatternTest (?) [duplicate]

This works fine: {3, -5, 2, 7, -6, 3} /. x_ /; x < 0 :> 0 (*{3, 0, 2, 7, 0, 3}*) and this works fine: ...
0
votes
2answers
74 views

Multiply value if it includes a period

I download data from an online source, now I have a problem: the source code doesn't allow to differ between values of 10 (which actually stands for 10) and 10.000 (which is 10'000, but Mathematica ...
5
votes
1answer
213 views

Multiple down-values with exactly the same lefthand side

I was working on an answer to this question, when I was sidetracked by what I bring up here. I wanted a function, which when given a string representing a binary number, would convert the string to a ...
8
votes
1answer
702 views

Switch inside Manipulate controls statement

I am using this code inside Manipulate: ...
3
votes
1answer
290 views

Why does pattern test not work in this case to restrict the function parameters?

I was looking at this Q&A about using pattern test (pattern_?test) vs pattern condition (pattern_/;cond) and came across ...
21
votes
3answers
1k views

Quick way to use conditioned patterns when defining multi-argument function?

I have a simple function that is supposed to only accept numeric values (i.e. complex/real numbers and constant symbols e.g. Pi, E). $$f(a,b,c)=a+b+c$$ Edit: I should have chosen a less simple ...
2
votes
1answer
210 views

Generate conditions seems to not work [closed]

I am trying to compute the following integral Integrate[E^(I*k*Omega*t), {t,0,T}, GenerateConditions->True] for which Mathematica returns ...
4
votes
4answers
701 views

Skip other If conditions

I'm trying to write a code to "random" move in a matrix but it can't go to a certain position if it has a certain value (in this case I'm using the number 2). How do I make it to skip all other If ...
5
votes
2answers
150 views

What is the syntax to conditionally suppress plotting in version 9?

Bug introduced in 9.0 and fixed in 9.0.1 In Mathematica 7 it is very easy to conditionally suppress plotting of individual lines using If: ...
1
vote
2answers
4k views

Evaluate conditional expression

I solved an integral and get a conditional expression as the result. The conditions are quite heavy but if I use Assumptions within my ...
0
votes
3answers
120 views

Half kth term if n is even and k=n/2?

I am trying to write a function which will perform the equation in the attached image. So far, I have: ...
0
votes
1answer
36 views

How to use more/less black textcolor in function of the value of numbers in a table?

A few weeks ago, I viewed in the Mathematica Documentation any page withmultiple examples using diferent styles dpending on the value of the number in position (i,j), but I can´t remember... and I can´...
1
vote
3answers
153 views

Initialize table in a Module but Break if criteria not met

I am initializing a table inside a function as follows: f[a1_, a2_, a3_] := Module[{RM = Table[a1+a2+a3+i1, {i1, 1, 10}]}, Plus@@RM] I am calling the function <...
7
votes
5answers
1k views

How can I name patterns in a Switch expression?

Suppose I have an expression and want to match it against successive patterns and return an expression corresponding to the first pattern that matched. In that case, I can use ...
1
vote
3answers
159 views

Where Statement

Is there a "parallel" way to perform these operations? Indices = {} For[i = 1, i <= Length[w], i++, If[w[[i]] < 0, AppendTo[Indices, i]]] Which gives a ...
0
votes
1answer
174 views

Resolve a conditional expression including Exists and ForAll

I don't know the Resolve function exactly, especially when involved with Exists and ForAll, ...
0
votes
2answers
338 views

Replace matrix with conditions

I want to replace the values of 1. in slot under the condition that the year and month in basevalue and ...
6
votes
2answers
866 views

Flow/graph-based programming in Mathematica?

Is it possible in Mathematica to write a program inside a graph? For example if you have a bunch of different If[] statements that you need to embed within one ...
2
votes
3answers
256 views

Join matrix based on conditions

Given the following matrix: ...
4
votes
2answers
254 views

Why Refine does not simplify Cos[2*Pi*FractionalPart[1/2*(i + j + k)]] to $(-1)^{i+j+k}$?

I am obtaining in Mathematica: Cos[2*Pi*FractionalPart[1/2*(i + j + k)]] We know that for $i, j, k$ being positive integers this expression after simplification ...
3
votes
1answer
259 views

Table doesn't replace inside conditionals (If, Which) [duplicate]

This: Table[If[cond, y], {y, 1, 3}] outputs this: {If[cond, y], If[cond, y], If[cond, y]} The ...
5
votes
2answers
309 views

How to “ReplaceAll” using a set of conditional expressions instead of a list of rules [closed]

Suppose that I have two linear functions f[x_] := f0 + f1 x g[x_] := g0 + g1 x and a (possibly rather complicated) set of conditional expressions, obtained ...
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 ...
1
vote
1answer
293 views

How to use ParametricPlot Wih Conditions (or similar)

I´m analizyng the game "Battle of the Buddies" similar to "Prisioner´s Dilenma" All works fine, BUT... I want to draw in red the point whose coordinates are less than the coords of a strategy. ...
0
votes
1answer
255 views

Start animation after choosing of initial values without Animate

I want to simply set some parameters with sliders and click a button to start animation. I know that I can manage this with Animate and Manipulate, but my animation is written like in this post, ...
0
votes
2answers
2k views

Conditional Table

I have following : SeedRandom[2] Table[Table[RandomInteger[100, {100, 10}][[r, s]] == x[r + s], {r, 1, 10}], {s,1,10}] How can I set condition inside Tables?Such ...
10
votes
4answers
13k views

How to remove ConditionalExpression from output

I need define the function with parameter so I could directly generate a power series expansion. The problem is that in some cases ConditionalExpression appears in output. Here is my code: ...
1
vote
1answer
878 views

How to define a function with different types of arguments by setting conditions on function's domain?

I need help in order to properly define a function of $4$ variables. Given that: ...
2
votes
2answers
271 views

Conditioned Probability Task

I have this task with two questions I would like to compute in Mathematica. Suppose a pair of random variables $(X, Y)$ has a equal distribution on the following 7 points: $\begin{matrix} &...
10
votes
5answers
819 views

ListPlot under conditions

I have a data file containing several columns and thousands lines of data. Below I present a small portion of it, in order to express my issue: ...
4
votes
2answers
376 views

Compile error from If but not from Piecewise

Consider this: point={1.,2.}; f1 = Compile[{{t, _Real}}, Evaluate[Block[{a, b}, {a, b} = point; If[t > 0., a*b*Sin[t], 0.]]]]; f1[2.] CompiledFunction::...
0
votes
2answers
115 views

Implementation of a condition in a Function

I have defined that stoptime {5, 2, 10, 2, 1, 11, 11, 1, 5, 11} and have the following function pvcosts = (-5/1.05^#) &[stoptime] Now I want that everytime "stoptime" is 11, the function gets ...
4
votes
2answers
517 views

Extracting data from a table under conditions

I have a very large table with two columns. Let's say the name of first column is E and the name of the second is P. How can I get the E values when P = 0.

1
4 5 6
7
8