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 (1)

0
votes
1answer
34 views

Solving a polynomial where variables are constrained to take only some values

I want to find out which combinations of 1's and 0's would make this kind of equation be null: ...
0
votes
0answers
28 views

Set more constrains on a function in Do loop with If condition [on hold]

This post is an extension of the post: Do loop with If condition The answer of @JasonB worked fine with me. that to use Reap ...
0
votes
3answers
89 views

Do loop with If condition

I have the following formulas: 1- A cross section: sigma[beta_,alpha_,Y4_] := c^2/(256*Pi) * (1/2) ( Ytt[beta,alpha,Y4]/ m ) * Abs [A] )^2 Where c is a strong ...
4
votes
1answer
74 views

How to compile when function contains Condition?

I use the following triangular recursive algorithm to compute $\{N_{i-p,p},\cdots,N_{i-1,p},N_{i,p}\}$ here, ...
0
votes
2answers
38 views

Conditions on a product

I want to impose specific conditions on a product I am trying to take. I found this previous question asked here but when I use this I get zero. My expression is $$ ...
5
votes
4answers
449 views

How to simplify block of multiple repetitive If statements?

I'm building a boardgame...game in Mathematica. I have the board state represented as a matrix. It's a two player game, and each player (let's call them A & B) only has one type of piece or ...
2
votes
1answer
70 views

Inconsistent Integrate behavior?

Evaluating the following integral with Mathematica Integrate[q0/(-1 + q0^2), {q0, 0, A}] gives a conditional expression ...
4
votes
1answer
82 views

double sum with condition

I was trying to compute the following sum: $$\phi(x,y)=\frac{1}{4\pi^2}\sum_{(n,m)\neq(0,0)}\frac{1}{n^2+m^2}\exp(i(nx+my))$$ where the range of indices is, say, $-10\leq n, \,m\leq 10$. But I don't ...
0
votes
0answers
24 views

Semi-infinite sheet and Spherical inversion

I'm trying to define a function that will give a semi-infinite sheet (i.e. a sheet which exists when z=0 and x>0 for all y). I've tried using ConditionalExpression and ForAll, but when plotted using ...
3
votes
2answers
79 views

Find most general 3-tensor under given constraint?

Consider A to be a general $2\times 2\times 2$ tensor: A = Table[ a[i,j,k], {i, 1, 2}, {j, 1, 2}, {k, 1, 2}]; pictorially one ...
0
votes
1answer
75 views

Conditional function plot in Manipulate

I'm looking into the stability of solution of a set of chemical rate equations. There is a set of rate constants {$k_i$} I which to manipulate, and I want to find the stable solutions where ...
0
votes
1answer
53 views

Checkbox in manipulate not properly working

This question is related to another question of mine : How can I add a checkbox to a Manipulate expression?, but I'm still unable to make the checkbox to work properly. Here's a MWE code, from my ...
1
vote
1answer
36 views

This input is incomplete [closed]

I'm sorry if this is a totally simple question, but I'm new to Mathematica, and I've just spent 30mins looking through the documentation, but I can't seem to figure out why this code won't work: ...
1
vote
1answer
87 views

Solving trigonometric functions in Mathematica

I am new to Mathematica language and recently I had the need to solve the following equations with two variables, A and B: ...
5
votes
1answer
81 views

An unexpected match when using Condition, Optional and passing a Sequence

Mathematica is behaving in an expected way when passing a parameter with an Optional and a Sequence. Here is an example: ...
12
votes
3answers
353 views

Double Sum Involving Condition

I would like to compute the dimensions of some small free nilpotent Lie algebras. However, I am totally new to this and I could not figure out how to write the double sum which gives the dimension of ...
3
votes
1answer
93 views

Eliminating elements from sublists under a global condition

Consider the following list of 4215 sublists (note that the file as displayed at github is truncated, but there is a link to the full version). Each of the ...
0
votes
0answers
24 views
1
vote
1answer
61 views

Conditional probability syntax [closed]

What syntax do I use to compute this in Mathematica? Game of Yahtzee: 1. Suppose you get three 5’s on the first roll. What is the probability of rolling the other two dice and completing the Yahtzee ...
3
votes
2answers
76 views

Except[] with levelspec

I am trying to determine all the variables used in list. For This I use: DeleteDuplicates[Cases[l1,_Symbol,-1]] This is great except that ...
15
votes
3answers
479 views

Generating Tuples with restrictions

I am interested in a certain subset of all tuples. Generating all with Tuples and then filtering is wasteful, and will "blow up" very quickly. For a concrete ...
0
votes
1answer
57 views

If Statement in function does not evaluate

I've written a function that should try to simulate a "triangle-wave-signal", given a few parameters. It looks like this: ...
1
vote
1answer
91 views

Manipulating Some Lists in Compile

Consider a list of lists, such as: Z={{1,4,3},{2,1,3},{3,1,4}} Z is an $n \times n$ matrix (here $3 \times 3$) which ...
3
votes
3answers
79 views

How-to select an entry from a list of pairs that meets a condition depending the 2nd element of each pair

Processed data structure data = Transpose[{RandomInteger[{1, 20}, 100], RandomReal[{10^-8, 10^-1}, 100]}] You can download the actual raw data structure here. ...
1
vote
0answers
50 views

recursion and if-statements

So im 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 statements work in mathematica and if ...
0
votes
2answers
170 views

Using 0 < x < 10 as a condition in an equation

How do I write 0 < x < 10 on the right side in the equation. If #1 + #2 is bigger than 0 and smaller than 10. And is it possible to require -10 < x < 10 with the additional condition x != ...
0
votes
2answers
70 views

If Which Piecewise-defined function [closed]

How would I write a function using If and/or Which command for following Piecewise-defined function then plot the function ...
5
votes
0answers
95 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 ...
0
votes
1answer
51 views

If/Then Statement Evaluation [closed]

Really rudimentary question here...why is the following if/then statement always evaluating both "True" and "False" expressions and updating my CurCost and Temp variable values? ...
0
votes
0answers
40 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. ...
0
votes
1answer
49 views

if-conditional tracing a half-sphere [closed]

I have a 2D discrete plane (x,y) and I would like to assign an amplitude to each point in the plane. Each dimension runs from -1 to 1. Say I want to assign an ...
2
votes
1answer
62 views

Change some elements at the second level of a list based on some conditions

I need to change some elements at the second level of a list based on some conditions. I have the following list of objects of the same type: ...
1
vote
1answer
149 views

Fall through multiple cases in switch to execute same function

In C++ / C#, one can fall through multiple cases to execute one function instead of calling that function after each case. For example, ...
10
votes
1answer
238 views

Question about Rules and Pattern (The operator patt/;test)

Maybe this question is so trivial but it has confused me. I'm studying the What the @#%^&*?! do all those funny signs mean? and in the Rules and patterns under ...
1
vote
1answer
60 views

How to make Which not connect its parts? [closed]

I've noticed that when "Mod" and "Which" are used to the same effect, they plot to slightly different results. Take the following example: ...
1
vote
1answer
52 views

Triangular inequality condition

I have to calculate the following table Table[ ThreeJSymbol[{j1, 0}, {j2, 0}, {j3, 0}], {j1, 1, j1max}, {j2, 1, j2max}, {j3, 1, j3max} ]; in such a way that ...
8
votes
1answer
157 views

Why does pattern test work only with pure functions?

Why is it that pattern test works only with pure functions? Cases[Range[0, 70], _?(Divisible[#, 7] &)] Cases[Range[0, 70], x_?(Divisible[x, 7])] I ...
1
vote
2answers
61 views

Creating a Table with a list of If statements given in a certain order

I am trying to create a conditional Table with If statements, where I move to the next condition only if the first one is satisfied, otherwise I "Break[]" and move to the next element of the table. ...
0
votes
1answer
104 views
2
votes
3answers
148 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 ...
3
votes
1answer
130 views

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

Let's consider the following: ...
0
votes
1answer
54 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
83 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
134 views

How do I color Riemann integral rectangles using conditionals?

I'm building a function to visualize the Riemann integration process for any function using rectangles. Everything is fine, except that I need the color of the rectangles to change if they're under ...
2
votes
1answer
2k 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
96 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
84 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
141 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: ...