0
$\begingroup$
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.

$\endgroup$
1
$\begingroup$
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[3], Point[{#, 24} & /@ roots]}]

enter image description here

Export["roots.xls", roots]

(* "roots.xls" *)

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

(* True *)
$\endgroup$
0
$\begingroup$

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"]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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