0
$\begingroup$

I tried to solve some equation for different values of parameter t and put results into array. Then I wanted to write this data into a txt-file. So i did it with Write function. But strings in this file look like:

{{y -> -300.339}}

Are there some parameters of Write function for numbers (with sign) writing only?

Array[f, 1000]

x := 2
z := 1
v := 0.98
T := 10
dt := T/1000

For[i = 0, i < 1000, 
 i++, f[i] = Solve[-T/2 + i*dt - y == Sqrt[x^2 + (z - v*y)^2], y]]

I tried this one, but it doesn't help:

For[i = 0, i < 1000, 
 i++, { a = Solve[-T/2 + i*dt - y == Sqrt[x^2 + (z - v*y)^2], y], 
  f[i] /. a}]
$\endgroup$
4
  • 1
    $\begingroup$ It is not clear what you are asking. If your results are in the form of Rule expressions you will need to convert them to bare numbers. See for example: (1616091), (8355218), (6669) $\endgroup$
    – Mr.Wizard
    Commented Feb 8, 2015 at 11:17
  • $\begingroup$ Okay, that's a code. Array[f, 1000] x := 2 z := 1 v := 0.98 T := 10 dt := T/1000 For[i = 0, i < 1000, i++, f[i] = Solve[-T/2 + i*dt - y == Sqrt[x^2 + (z - v*y)^2], y]] I tried this one, but it doesn't help: For[i = 0, i < 1000, i++, { a = Solve[-T/2 + i*dt - y == Sqrt[x^2 + (z - v*y)^2], y], f[i] /. a}] $\endgroup$
    – newt
    Commented Feb 8, 2015 at 11:34
  • $\begingroup$ Please use the edit link below your question to include code examples. $\endgroup$
    – Mr.Wizard
    Commented Feb 8, 2015 at 11:35
  • $\begingroup$ I posted an answer. I hope the examples help you. I am not sure what you intend for f so I left it out. If you wish to save the definition of f itself please see: (2008) $\endgroup$
    – Mr.Wizard
    Commented Feb 8, 2015 at 11:43

1 Answer 1

1
$\begingroup$

Please try this code:

x := 2
z := 1
v := 0.98
T := 10
dt := T/1000

Table[
 y /. Solve[-T/2 + i*dt - y == Sqrt[x^2 + (z - v*y)^2], y][[1]],
 {i, 0, 999}
]
{-300.33859829722434`, -299.8391603699061`, -299.3397243096371`, 
 -298.8402901257249`, . . ., 2.506139642749351`, 2.5124784155139106`}

You should be able to Export that as a plain list of numbers. Be aware that I extract only the first solution, should more than one exist, but I am guessing that is OK.

If you need a table including the i values:

Table[
 {i, y /. Solve[-T/2 + i*dt - y == Sqrt[x^2 + (z - v*y)^2], y][[1]]},
 {i, 0, 999}
]
$\endgroup$

Your Answer

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

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