string manipulation – ToExpression applied to an element of an array fails

When I apply ToExpression to a symbol, a, everthing works fine in that the string value of the symbol is converted to an Integer.

a = "1";

(* String *)

(* 1 *)

(* Integer *)

However when I apply it to an element of an array it fails


a={{"name1", "‏‎11", "15", "AM"}, {"name2", "‏‎1", "31", "PM"}};

(* 1 *)

(* String *)

ToExpression(a((2, 2)))
(* 1 *)

ToExpression(a((2, 2))) // Head
(* Symbol *)

I discovered this when attempting something like:

ToExpression(a((2, 2))) + 12
(* 12 + 1 *)

I got the indicated answer rather than the Integer, 13.

list manipulation – Export data to file

I have a function f(x,y,z,i) that returns the solutions {x1,y1,z1} for each step “i”.
I would like to use a repeating command (such as Do(…)) to get the outputs of this function f saved in a file. More specifically, I thought using something like Do(f(x,y,z,i),{i,1,10,1}) combined with Save, but I do not know how to combine these two commands with the interation of “i”

list manipulation – How to construct a tree from a preorder traversal

The list

t1 = {1, 2, 3, 3, 4, 4, 3, 3, 4, 3, 3, 2, 3, 4, 2, 3, 2};

might be derived from a pre-order traversal of

tree1 = Tree[1, {Tree[2, {3, Tree[3, {4, 4}], 3, Tree[3, {4}], 3, 3}], 
  Tree[2, {Tree[3, {4}]}], Tree[2, {3}], 2}]

But how to take the original list, t1 here, and build the tree tree1 ?

What have I tried so far ? Nothing to any avail! Well, that’s not quite true, I have made some progress with a very procedural code to walk along the list and try to figure out the structure of the tree as each new element is read, but I have a dispiriting feeling that I have missed an obvious usage of some of the smarter functional programming functionality.

list manipulation – How to evaluate a function on all solutions given in output of a Reduce function

Say I have a Mathematica programme/function $f(z_,w_{} ) = mathrm{Reduce}(cdots)$ which outputs a list of solutions, which looks something like $$a = 1 && ((0leq b leq 1000 && -5 leq c leq 65)) $$
$$a = 2 && ((32leq b leq 860 && -4 leq c leq 36)) $$
and so on for all cases of $a$ (here $1 leq a leq 10$). Here $a,b,c$ are all integers.

I have another function $g$ written in Mathematica taking values in four integers that I would like to evaluate on each solution in the list above. Is it possible to write code which does this in Mathematica? I have searched online but haven’t had much luck. Thanks!

list manipulation – Why are the inputs not being applied to the function in this MWE?

Consider the following MWE


randFunc(listFunc_) := RandomChoice(listFunc)@x;
mwe(list_) := Module({testfun1, testfun2},
  testfun1(x_) = RandomChoice(list)@x;
  testfun2(x_) = randFunc(list);
  N@{testfun1(2), testfun2(2)}

mwe({Sqrt, Log})

Which gives output that looks like {0.693147, Log(x)}

The numbers/function changes because of RandomChoice, but why does testfun1(2) evaluate but not testfun2(2)?

Note: The following code (where the list is explicitly input in testfun1 and testfun2 does work


randFunc(listFunc_) := RandomChoice(listFunc)@x;
testfun1(x_, list_) = RandomChoice(list)@x;
testfun2(x_, list_) = randFunc(list);
N@{testfun1(2, {Sqrt, Log}), testfun2(2, {Sqrt, Log})}

Which gives output like {1.41421, 0.693147} (again, RandomChoice can change values, but they are both evaluating)

Note 2: I can get the expected behavior in the first example by changing testfun2(x_) = randFunc(list) ;to testfun2(y_) = randFunc(list) /. x -> y;, but I don’t understand why I would need to do this.

Looking at the trace, Maybe randFunc(list) is not evaluating when testfun2(x_) is being defined in the Module, but I don’t understand why this would be?

  • (maybe the HoldAll attribute of Module?)

list manipulation – Indexed[] returning Table::nliter error

I have been trying to create a new table from a list of values. I used

testtab = {{1, 1}, {2, 1}, {3, 4}, {5, 10}};
difftesttab = 
 Table(Indexed(testtab, {part, 1}), (
  Indexed(testtab, {part + 1, 2}) - Indexed(testtab, {part, 2}))/(
  0.5 (Indexed(testtab, {part + 1, 2}) + 
     Indexed(testtab, {part, 2}))), {part, 1, Length(testtab) - 1})

which gives me a Table::nliter error. I also tried using testtab((part,1)) instead of Indexed, but that gives me a Part::pkspec1 error. Do you have any suggestions on how to approach this?


list manipulation – Diagonal matrix command in Mathematica

tmp = spdiags(AA,0)


AA =
    0.6948    0.0344    0.7655
    0.3171    0.4387    0.7952
    0.9502    0.3816    0.1869

tmp =

tmp =

ans =
    0.6948    0.0344    0.7655
    0.3171    1.0000    0.7952
    0.9502    0.3816    0.1869

In Mathematica

(AA = {{0.6948, 0.0344, 0.7655}, {0.3171, 0.4387, 0.7952}, {0.9502, 
    0.3816, 0.1869}}) // MatrixForm
tmp = Diagonal(AA, 0);
tmp((2)) = 1;
backmat = 
 SparseArray(Band({1, 1}) -> tmp) + 
  SparseArray@UpperTriangularize(AA, 1) + 
  SparseArray@LowerTriangularize(AA, -1)


Mathematica graphics

I do not think Mathematica has command to insert diagonal into sparse matrix directly like Matlab’s spdiags but it is possible to do it as above indirectly.

algebraic manipulation – Rearranging inequality

I’m trying to rearrange this inequality $a + b a – 1 > a^2 – c a – b c$, to appear as $-a^2 + (b+c+1)a>1-bc$ or $-a^2 + (b+c+1)a-1+bc>0$. I’ve tried to achieve that with Collect, but couldn’t make it work on both sides of the inequality.

Any ideas on how to achieve that?

I will do any photoshop editing and photo manipulation for $10

I will do any photoshop editing and photo manipulation

Hi, I am a professional Photoshop editor, I have been in this profession for the last 6 years and I have worked on very large projects in my career.And I am sure that I will not disappoint you with my art of photo editing.

Services i provide –

– Face editing (wrinkles, blemishes, eye bags, shadows etc.)

– Color correction (brightness, white balance, vibrancy, saturation etc.)

– skin retouching (airbrush/soften skin)

– Remove background and change to any color or picture

– Change background

– Change color of items

– Change shape of body/face

– Add or remove people/items from a photo

– And anything else you can think of really

-Adobe Photoshop editing for amazon product

-Photoshop manipulation

-Photoshop retouching

why choose me –

-6 years plus experience

-under 24 hours Delievery

-unlimited revision

-24 x 7 availability

-Master in Photoshop editing

I can assure you that if you give me order, I will not disappoint you at all.Best regardsS.K.Thankyou


list manipulation – How to convert decimals to integers and joint them to a file name

There’s a list such as {0.1,2,0.15,5}. I want to know how to convert the decimal to integer( but begin with zero 0), and don’t touch the integer. In the second step, joint the data to a file name “a01b2c015d5”. Note that the data in the printed file name are separated with a,b,c and d, because I have tons of data to mark with a, b, c and d. How to do it? Thank you!