Questions tagged [conversion]

Questions on changing Mathematica expressions of one type or format to another, for example date formats, Boxes and other typesetting representations, or different units of measurements.

Although everything in Mathematica is an expression, different kinds of expression have their own internal format or logic, and there are times where one might want to convert an expression to another representational form. The most common case would be to change the way a particular expression is displayed.

Typesetting representations

Mathematica allows for two-dimensional mathematical typesetting and other highly formatted output. It is possible to convert between String, normal StandardForm output and typeset Box representations using the ToString, ToExpression and ToBoxes functions.

Date/Time representations

Mathematica can represent dates in both seconds-since-1900 format and DateList format ({year, month, day} or {year, month, day, hours, minutes, seconds}. All the elements should be integers, except the seconds. As noted in the answer to this question, these formats can be easily converted between each other using the DateList and AbsoluteTime functions.

247 questions
7
votes
1 answer

How to write aligned equations and export them HTML/TeX

This question is mainly about exporting to HTML/TeX. For those of you who do not know how to write aligned equations in Mathematica please see this answer. Lets assume that you modified your stylesheet as I mentioned in my answer. In my notebook…
jmlopez
  • 6,470
  • 4
  • 28
  • 48
7
votes
1 answer

Inconsistent rounding with ToExpression

I am trying to convert a string which contains a decimal number into a number with out any lost of precision. For example the string 5000000.0000000009 should become the number 5000000.0000000009 and not 5000000.000000001 Using the built in function…
The Square Cow
  • 315
  • 1
  • 6
4
votes
0 answers

Efficient conversion of a ByteArray object into a hexadecimal string

What is the best way to convert ByteArray objects into hexadecimal string representation? Although the following works, I find it questionably awkward (and likely not very efficient): ByteArray[{9, 182, 236, 38, 171, 0, 236, 56}] // …
kirma
  • 19,056
  • 1
  • 51
  • 93
2
votes
1 answer

How to convert sine wave into square wave? (analog to digital signal)

I've got this plot with two sine waves and what I need is follow: Amplitude values can diverge from time to time like here min 100 and max 700 but another time it's 300 600. I guess I will not be able to get these nice phased waves from those on…
a_vasilkov
  • 123
  • 1
  • 4
2
votes
1 answer

Convert Wolfram code into C language

Here is my Mathematica code: f[x_] := x^2 + 4 x + 4; Solve[f[x] == 9, x] I tried to convert it to C but failed. Here is the code for conversion: CForm[f[x_] := x^2 + 4 x + 4] and this CForm[f[x_] := x^2 + 4 x + 4; Solve[f[x] == 9, x]] The former…
kile
  • 1,671
  • 5
  • 10
2
votes
1 answer

ToExpression interpreting typeset strings

Restatement of question, including code. numList = {"3 ", "(2)^2 ", "foo", "bar"}; Manipulate[nums = Extract[numList, {{1}, {i}}]; Grid[{{"Perform the following calculation."}, {"input=" <> StringJoin[nums]}, {"ans=" <> …
rhomboidRhipper
  • 856
  • 4
  • 7
1
vote
2 answers

How to get monomials multiplied by each other?

Suppose Subscript[x, #] & /@ {1, 3, 7} that returns {x_1,x_3,x_7}. Now how can I get x_1x_3x_7? Tried it already... P.s. I am trying to understand this thread deeper about converting binary mlfs to mlfs.
hhh
  • 2,603
  • 2
  • 19
  • 30
1
vote
2 answers

How to get rid of trailing string after using Convert?

Convert[0.05263, Percent] /. Percent -> "%" I would like to remove the trailing "%" but if I put Percent->"" it concatenates a literal empty pair of quotes. Thanks. Edit: I should have explained it works well in the Mathematica interactive…
dabd
  • 839
  • 4
  • 13
0
votes
0 answers

Strange style conversion indicator appeared when type "a Pre"

I got the following strange style conversion indicator when I was typing a Pre(character a and Pre separated by a space) in an input cell: I have no clue why it was triggered and I don't even know this kind of conversion indicator is possible. So…
Naitree
  • 1,235
  • 9
  • 20
0
votes
0 answers

Convert Mathematica Code to R Code

I would like to convert Mathematica code to R code. For example, 4/(-1 + δ) + (-1 + δ) Subscript[P, R] The above is a copy version from Matematica. But I would like to type this one in R such as: 4/(-1 + Delta) + (-1 + Delta)*PR Of course, the…
Sam Kim
  • 1
  • 1
-1
votes
1 answer

Conversion code Mathematica 5.0 to Matlab

How to convert the following Mathematica code into Matlab? What is the corresponding Matlab code? Clear[defvar] defvar[{Nh_Symbol, Nhf_Symbol, gini_Symbol}, {dim_Integer, steps_Integer}] := Module[{cN, cNf, ginix}, cN = Array[Nh, dim]; …