Tag Info

10

Clear["Global*"] air = {3, 1, 6}; water = {2, 4, 3}; road = {1, 0, 7}; root = {6, 1, 2}; clist = {"Belarus", "Georgia", "Armenia"}; legends = Row /@ Transpose[{{" ", " ", " ", " "}, ColorData["Pastel"] /@ Range[0, 1, 1/3], {" change in air", &...

10

I have used an L-System from The Algorithmic Beauty of Plants - I highly recommend it. There's a 2D L-System in the WFR ResourceFunction["LSystem"], but unfortunately not 3D yet, so I made one for this answer. This L-System is parametric so I'm using RegularExpression to extract the parameters in ( ... ) parentheses and update them during ...

8

Use the correct iterator for the job, in this case use While instead of Table: In:= Module[{i = 0, list = {}}, While[++i <= 10, If[i == 3, i += 2]; AppendTo[list, i] ]; list ] Out= {1, 2, 5, 6, 7, 8, 9, 10} If you don't like the performance penalty associated with AppendTo there are plenty of alternatives.

6

A custom DisplayFunction that adds legends and data table with columns aligned with group labels: ClearAll[displayF] displayF[lgnds_, tbl_, lbgrnd_: Automatic, tbgrnd_: Automatic, voffset_: 25, gap_:25] := Module[{volist = Accumulate[Prepend[gap] @ ConstantArray[voffset, Length @ tbl]], hoffset = 1.1 Max[Ceiling[Rasterize[Style[#, "Graphics"],...

6

There are few way. One could be to use MemberQ with an If list = {1.2, 1.6, 1.8, 1.9, 2, 2.22, 3.04, 1000}; x = 1.6; If[MemberQ[list, x], x^2, 0]

5

Try this: Table[If[i == 3, j := i + 2, j := i]; j, {i, 1, 10}] (* {1, 2, 5, 4, 5, 6, 7, 8, 9, 10} *) Have fun!

5

Edit: I misunderstood the question, but the technique remains. Don't try to redefine the iterator symbol, just use it as is. Table[If[3 < i < 5, Nothing, i], {i, 1, 10}] (* {1, 2, 3, 5, 6, 7, 8, 9, 10} *) In general, you should not think of symbols as being equivalent to the "variables" of other programming languages. If you really want ...

4

Try this: check[x_] := If[MemberQ[lst, x], x^2, 0] Let us test it: lst = {1.2, 1.6, 1.8, 1.9, 2, 2.22, 3.04, 1000}; check[1.9] (* 3.61 *) check[1.8] (* 3.24 *) check[1.7] (* 0 *) Done. Have fun!

4

There aren't many functions that create indeterminate-length lists. NestWhileList comes to mind. Sow/Reap, Append, Join etc. can be used with other iterators to create a list of an arbitrary length. FoldWhileList[f, givenlist,...] does not create a list longer than givenlist. Here's a way to rewrite Table in terms of NestWhileList that allows the iterator ...

3

Edit Another way is use Rationalize to the values k and A function[k_, A_, u1_, u2_] := (1 + Tanh[k (u1 - 2 A u2)])/2 - u1; results[k_, A_] := NSolve[function[Rationalize@k, Rationalize@A, u1, u2] == 0 && function[Rationalize@k, Rationalize@A, u2, u1] == 0 && 0 <= u1 <= 1 && 0 <= u2 <= 1, {u1, u2}] values = Range[...

3

Try Map (don't know why Table doesn't work) Map[results[0.2, #] &, { 2.2, 2.4, 0.1}] // Quiet (*{{{u1 -> 0.375147, u2 -> 0.375147}}, {{u1 -> 0.364816,u2 -> 0.364816}}, {{u1 -> 0.54336, u2 -> 0.54336}}}*) Edit I still do not understand why NSolve (numerical solver!) only evaluates with Rationalize! NMinimize solves without this ...

3

Edit ClearAll["Global*"] air = {3, 1, 6}; water = {2, 4, 3}; road = {1, 0, 7}; root = {6, 1, 2}; fig = BarChart[Transpose@{air, water}, ChartStyle -> {None, "Pastel"}, FrameLabel -> {None, Style["Percent Change", 13, Black, FontFamily -> "Helvetica"]}, PlotTheme -> "Business", ...

3

Here is an example using ParallelSubmit: f1[x_] = x; f2[x_] = x^2; f3[x_] = x^3; f4[x_] = x^4; WaitAll[{ ParallelSubmit[f1], ParallelSubmit[f2], ParallelSubmit[f3], ParallelSubmit[f4] }] (* {2, 4, 8, 16} *)

3

If you want to do in-place modification of A through a function call to a, then you have to tell a that you want to pass the matrix A by reference. You can do that by giving a the attribute HoldFirst (which in this context means call by reference for the first argument only). So your function could look like this: ClearAll[a]; SetAttributes[a, HoldFirst]; a[...

3

Firstly, define the matrices. Below I am doing $(5 \times 5)$ but the dimensions can easily be changed. n = 5; A = Table[RandomInteger[], {i, 1, n}, {j, 1, n}]; B = Table[b[i, j], {i, 1, n}, {j, 1, n}]; A // MatrixForm B // MatrixForm Then, you do the multiplication like so: A B // MatrixForm Comparing to the forms of the matrices A and B ,the result of ...

2

f = #^2 Unitize@Length@Cases[alist, #] & For testing: tList = RandomReal[{-10, 10}, {10}]~Join~alist~Join~ RandomInteger[{-10, 10}, {10}] f /@ tList {0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1.44, 2.56, 3.24, 3.61, 4, \ 4.9284, 9.2416, 1000000, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0}

2

You could use a Condition: Table[ i /.a_:>Nothing/;2<a<5 , {i, 1, 10}] {1,2,5,6,7,8,9,10} If somehow you need to define the iterators to skip prior to evaluation, or want to control this without rewriting the Table: ClearAll[n]; n=3; Table[ i /.a_:>Nothing/;n<=a<n+2 , {i, 1, 10}] {1,2,5,6,7,8,9,10}

2

I was pointed out in the comments, using Coefficient[] one can achieve the desired table as in the code below

2

ParallelMap[Construct[#, x] &, {f1, f2, f3, f4}] (* {f1[x], f2[x], f3[x], f4[x]} *)

1

You are nearly there. You need to infuse the range using Sequence like e.g.: Integrate[1, Sequence @@ range] Of course this example does not converge.

1

Maybe this is what you want. This does not use any SparseArrays because the resulting array is just not sparse enough for SparseArray providing any benefit. k = 6; A = ArrayReshape[ Join[ ConstantArray[a, Quotient[k^3, 4]], ConstantArray[b, Quotient[k^3, 4]], ConstantArray[c, Quotient[k^3, 4]], ConstantArray[d, Quotient[k^3, 4]] ][...

Only top voted, non community-wiki answers of a minimum length are eligible