# Export Roots of EigenValue Function from Mathematica to Excel file

For[i=2,i<200, i++, Print[FindRoot[1-x Cot [x]==24,{x,i}]]


I have this equation in for loop. it prints the value but I want to export these values in excel file. Can anyone please help me. I shall be very thankful to you.

Clear["Global*"]

eqn = 1 - x Cot[x] == 24;

roots = x /. NSolve[{eqn, 0 < x < 200}, x];

Plot[Evaluate[List @@ eqn], {x, 0, 200},
PlotRange -> {-10, 50},
Epilog -> {Red, AbsolutePointSize, Point[{#, 24} & /@ roots]}] Export["roots.xls", roots]

(* "roots.xls" *)

roots == (Import["roots.xls"] // Flatten)

(* True *)


We use Values to extract the values of the roots.

output = Values @@@
Table[FindRoot[1 - x Cot[x] == 24, {x, i}], {i, 2, 200}]
Export["data.xls", output]
Import["data.xls"]


You can also set $Output to accept the Print. $Output = "abc.txt";
For[i = 2, i < 200, i++,
Print[Values @@ FindRoot[1 - x Cot[x] == 24, {x, i}]]]
Export["newdata.txt", Import["abc.txt"]]
Import["newdata.txt"]
`