I have an expression as below:
Equations = 2.0799361919940695` x[1] + 3.3534325557330327` x[1]^2 -
4.335179297091139` x[1] x[2] + 1.1989715511881491` x[2]^2 -
3.766597877399148` x[1] x[3] - 0.33254815073371535` x[2] x[3] +
1.9050048836042945` x[3]^2 + 1.1386715715291826` x[1] x[4] +
2.802846492104668` x[2] x[4] - 0.6210244597295915` x[3] x[4] +
4.943369095158792` x[4]^2
I want to write it in an output file. So I use the below code:
removebracketvar[x_] :=
StringReplace[
StringReplace[
ToString[x], {"[" -> "", "]" -> "", "," -> "", "*^" -> "e",
".*" -> ".0*"}], Whitespace -> ""];
SetDirectory["C:\\folder"];
WriteString["eqfile.txt",
removebracketvar[
ToString[Equations , InputForm, NumberMarks -> False]] ];
Close["eqfile.txt"]
The slight problem with the code for me is that it inserts the floating point numbers up to 16 digits of precision. I just want them to around up to 10 digits of precision. When I use SetPrecision[Equations,10]
, it weirdly changes x[1]
etc. to x[1.0000000]
, etc.! I want to leave the variables as they are but want to change the floating points to less number of digits after the decimal point. What would be the best way of doing this?
Comments
Post a Comment