Questions about programming or mathematical constructs that enable verification, selection, or branching behavior when one or more criteria are determined to be True.

learn more… | top users | synonyms

0
votes
1answer
41 views
0
votes
0answers
53 views
2
votes
3answers
119 views

Join nested lists based on first and last elements within each list

I have a nested list like this: test1 = {{1, 3}, {1, 4}, {1, 7}, {2, 1}, {3, 5}, {4, 1}, {5, 2}, {6, 1}, {7, 6}} I want to join the lists together depending on ...
2
votes
1answer
103 views

How to use Compile to generate an $n\times n$ array using $n$ vectors

Let's consider the following: ...
0
votes
1answer
50 views

If statement for evaluating small values

I have a simple calculation which I am trying to use if condition to evaluate summation of some values, here's a code; ...
3
votes
2answers
61 views

An conditional Sum of elements in Array [duplicate]

Consider we have: list = {{2, 3}, {3, 30}, {3, 2}, {4, 53}} and we want to compare the first elements and sum the second elements if first elements are similar ...
3
votes
1answer
75 views

How do I color Riemann integral rectangles using conditionals?

I'm builind a function to visualize the Riemann Integration process to any function using rectangles. Everything is fine, except that I need the color of the rectangles to change if they're under the ...
1
vote
1answer
70 views

Multiple lines in an If statement [closed]

What I am wondering is how do you perform multiple lines when using the If statement. I know the following is not proper Mathematica code, but how would I do this in Mathematica? ...
0
votes
1answer
85 views

FullSimplify not giving me a physically useful answer for Mott scattering

I am using Mathematica to find the cross-section for Mott scattering over an extended target. I evaluated ...
3
votes
2answers
69 views

Faster use of Condition for a large array (see the example)

Here is the example/problem. I have a array of $n$ random number. n = 2000; p = RandomReal[{0, 9}, n]; I have to create a $n\times n$ sparse matrix with ...
4
votes
1answer
99 views

Query Dataset to check if row contains any from a set of values

For a given keyless dataset, I can query to return the rows whose columns contain a specific value. For example: ...
4
votes
2answers
96 views

How to conditionally combine a RegionPlot3D with a ContourPlot3D inside a Manipulate?

I know how to combine a RegionPlot3D and a ContourPlot3D, which I did (see below for details on the code I'm referring to) with ...
2
votes
1answer
67 views

Applying Switch and Which to mixed-Key Association lists

Given an Association list w/ a common Key but also some distinct ones: ...
-2
votes
3answers
65 views

Two unrelated questions: 1. Output of Series[] for function, 2. Output conditional answers as if not conditional [closed]

As mentioned in the title, I have two questions. 1. I have code that looks similar to: ...
1
vote
1answer
155 views

Solution of a system of differential equations with a correction factor varying over time

Dear Mathematica users, I am trying to solve a system of equations of first order and time depedent. The system has 5 equations, one for every variable which varies over time. At the moment I am ...
0
votes
1answer
164 views

Set conditions at a permutation

I need to find all permutations of 3 elements from {a,b,c,d,e} with this condition: These must include element d maximum once, ...
0
votes
1answer
283 views

Add assumptions to Solve command

I want Mathematica to solve the following by assuming the part within the Log function, which is ...
0
votes
1answer
72 views

How to properly use conditionals inside NDSolve

Currently I am working with Mathematica to learn the program, and I'm confused what exactly is wrong with this code. ...
1
vote
1answer
99 views

Solving equations bounded by a region

Straight to the point I have a function ...
2
votes
1answer
57 views

Is there a shorthand for Optional with Condition?

I have a recursive function that does some work to an object for a repeatedamount of times. ...
2
votes
2answers
96 views

RSolve with conditional equation

I have the following conditional equation: $f(n) = 1+2 f(n/2)$ when n is even $f(n) = 1+f((n-1)/2)+f((n+1)/2)$ when n is odd I want to represent this as a conditional equation to be used in ...
2
votes
1answer
77 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 ...
1
vote
1answer
58 views

Replacing Logic operator List and generate combination of variables

so I'm trying to do the following starting from a list of inequalities: ...
1
vote
2answers
81 views

Conditional Convolution

I was hoping to incorporate an If function into a Convolve operation, as in ...
1
vote
2answers
144 views

How to select elements from a list by condition?

Considering I have a list: F = {f1, f2, f3, f4} I want to perform exponent on the list F = Power[#, 2]& /@ F Now I ...
0
votes
0answers
34 views

Doing a repeated calculation on unique chunks of data based on a value in a column

First post ever on a forum, please bear with me if I don't get it right the first time :) I'm making a script for someone that imports a data file, generates some histograms, tables, and outputs them ...
0
votes
0answers
50 views

Evaluating an integral

Here is the input: Integrate[E^(2 I*t)/(2*Pi*(E^(I*t) - z)), {t, 0, 2 Pi}] and here the output: ...
3
votes
3answers
165 views

Inefficient NIntegrate and Which

In version 10 a simple numerical integraton of piecewise function is highly inefficient: ...
1
vote
1answer
81 views

Minimize under constraint on an interval

I want find the minima of a (multivariable) function under a constraint which has to be fulfilled on a whole interval, let's say $$ \nabla f (\underline x) = 0 \ \\ \ c(\underline x,s)\geq0\ \forall ...
2
votes
1answer
101 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
144 views

Problems with Solve when constraining solutions to a range

I have the following code ...
1
vote
1answer
108 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
46 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 ...
2
votes
1answer
160 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<= ...
2
votes
4answers
124 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
22 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
92 views

Modifying a list of matrices with conditional statement

I have a list of around 100 matrices, that looks like this ...
6
votes
2answers
150 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 ...
8
votes
2answers
138 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
76 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: ...
1
vote
1answer
157 views

Counting number of trues in If condition inside a For loop [closed]

I want to count number of trues in an If condition inside a For loop of some 10k iterations. I will be happy if you suggest me some command.
3
votes
1answer
72 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.
27
votes
5answers
2k views

2D random walk within a bounded area

I want to simulate a random walk on two dimension in a bounded area such as a square or circle. I am thinking of using If statement to define a boundary. Is there a ...
3
votes
5answers
308 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
170 views

Minimum and maximum values under conditions

Let's create some sample data ...
0
votes
0answers
42 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
50 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 ...
4
votes
1answer
147 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 ...
6
votes
1answer
222 views

Switch inside Manipulate controls statement

I am using this code inside Manipulate: ...
3
votes
1answer
131 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 ...