4
$\begingroup$

I want to do a simple calculation with a list with Pi and 10^-6 and get a list of decimal numbers as the result.

List1={380, 421, 430, 515, 498}
Solve[Pi*(List1*10^-6)]

It gave me this:

Solve[{(19 \[Pi])/50000, (421 \[Pi])/1000000, (43 \[Pi])/100000, (103 \[Pi])/200000, (249 \[Pi])/500000]

Solve did not output the answer in decimal. I want the answers in a list like the one shown below.

{0.001234646, 0.001372876, 0.00140115, 0.001674469, 0.001627345}

Please help.

$\endgroup$
3
  • $\begingroup$ Look up N[].${}$ $\endgroup$ Dec 11, 2015 at 20:44
  • $\begingroup$ This is not a correct usage of Solve in the first place. Its not ever clear what you are intending. $\endgroup$
    – george2079
    Dec 11, 2015 at 20:59
  • $\begingroup$ What is a "formulation"? $\endgroup$ Dec 11, 2015 at 21:21

1 Answer 1

3
$\begingroup$

Given the values

vals = {380, 421, 430, 515, 498};

here are two ways to force Mathematica to do arithmetic on these values that produces results expressed in your computer's native floating point numbers.

Pi vals 1.*^-6

and

Pi vals 10^-6 // N

The first one works because Mathematica has an evaluation rule that in effect says: if any number in a computation is a machine floating point number, coerce the results into machine floats.

The second one does the whole computation with exact numbers (those that you show in the Solve output you posted) and then passes the list of exact results to the numerical evaluation function N, which coerces the exact numbers in the list into machine floats. N can do some other things, but this is the most common way it is used. You can also write this in two other ways

N[Pi vals 10^-6]

and

N @ Pi vals 10^-6

That is, N can be written as a standard function, a pre-fixe operator, or a post-fix operator.

Note that there is no need to use Solve or Map to make this simple numeric computation across a list of values. Almost all the numeric functions in Mathematica have a attribute called Listable that makes them automatically map across the elements of a list.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.